use of org.hibernate.persister.entity.SingleTableEntityPersister in project hibernate-orm by hibernate.
the class QualifiedTableNamingTest method testQualifiedNameSeparator.
@Test
public void testQualifiedNameSeparator() throws Exception {
Namespace.Name namespaceName = new Namespace.Name(Identifier.toIdentifier("DB1"), Identifier.toIdentifier("PUBLIC"));
String expectedName = null;
for (Namespace namespace : metadata().getDatabase().getNamespaces()) {
if (!namespace.getName().equals(namespaceName)) {
continue;
}
assertEquals(1, namespace.getTables().size());
expectedName = metadata().getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format(namespace.getTables().iterator().next().getQualifiedTableName(), getDialect());
}
assertNotNull(expectedName);
SingleTableEntityPersister persister = (SingleTableEntityPersister) sessionFactory().getEntityPersister(Box.class.getName());
assertEquals(expectedName, persister.getTableName());
}
use of org.hibernate.persister.entity.SingleTableEntityPersister in project Gemma by PavlidisLab.
the class AuditEventDaoImpl method getClassHierarchy.
/**
* Determine the full set of AuditEventTypes that are needed (that is, subclasses of the given class)
*
* @param type Class
* @return A List of class names, including the given type.
*/
private List<String> getClassHierarchy(Class<? extends AuditEventType> type) {
List<String> classes = new ArrayList<>();
classes.add(type.getSimpleName());
// how to determine subclasses? There is no way to do this but the hibernate way.
SingleTableEntityPersister classMetadata = (SingleTableEntityPersister) this.getSessionFactory().getClassMetadata(type.getName());
if (classMetadata == null)
return classes;
CommonQueries.addSubclasses(classes, classMetadata);
return classes;
}
use of org.hibernate.persister.entity.SingleTableEntityPersister in project dhis2-core by dhis2.
the class DefaultSchemaService method handleContextRefresh.
@EventListener
public void handleContextRefresh(ContextRefreshedEvent contextRefreshedEvent) {
for (SchemaDescriptor descriptor : descriptors.values()) {
Schema schema = descriptor.getSchema();
MetamodelImplementor metamodelImplementor = (MetamodelImplementor) sessionFactory.getMetamodel();
try {
EntityPersister entityPersister = metamodelImplementor.entityPersister(schema.getKlass());
if (entityPersister instanceof SingleTableEntityPersister) {
schema.setTableName(((SingleTableEntityPersister) entityPersister).getTableName());
}
schema.setPersisted(true);
} catch (MappingException e) {
// Class is not persisted with Hibernate
schema.setPersisted(false);
}
schema.setDisplayName(TextUtils.getPrettyClassName(schema.getKlass()));
if (schema.getProperties().isEmpty()) {
schema.setPropertyMap(Maps.newHashMap(propertyIntrospectorService.getPropertiesMap(schema.getKlass())));
}
classSchemaMap.put(schema.getKlass(), schema);
singularSchemaMap.put(schema.getSingular(), schema);
pluralSchemaMap.put(schema.getPlural(), schema);
updateSelf(schema);
schema.getPersistedProperties();
schema.getNonPersistedProperties();
schema.getReadableProperties();
schema.getEmbeddedObjectProperties();
}
}
use of org.hibernate.persister.entity.SingleTableEntityPersister in project dhis2-core by dhis2.
the class TableNameToEntityMapping method extractTableNames.
public void extractTableNames(final Class<?> modelClazz) {
final MetamodelImpl metamodel = (MetamodelImpl) sessionFactory.getMetamodel();
final EntityPersister entityPersister = metamodel.entityPersister(modelClazz);
for (int i = 0; i < entityPersister.getPropertyTypes().length; i++) {
Type type = entityPersister.getPropertyTypes()[i];
if (type.isCollectionType()) {
CollectionType collectionType = (CollectionType) type;
CollectionPersister collectionPersister = metamodel.collectionPersister(collectionType.getRole());
if (collectionPersister instanceof BasicCollectionPersister) {
BasicCollectionPersister bc = (BasicCollectionPersister) collectionPersister;
String tableName = bc.getTableName();
tableNameToEntity.computeIfAbsent(tableName, s -> new ArrayList<>()).add(new Object[] { modelClazz, collectionType.getRole() });
}
}
}
if (entityPersister instanceof SingleTableEntityPersister) {
String tableName = ((SingleTableEntityPersister) entityPersister).getTableName();
tableNameToEntity.computeIfAbsent(tableName, s -> new ArrayList<>()).add(new Object[] { modelClazz });
} else {
throw new IllegalArgumentException(modelClazz + " does not map to a single table.");
}
}
Aggregations