Skip to content

Commit cc1ce68

Browse files
committed
HHH-7709 - change org.hibernate.type.ForeignKeyDirection to enum
1 parent 46a0cbe commit cc1ce68

File tree

11 files changed

+33
-45
lines changed

11 files changed

+33
-45
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,9 @@ public static void bindOneToOne(Element node, OneToOne oneToOne, String path, bo
16951695
oneToOne.setConstrained( constrained );
16961696

16971697
oneToOne.setForeignKeyType( constrained ?
1698-
ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
1699-
ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );
1698+
ForeignKeyDirection.FROM_PARENT :
1699+
ForeignKeyDirection.TO_PARENT
1700+
);
17001701

17011702
initOuterJoinFetchSetting( node, oneToOne );
17021703
initLaziness( node, oneToOne, mappings, true );

hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public void doSecondPass(Map persistentClasses) throws MappingException {
104104
if ( !optional ) value.setConstrained( true );
105105
value.setForeignKeyType(
106106
value.isConstrained() ?
107-
ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
108-
ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
107+
ForeignKeyDirection.FROM_PARENT :
108+
ForeignKeyDirection.TO_PARENT
109109
);
110110
PropertyBinder binder = new PropertyBinder();
111111
binder.setName( propertyName );

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ protected void entityIsTransient(MergeEvent event, Map copyCache) {
212212
// copy created before we actually copy
213213
//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
214214
super.cascadeBeforeSave(source, persister, entity, copyCache);
215-
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT);
215+
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT );
216216

217217
saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache );
218218

219219
// cascade first, so that all unsaved objects get their
220220
// copy created before we actually copy
221221
super.cascadeAfterSave(source, persister, entity, copyCache);
222-
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
222+
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT );
223223

224224
event.setResult( copy );
225225
}
@@ -392,7 +392,7 @@ protected void copyValues(
392392

393393
final Object[] copiedValues;
394394

395-
if ( foreignKeyDirection == ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ) {
395+
if ( foreignKeyDirection == ForeignKeyDirection.TO_PARENT ) {
396396
// this is the second pass through on a merge op, so here we limit the
397397
// replacement to associations types (value types were already replaced
398398
// during the first pass)

hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ protected boolean isDuplicateAssociation(final String foreignKeyTable, final Str
760760
protected boolean isDuplicateAssociation(final String lhsTable, final String[] lhsColumnNames, final AssociationType type) {
761761
final String foreignKeyTable;
762762
final String[] foreignKeyColumns;
763-
if ( type.getForeignKeyDirection()==ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT ) {
763+
if ( type.getForeignKeyDirection()==ForeignKeyDirection.FROM_PARENT ) {
764764
foreignKeyTable = lhsTable;
765765
foreignKeyColumns = lhsColumnNames;
766766
}

hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public Object replace(
383383
Object owner,
384384
Map copyCache,
385385
ForeignKeyDirection foreignKeyDirection) {
386-
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT == foreignKeyDirection
386+
return ForeignKeyDirection.FROM_PARENT == foreignKeyDirection
387387
? getReplacement( (T) original, (T) target, session )
388388
: target;
389389
}

hibernate-core/src/main/java/org/hibernate/type/AbstractType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public Object replace(
173173
include = atype.getForeignKeyDirection()==foreignKeyDirection;
174174
}
175175
else {
176-
include = ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT==foreignKeyDirection;
176+
include = ForeignKeyDirection.FROM_PARENT ==foreignKeyDirection;
177177
}
178178
return include ? replace(original, target, session, owner, copyCache) : target;
179179
}

hibernate-core/src/main/java/org/hibernate/type/AnyType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ public boolean isComponentType() {
327327
}
328328

329329
public ForeignKeyDirection getForeignKeyDirection() {
330-
//return AssociationType.FOREIGN_KEY_TO_PARENT; //this is better but causes a transient object exception...
331-
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
330+
//return AssociationType.TO_PARENT; //this is better but causes a transient object exception...
331+
return ForeignKeyDirection.FROM_PARENT;
332332
}
333333

334334
public boolean isAssociationType() {

hibernate-core/src/main/java/org/hibernate/type/CollectionType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public boolean isAssociationType() {
321321
}
322322

323323
public ForeignKeyDirection getForeignKeyDirection() {
324-
return ForeignKeyDirection.FOREIGN_KEY_TO_PARENT;
324+
return ForeignKeyDirection.TO_PARENT;
325325
}
326326

327327
/**

hibernate-core/src/main/java/org/hibernate/type/ForeignKeyDirection.java

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,39 @@
2323
*/
2424
package org.hibernate.type;
2525

26-
import java.io.Serializable;
27-
2826
import org.hibernate.engine.internal.Cascade;
2927

3028
/**
3129
* Represents directionality of the foreign key constraint
30+
*
3231
* @author Gavin King
3332
*/
34-
public abstract class ForeignKeyDirection implements Serializable {
35-
protected ForeignKeyDirection() {}
36-
/**
37-
* Should we cascade at this cascade point?
38-
* @see org.hibernate.engine.internal.Cascade
39-
*/
40-
public abstract boolean cascadeNow(int cascadePoint);
41-
33+
public enum ForeignKeyDirection {
4234
/**
4335
* A foreign key from child to parent
4436
*/
45-
public static final ForeignKeyDirection FOREIGN_KEY_TO_PARENT = new ForeignKeyDirection() {
37+
TO_PARENT {
38+
@Override
4639
public boolean cascadeNow(int cascadePoint) {
47-
return cascadePoint!=Cascade.BEFORE_INSERT_AFTER_DELETE;
40+
return cascadePoint != Cascade.BEFORE_INSERT_AFTER_DELETE;
4841
}
4942

50-
public String toString() {
51-
return "toParent";
52-
}
53-
54-
Object readResolve() {
55-
return FOREIGN_KEY_TO_PARENT;
56-
}
57-
};
43+
},
5844
/**
5945
* A foreign key from parent to child
6046
*/
61-
public static final ForeignKeyDirection FOREIGN_KEY_FROM_PARENT = new ForeignKeyDirection() {
47+
FROM_PARENT {
48+
@Override
6249
public boolean cascadeNow(int cascadePoint) {
63-
return cascadePoint!= Cascade.AFTER_INSERT_BEFORE_DELETE;
64-
}
65-
66-
public String toString() {
67-
return "fromParent";
68-
}
69-
70-
Object readResolve() {
71-
return FOREIGN_KEY_FROM_PARENT;
50+
return cascadePoint != Cascade.AFTER_INSERT_BEFORE_DELETE;
7251
}
7352
};
53+
54+
/**
55+
* Should we cascade at this cascade point?
56+
*
57+
* @see org.hibernate.engine.internal.Cascade
58+
*/
59+
public abstract boolean cascadeNow(int cascadePoint);
60+
7461
}

hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void nullSafeSet(
143143
}
144144

145145
public ForeignKeyDirection getForeignKeyDirection() {
146-
return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
146+
return ForeignKeyDirection.FROM_PARENT;
147147
}
148148

149149
public Object hydrate(

hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Object hydrate(
142142
}
143143

144144
protected boolean isNullable() {
145-
return foreignKeyType==ForeignKeyDirection.FOREIGN_KEY_TO_PARENT;
145+
return foreignKeyType==ForeignKeyDirection.TO_PARENT;
146146
}
147147

148148
public boolean useLHSPrimaryKey() {

0 commit comments

Comments
 (0)