use of org.hibernate.mapping.KeyValue in project jbosstools-hibernate by jbosstools.
the class PersistentClassFacadeTest method testGetIdentifier.
@Test
public void testGetIdentifier() throws Exception {
KeyValue valueTarget = createValue();
Field field = AbstractPersistentClassFacade.class.getDeclaredField("identifier");
field.setAccessible(true);
assertNull(field.get(persistentClassFacade));
assertNull(persistentClassFacade.getIdentifier());
assertNull(field.get(persistentClassFacade));
((RootClass) persistentClassTarget).setIdentifier(valueTarget);
IValue valueFacade = persistentClassFacade.getIdentifier();
assertNotNull(valueFacade);
assertSame(valueFacade, field.get(persistentClassFacade));
assertSame(valueTarget, ((IFacade) valueFacade).getTarget());
}
use of org.hibernate.mapping.KeyValue in project jbosstools-hibernate by jbosstools.
the class ValueFacadeTest method testGetKey.
@Test
public void testGetKey() {
Map valueTarget = new Map(null, null);
valueFacade = FACADE_FACTORY.createValue(valueTarget);
assertNull(valueFacade.getKey());
KeyValue keyValue = new SimpleValue(null);
valueTarget.setKey(keyValue);
assertSame(keyValue, ((IFacade) valueFacade.getKey()).getTarget());
}
use of org.hibernate.mapping.KeyValue in project jbosstools-hibernate by jbosstools.
the class ValueFacadeTest method testSetKey.
@Test
public void testSetKey() {
KeyValue keyValueTarget = new SimpleValue(null);
IValue keyValueFacade = FACADE_FACTORY.createValue(keyValueTarget);
Collection collectionTarget = new Bag(null, null);
IValue collectionFacade = FACADE_FACTORY.createValue(collectionTarget);
assertNull(collectionTarget.getKey());
collectionFacade.setKey(keyValueFacade);
assertSame(keyValueTarget, collectionTarget.getKey());
}
use of org.hibernate.mapping.KeyValue in project jbosstools-hibernate by jbosstools.
the class ValueFacadeTest method testSetKey.
@Test
public void testSetKey() {
KeyValue keyValueTarget = new SimpleValue(DummyMetadataBuildingContext.INSTANCE, null);
IValue keyValueFacade = FACADE_FACTORY.createValue(keyValueTarget);
Collection collectionTarget = new Bag(DummyMetadataBuildingContext.INSTANCE, null);
IValue collectionFacade = FACADE_FACTORY.createValue(collectionTarget);
assertNull(collectionTarget.getKey());
collectionFacade.setKey(keyValueFacade);
assertSame(keyValueTarget, collectionTarget.getKey());
}
use of org.hibernate.mapping.KeyValue in project hibernate-orm by hibernate.
the class AnnotationBinder method bindOneToOne.
private static void bindOneToOne(String cascadeStrategy, Ejb3JoinColumn[] joinColumns, boolean optional, FetchMode fetchMode, boolean ignoreNotFound, boolean cascadeOnDelete, XClass targetEntity, PropertyHolder propertyHolder, PropertyData inferredData, String mappedBy, boolean trueOneToOne, boolean isIdentifierMapper, boolean inSecondPass, PropertyBinder propertyBinder, MetadataBuildingContext context) {
// column.getTable() => persistentClass.getTable()
final String propertyName = inferredData.getPropertyName();
LOG.tracev("Fetching {0} with {1}", propertyName, fetchMode);
boolean mapToPK = true;
if (!trueOneToOne) {
// try to find a hidden true one to one (FK == PK columns)
KeyValue identifier = propertyHolder.getIdentifier();
if (identifier == null) {
// this is a @OneToOne in a @EmbeddedId (the persistentClass.identifier is not set yet, it's being built)
// by definition the PK cannot refers to itself so it cannot map to itself
mapToPK = false;
} else {
Iterator idColumns = identifier.getColumnIterator();
List<String> idColumnNames = new ArrayList<>();
org.hibernate.mapping.Column currentColumn;
if (identifier.getColumnSpan() != joinColumns.length) {
mapToPK = false;
} else {
while (idColumns.hasNext()) {
currentColumn = (org.hibernate.mapping.Column) idColumns.next();
idColumnNames.add(currentColumn.getName());
}
for (Ejb3JoinColumn col : joinColumns) {
if (!idColumnNames.contains(col.getMappingColumn().getName())) {
mapToPK = false;
break;
}
}
}
}
}
if (trueOneToOne || mapToPK || !BinderHelper.isEmptyAnnotationValue(mappedBy)) {
// is a true one-to-one
// FIXME referencedColumnName ignored => ordering may fail.
OneToOneSecondPass secondPass = new OneToOneSecondPass(mappedBy, propertyHolder.getEntityName(), propertyName, propertyHolder, inferredData, targetEntity, ignoreNotFound, cascadeOnDelete, optional, cascadeStrategy, joinColumns, context);
if (inSecondPass) {
secondPass.doSecondPass(context.getMetadataCollector().getEntityBindingMap());
} else {
context.getMetadataCollector().addSecondPass(secondPass, BinderHelper.isEmptyAnnotationValue(mappedBy));
}
} else {
// has a FK on the table
bindManyToOne(cascadeStrategy, joinColumns, optional, ignoreNotFound, cascadeOnDelete, targetEntity, propertyHolder, inferredData, true, isIdentifierMapper, inSecondPass, propertyBinder, context);
}
}
Aggregations