Search in sources :

Example 6 with EntityMode

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());
        }
    }
}
Also used : Column(org.hibernate.mapping.Column) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) Map(java.util.Map) HashMap(java.util.HashMap) EntityMode(org.hibernate.EntityMode)

Example 7 with EntityMode

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;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityMode(org.hibernate.EntityMode)

Example 8 with EntityMode

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);
}
Also used : PropertyAccessStrategyResolver(org.hibernate.property.access.spi.PropertyAccessStrategyResolver) EntityMode(org.hibernate.EntityMode)

Example 9 with 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)));
}
Also used : Serializable(java.io.Serializable) PersistentObject(gov.ca.cwds.data.persistence.PersistentObject) EntityMode(org.hibernate.EntityMode) Test(org.junit.Test)

Example 10 with EntityMode

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);
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) ArrayList(java.util.ArrayList) SimpleValue(org.hibernate.mapping.SimpleValue) EntityMode(org.hibernate.EntityMode) Column(org.hibernate.mapping.Column) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Aggregations

EntityMode (org.hibernate.EntityMode)12 RootClass (org.hibernate.mapping.RootClass)4 ArrayList (java.util.ArrayList)3 PersistentCollection (org.hibernate.collection.spi.PersistentCollection)3 CollectionKey (org.hibernate.engine.spi.CollectionKey)3 Column (org.hibernate.mapping.Column)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Tuplizer (org.hibernate.annotations.Tuplizer)2 Tuplizers (org.hibernate.annotations.Tuplizers)2 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)2 Configuration (org.hibernate.cfg.Configuration)2 AbstractPersistentCollection (org.hibernate.collection.internal.AbstractPersistentCollection)2 SessionFactoryImplementor (org.hibernate.engine.SessionFactoryImplementor)2 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)2 FilterDefinition (org.hibernate.engine.spi.FilterDefinition)2 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)2 SessionFactoryImpl (org.hibernate.impl.SessionFactoryImpl)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 SimpleValue (org.hibernate.mapping.SimpleValue)2