Search in sources :

Example 1 with SingleTableEntityPersister

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());
}
Also used : SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test)

Example 2 with SingleTableEntityPersister

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

Example 3 with SingleTableEntityPersister

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();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) MappingException(org.hibernate.MappingException) EventListener(org.springframework.context.event.EventListener)

Example 4 with SingleTableEntityPersister

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.");
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) EntityPersister(org.hibernate.persister.entity.EntityPersister) ListIterator(java.util.ListIterator) SessionFactory(org.hibernate.SessionFactory) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) CollectionType(org.hibernate.type.CollectionType) Autowired(org.springframework.beans.factory.annotation.Autowired) Profile(org.springframework.context.annotation.Profile) ArrayList(java.util.ArrayList) List(java.util.List) EntityType(javax.persistence.metamodel.EntityType) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) Map(java.util.Map) BasicCollectionPersister(org.hibernate.persister.collection.BasicCollectionPersister) MetamodelImpl(org.hibernate.metamodel.internal.MetamodelImpl) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) Type(org.hibernate.type.Type) CollectionType(org.hibernate.type.CollectionType) EntityType(javax.persistence.metamodel.EntityType) Type(org.hibernate.type.Type) BasicCollectionPersister(org.hibernate.persister.collection.BasicCollectionPersister) MetamodelImpl(org.hibernate.metamodel.internal.MetamodelImpl) BasicCollectionPersister(org.hibernate.persister.collection.BasicCollectionPersister) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CollectionType(org.hibernate.type.CollectionType) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) ArrayList(java.util.ArrayList)

Aggregations

SingleTableEntityPersister (org.hibernate.persister.entity.SingleTableEntityPersister)4 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 EntityType (javax.persistence.metamodel.EntityType)1 Slf4j (lombok.extern.slf4j.Slf4j)1 MappingException (org.hibernate.MappingException)1 SessionFactory (org.hibernate.SessionFactory)1 Namespace (org.hibernate.boot.model.relational.Namespace)1 MetamodelImpl (org.hibernate.metamodel.internal.MetamodelImpl)1 MetamodelImplementor (org.hibernate.metamodel.spi.MetamodelImplementor)1 BasicCollectionPersister (org.hibernate.persister.collection.BasicCollectionPersister)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1 CollectionType (org.hibernate.type.CollectionType)1 Type (org.hibernate.type.Type)1 Test (org.junit.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1