HHH-7709 - change org.hibernate.type.ForeignKeyDirection to enum
This commit is contained in:
parent
46a0cbe7fa
commit
cc1ce680a4
|
@ -1695,8 +1695,9 @@ public final class HbmBinder {
|
|||
oneToOne.setConstrained( constrained );
|
||||
|
||||
oneToOne.setForeignKeyType( constrained ?
|
||||
ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
|
||||
ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );
|
||||
ForeignKeyDirection.FROM_PARENT :
|
||||
ForeignKeyDirection.TO_PARENT
|
||||
);
|
||||
|
||||
initOuterJoinFetchSetting( node, oneToOne );
|
||||
initLaziness( node, oneToOne, mappings, true );
|
||||
|
|
|
@ -104,8 +104,8 @@ public class OneToOneSecondPass implements SecondPass {
|
|||
if ( !optional ) value.setConstrained( true );
|
||||
value.setForeignKeyType(
|
||||
value.isConstrained() ?
|
||||
ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
|
||||
ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
|
||||
ForeignKeyDirection.FROM_PARENT :
|
||||
ForeignKeyDirection.TO_PARENT
|
||||
);
|
||||
PropertyBinder binder = new PropertyBinder();
|
||||
binder.setName( propertyName );
|
||||
|
|
|
@ -212,14 +212,14 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
// copy created before we actually copy
|
||||
//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
|
||||
super.cascadeBeforeSave(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT );
|
||||
|
||||
saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache );
|
||||
|
||||
// cascade first, so that all unsaved objects get their
|
||||
// copy created before we actually copy
|
||||
super.cascadeAfterSave(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT );
|
||||
|
||||
event.setResult( copy );
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
|
||||
final Object[] copiedValues;
|
||||
|
||||
if ( foreignKeyDirection == ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ) {
|
||||
if ( foreignKeyDirection == ForeignKeyDirection.TO_PARENT ) {
|
||||
// this is the second pass through on a merge op, so here we limit the
|
||||
// replacement to associations types (value types were already replaced
|
||||
// during the first pass)
|
||||
|
|
|
@ -760,7 +760,7 @@ public class JoinWalker {
|
|||
protected boolean isDuplicateAssociation(final String lhsTable, final String[] lhsColumnNames, final AssociationType type) {
|
||||
final String foreignKeyTable;
|
||||
final String[] foreignKeyColumns;
|
||||
if ( type.getForeignKeyDirection()==ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT ) {
|
||||
if ( type.getForeignKeyDirection()==ForeignKeyDirection.FROM_PARENT ) {
|
||||
foreignKeyTable = lhsTable;
|
||||
foreignKeyColumns = lhsColumnNames;
|
||||
}
|
||||
|
|
|
@ -383,7 +383,7 @@ public abstract class AbstractStandardBasicType<T>
|
|||
Object owner,
|
||||
Map copyCache,
|
||||
ForeignKeyDirection foreignKeyDirection) {
|
||||
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT == foreignKeyDirection
|
||||
return ForeignKeyDirection.FROM_PARENT == foreignKeyDirection
|
||||
? getReplacement( (T) original, (T) target, session )
|
||||
: target;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ public abstract class AbstractType implements Type {
|
|||
include = atype.getForeignKeyDirection()==foreignKeyDirection;
|
||||
}
|
||||
else {
|
||||
include = ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT==foreignKeyDirection;
|
||||
include = ForeignKeyDirection.FROM_PARENT ==foreignKeyDirection;
|
||||
}
|
||||
return include ? replace(original, target, session, owner, copyCache) : target;
|
||||
}
|
||||
|
|
|
@ -327,8 +327,8 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
|||
}
|
||||
|
||||
public ForeignKeyDirection getForeignKeyDirection() {
|
||||
//return AssociationType.FOREIGN_KEY_TO_PARENT; //this is better but causes a transient object exception...
|
||||
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
|
||||
//return AssociationType.TO_PARENT; //this is better but causes a transient object exception...
|
||||
return ForeignKeyDirection.FROM_PARENT;
|
||||
}
|
||||
|
||||
public boolean isAssociationType() {
|
||||
|
|
|
@ -321,7 +321,7 @@ public abstract class CollectionType extends AbstractType implements Association
|
|||
}
|
||||
|
||||
public ForeignKeyDirection getForeignKeyDirection() {
|
||||
return ForeignKeyDirection.FOREIGN_KEY_TO_PARENT;
|
||||
return ForeignKeyDirection.TO_PARENT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,52 +23,39 @@
|
|||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
|
||||
/**
|
||||
* Represents directionality of the foreign key constraint
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public abstract class ForeignKeyDirection implements Serializable {
|
||||
protected ForeignKeyDirection() {}
|
||||
public enum ForeignKeyDirection {
|
||||
/**
|
||||
* A foreign key from child to parent
|
||||
*/
|
||||
TO_PARENT {
|
||||
@Override
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint != Cascade.BEFORE_INSERT_AFTER_DELETE;
|
||||
}
|
||||
|
||||
},
|
||||
/**
|
||||
* A foreign key from parent to child
|
||||
*/
|
||||
FROM_PARENT {
|
||||
@Override
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint != Cascade.AFTER_INSERT_BEFORE_DELETE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Should we cascade at this cascade point?
|
||||
*
|
||||
* @see org.hibernate.engine.internal.Cascade
|
||||
*/
|
||||
public abstract boolean cascadeNow(int cascadePoint);
|
||||
|
||||
/**
|
||||
* A foreign key from child to parent
|
||||
*/
|
||||
public static final ForeignKeyDirection FOREIGN_KEY_TO_PARENT = new ForeignKeyDirection() {
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint!=Cascade.BEFORE_INSERT_AFTER_DELETE;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "toParent";
|
||||
}
|
||||
|
||||
Object readResolve() {
|
||||
return FOREIGN_KEY_TO_PARENT;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* A foreign key from parent to child
|
||||
*/
|
||||
public static final ForeignKeyDirection FOREIGN_KEY_FROM_PARENT = new ForeignKeyDirection() {
|
||||
public boolean cascadeNow(int cascadePoint) {
|
||||
return cascadePoint!= Cascade.AFTER_INSERT_BEFORE_DELETE;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "fromParent";
|
||||
}
|
||||
|
||||
Object readResolve() {
|
||||
return FOREIGN_KEY_FROM_PARENT;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -143,7 +143,7 @@ public class ManyToOneType extends EntityType {
|
|||
}
|
||||
|
||||
public ForeignKeyDirection getForeignKeyDirection() {
|
||||
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
|
||||
return ForeignKeyDirection.FROM_PARENT;
|
||||
}
|
||||
|
||||
public Object hydrate(
|
||||
|
|
|
@ -142,7 +142,7 @@ public class OneToOneType extends EntityType {
|
|||
}
|
||||
|
||||
protected boolean isNullable() {
|
||||
return foreignKeyType==ForeignKeyDirection.FOREIGN_KEY_TO_PARENT;
|
||||
return foreignKeyType==ForeignKeyDirection.TO_PARENT;
|
||||
}
|
||||
|
||||
public boolean useLHSPrimaryKey() {
|
||||
|
|
Loading…
Reference in New Issue