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();
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);
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class ModelBinder method bindBasicEntityValues.
private void bindBasicEntityValues(MappingDocument sourceDocument, AbstractEntitySourceImpl entitySource, PersistentClass entityDescriptor) {
entityDescriptor.setEntityName(entitySource.getEntityNamingSource().getEntityName());
entityDescriptor.setJpaEntityName(entitySource.getEntityNamingSource().getJpaEntityName());
entityDescriptor.setClassName(entitySource.getEntityNamingSource().getClassName());
entityDescriptor.setDiscriminatorValue(entitySource.getDiscriminatorMatchValue() != null ? entitySource.getDiscriminatorMatchValue() : entityDescriptor.getEntityName());
// NOTE : entitySource#isLazy already accounts for MappingDefaults#areEntitiesImplicitlyLazy
if (StringHelper.isNotEmpty(entitySource.getProxy())) {
final String qualifiedProxyName = sourceDocument.qualifyClassName(entitySource.getProxy());
entityDescriptor.setProxyInterfaceName(qualifiedProxyName);
entityDescriptor.setLazy(true);
} else if (entitySource.isLazy()) {
entityDescriptor.setProxyInterfaceName(entityDescriptor.getClassName());
entityDescriptor.setLazy(true);
} else {
entityDescriptor.setProxyInterfaceName(null);
entityDescriptor.setLazy(false);
}
entityDescriptor.setAbstract(entitySource.isAbstract());
sourceDocument.getMetadataCollector().addImport(entitySource.getEntityNamingSource().getEntityName(), entitySource.getEntityNamingSource().getEntityName());
if (sourceDocument.getMappingDefaults().isAutoImportEnabled() && entitySource.getEntityNamingSource().getEntityName().indexOf('.') > 0) {
sourceDocument.getMetadataCollector().addImport(StringHelper.unqualify(entitySource.getEntityNamingSource().getEntityName()), entitySource.getEntityNamingSource().getEntityName());
}
if (entitySource.getTuplizerClassMap() != null) {
if (entitySource.getTuplizerClassMap().size() > 1) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfMultipleEntityModeSupport();
}
for (Map.Entry<EntityMode, String> tuplizerEntry : entitySource.getTuplizerClassMap().entrySet()) {
entityDescriptor.addTuplizer(tuplizerEntry.getKey(), tuplizerEntry.getValue());
}
}
if (StringHelper.isNotEmpty(entitySource.getXmlNodeName())) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
}
entityDescriptor.setDynamicInsert(entitySource.isDynamicInsert());
entityDescriptor.setDynamicUpdate(entitySource.isDynamicUpdate());
entityDescriptor.setBatchSize(entitySource.getBatchSize());
entityDescriptor.setSelectBeforeUpdate(entitySource.isSelectBeforeUpdate());
if (StringHelper.isNotEmpty(entitySource.getCustomPersisterClassName())) {
try {
entityDescriptor.setEntityPersisterClass(sourceDocument.getBootstrapContext().getClassLoaderAccess().classForName(entitySource.getCustomPersisterClassName()));
} catch (ClassLoadingException e) {
throw new MappingException(String.format(Locale.ENGLISH, "Unable to load specified persister class : %s", entitySource.getCustomPersisterClassName()), e, sourceDocument.getOrigin());
}
}
bindCustomSql(sourceDocument, entitySource, entityDescriptor);
final JdbcEnvironment jdbcEnvironment = sourceDocument.getMetadataCollector().getDatabase().getJdbcEnvironment();
for (String tableName : entitySource.getSynchronizedTableNames()) {
final Identifier physicalTableName = sourceDocument.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(jdbcEnvironment.getIdentifierHelper().toIdentifier(tableName), jdbcEnvironment);
entityDescriptor.addSynchronizedTable(physicalTableName.render(jdbcEnvironment.getDialect()));
}
for (FilterSource filterSource : entitySource.getFilterSources()) {
String condition = filterSource.getCondition();
if (condition == null) {
final FilterDefinition filterDefinition = sourceDocument.getMetadataCollector().getFilterDefinition(filterSource.getName());
if (filterDefinition != null) {
condition = filterDefinition.getDefaultFilterCondition();
}
}
entityDescriptor.addFilter(filterSource.getName(), condition, filterSource.shouldAutoInjectAliases(), filterSource.getAliasToTableMap(), filterSource.getAliasToEntityMap());
}
for (JaxbHbmNamedQueryType namedQuery : entitySource.getNamedQueries()) {
NamedQueryBinder.processNamedQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
for (JaxbHbmNamedNativeQueryType namedQuery : entitySource.getNamedNativeQueries()) {
NamedQueryBinder.processNamedNativeQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
entityDescriptor.setMetaAttributes(entitySource.getToolingHintContext().getMetaAttributeMap());
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class CollectionType method getCollection.
/**
* instantiate a collection wrapper (called when loading an object)
*
* @param key The collection owner key
* @param session The session from which the request is originating.
* @param owner The collection owner
* @return The collection
*/
public Object getCollection(Serializable key, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) {
CollectionPersister persister = getPersister(session);
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
// check if collection is currently being loaded
PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection(persister, key);
if (collection == null) {
// check if it is already completely loaded, but unowned
collection = persistenceContext.useUnownedCollection(new CollectionKey(persister, key, entityMode));
if (collection == null) {
collection = persistenceContext.getCollection(new CollectionKey(persister, key, entityMode));
if (collection == null) {
// create a new collection wrapper, to be initialized later
collection = instantiate(session, persister, key);
collection.setOwner(owner);
persistenceContext.addUninitializedCollection(persister, collection, key);
// some collections are not lazy:
boolean eager = overridingEager != null ? overridingEager : !persister.isLazy();
if (initializeImmediately()) {
session.initializeCollection(collection, false);
} else if (eager) {
persistenceContext.addNonLazyCollection(collection);
}
if (hasHolder()) {
session.getPersistenceContext().addCollectionHolder(collection);
}
}
}
if (LOG.isTraceEnabled()) {
LOG.tracef("Created collection wrapper: %s", MessageHelper.collectionInfoString(persister, collection, key, session));
}
}
collection.setOwner(owner);
return collection.getValue();
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class AnnotationBinder method setupComponentTuplizer.
private static void setupComponentTuplizer(XProperty property, Component component) {
if (property == null) {
return;
}
if (property.isAnnotationPresent(Tuplizers.class)) {
for (Tuplizer tuplizer : property.getAnnotation(Tuplizers.class).value()) {
EntityMode mode = EntityMode.parse(tuplizer.entityMode());
// todo tuplizer.entityModeType
component.addTuplizer(mode, tuplizer.impl().getName());
}
}
if (property.isAnnotationPresent(Tuplizer.class)) {
Tuplizer tuplizer = property.getAnnotation(Tuplizer.class);
EntityMode mode = EntityMode.parse(tuplizer.entityMode());
// todo tuplizer.entityModeType
component.addTuplizer(mode, tuplizer.impl().getName());
}
}
use of org.hibernate.EntityMode in project hibernate-orm by hibernate.
the class CollectionType method getCollection.
/**
* instantiate a collection wrapper (called when loading an object)
*
* @param key The collection owner key
* @param session The session from which the request is originating.
* @param owner The collection owner
* @return The collection
*/
public Object getCollection(Serializable key, SharedSessionContractImplementor session, Object owner) {
CollectionPersister persister = getPersister(session);
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
// check if collection is currently being loaded
PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection(persister, key);
if (collection == null) {
// check if it is already completely loaded, but unowned
collection = persistenceContext.useUnownedCollection(new CollectionKey(persister, key, entityMode));
if (collection == null) {
collection = persistenceContext.getCollection(new CollectionKey(persister, key, entityMode));
if (collection == null) {
// create a new collection wrapper, to be initialized later
collection = instantiate(session, persister, key);
collection.setOwner(owner);
persistenceContext.addUninitializedCollection(persister, collection, key);
// some collections are not lazy:
if (initializeImmediately()) {
session.initializeCollection(collection, false);
} else if (!persister.isLazy()) {
persistenceContext.addNonLazyCollection(collection);
}
if (hasHolder()) {
session.getPersistenceContext().addCollectionHolder(collection);
}
}
}
if (LOG.isTraceEnabled()) {
LOG.tracef("Created collection wrapper: %s", MessageHelper.collectionInfoString(persister, collection, key, session));
}
}
collection.setOwner(owner);
return collection.getValue();
}
Aggregations