use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class ModelBinder method bindComponent.
private void bindComponent(MappingDocument sourceDocument, String role, EmbeddableSource embeddableSource, Component componentBinding, String explicitComponentClassName, String containingClassName, String propertyName, boolean isVirtual, boolean isDynamic, String xmlNodeName) {
componentBinding.setMetaAttributes(embeddableSource.getToolingHintContext().getMetaAttributeMap());
componentBinding.setRoleName(role);
componentBinding.setEmbedded(isVirtual);
// todo : better define the conditions in this if/else
if (isDynamic) {
// dynamic is represented as a Map
log.debugf("Binding dynamic-component [%s]", role);
componentBinding.setDynamic(true);
} else if (isVirtual) {
// <properties/> for example
if (componentBinding.getOwner().hasPojoRepresentation()) {
log.debugf("Binding virtual component [%s] to owner class [%s]", role, componentBinding.getOwner().getClassName());
componentBinding.setComponentClassName(componentBinding.getOwner().getClassName());
} else {
log.debugf("Binding virtual component [%s] as dynamic", role);
componentBinding.setDynamic(true);
}
} else {
log.debugf("Binding component [%s]", role);
if (StringHelper.isNotEmpty(explicitComponentClassName)) {
log.debugf("Binding component [%s] to explicitly specified class", role, explicitComponentClassName);
componentBinding.setComponentClassName(explicitComponentClassName);
} else if (componentBinding.getOwner().hasPojoRepresentation()) {
log.tracef("Attempting to determine component class by reflection %s", role);
final Class reflectedComponentClass;
if (StringHelper.isNotEmpty(containingClassName) && StringHelper.isNotEmpty(propertyName)) {
reflectedComponentClass = Helper.reflectedPropertyClass(sourceDocument, containingClassName, propertyName);
} else {
reflectedComponentClass = null;
}
if (reflectedComponentClass == null) {
log.debugf("Unable to determine component class name via reflection, and explicit " + "class name not given; role=[%s]", role);
} else {
componentBinding.setComponentClassName(reflectedComponentClass.getName());
}
} else {
componentBinding.setDynamic(true);
}
}
String nodeName = xmlNodeName;
if (StringHelper.isNotEmpty(nodeName)) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
}
// todo : anything else to pass along?
bindAllCompositeAttributes(sourceDocument, embeddableSource, componentBinding);
if (embeddableSource.getParentReferenceAttributeName() != null) {
componentBinding.setParentProperty(embeddableSource.getParentReferenceAttributeName());
}
if (embeddableSource.isUnique()) {
final ArrayList<Column> cols = new ArrayList<Column>();
final Iterator itr = componentBinding.getColumnIterator();
while (itr.hasNext()) {
final Object selectable = itr.next();
// skip formulas. ugh, yes terrible naming of these methods :(
if (!Column.class.isInstance(selectable)) {
continue;
}
cols.add((Column) selectable);
}
// todo : we may need to delay this
componentBinding.getOwner().getTable().createUniqueKey(cols);
}
if (embeddableSource.getTuplizerClassMap() != null) {
if (embeddableSource.getTuplizerClassMap().size() > 1) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfMultipleEntityModeSupport();
}
for (Map.Entry<EntityMode, String> tuplizerEntry : embeddableSource.getTuplizerClassMap().entrySet()) {
componentBinding.addTuplizer(tuplizerEntry.getKey(), tuplizerEntry.getValue());
}
}
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class Example method getEntityMode.
private EntityMode getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery) {
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
final EntityMode result = meta.getEntityMode();
if (!meta.getEntityMetamodel().getTuplizer().isInstance(exampleEntity)) {
throw new ClassCastException(exampleEntity.getClass().getName());
}
return result;
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class Property method getPropertyAccessStrategy.
// todo : remove
public PropertyAccessStrategy getPropertyAccessStrategy(Class clazz) throws MappingException {
String accessName = getPropertyAccessorName();
if (accessName == null) {
if (clazz == null || java.util.Map.class.equals(clazz)) {
accessName = "map";
} else {
accessName = "property";
}
}
final EntityMode entityMode = clazz == null || java.util.Map.class.equals(clazz) ? EntityMode.MAP : EntityMode.POJO;
return resolveServiceRegistry().getService(PropertyAccessStrategyResolver.class).resolvePropertyAccessStrategy(clazz, accessName, entityMode);
}
use of org.hibernate.EntityMode in project api-core by ca-cwds.
the class ApiHibernateInterceptorTest method instantiate_Args__String__EntityMode__Serializable.
@Test
public void instantiate_Args__String__EntityMode__Serializable() throws Exception {
String entityName = null;
EntityMode entityMode = EntityMode.POJO;
Serializable id = "abc1234567";
Object actual = target.instantiate(entityName, entityMode, id);
Object expected = null;
assertThat(actual, is(equalTo(expected)));
}
use of org.hibernate.EntityMode in project jbosstools-hibernate by jbosstools.
the class EntityMetamodelFacadeTest method setUp.
@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
RootClass rc = new RootClass();
Table t = new Table("foobar");
rc.setTable(t);
Column c = new Column("foo");
t.addColumn(c);
ArrayList<Column> keyList = new ArrayList<>();
keyList.add(c);
t.createUniqueKey(keyList);
SimpleValue sv = new SimpleValue(configuration.createMappings());
sv.setNullValue("null");
sv.setTypeName(Integer.class.getName());
sv.addColumn(c);
rc.setEntityName("foobar");
rc.setIdentifier(sv);
entityMetamodel = new EntityMetamodel(rc, sfi) {
@Override
public EntityTuplizer getTuplizer(EntityMode entityMode) {
return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
}
@Override
public Integer getPropertyIndexOrNull(String id) {
methodName = "getPropertyIndexOrNull";
arguments = new Object[] { id };
return INDEX;
}
};
entityMetamodelFacade = new EntityMetamodelFacadeImpl(FACADE_FACTORY, entityMetamodel);
}
Aggregations