Example usage for org.hibernate.mapping PersistentClass isInherited

List of usage examples for org.hibernate.mapping PersistentClass isInherited

Introduction

In this page you can find the example usage for org.hibernate.mapping PersistentClass isInherited.

Prototype

public abstract boolean isInherited();

Source Link

Usage

From source file:com.mysema.query.jpa.codegen.HibernateDomainExporter.java

License:Apache License

private void collectTypes() throws IOException, XMLStreamException, ClassNotFoundException, SecurityException,
        NoSuchMethodException {//  w  ww .  j ava2 s .c o  m
    // super classes
    Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings();
    while (superClassMappings.hasNext()) {
        MappedSuperclass msc = (MappedSuperclass) superClassMappings.next();
        EntityType entityType = createSuperType(msc.getMappedClass());
        if (msc.getDeclaredIdentifierProperty() != null) {
            handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty());
        }
        Iterator<?> properties = msc.getDeclaredPropertyIterator();
        while (properties.hasNext()) {
            handleProperty(entityType, msc.getMappedClass(),
                    (org.hibernate.mapping.Property) properties.next());
        }
    }

    // entity classes
    Iterator<?> classMappings = configuration.getClassMappings();
    while (classMappings.hasNext()) {
        PersistentClass pc = (PersistentClass) classMappings.next();
        EntityType entityType = createEntityType(pc.getMappedClass());
        if (pc.getDeclaredIdentifierProperty() != null) {
            handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty());
        } else if (!pc.isInherited() && pc.hasIdentifierProperty()) {
            logger.info(entityType.toString() + pc.getIdentifierProperty());
            handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty());
        } else if (pc.getIdentifier() != null) {
            KeyValue identifier = pc.getIdentifier();
            if (identifier instanceof Component) {
                Component component = (Component) identifier;
                Iterator<?> properties = component.getPropertyIterator();
                if (component.isEmbedded()) {
                    while (properties.hasNext()) {
                        handleProperty(entityType, pc.getMappedClass(),
                                (org.hibernate.mapping.Property) properties.next());
                    }
                } else {
                    String name = component.getNodeName();
                    Class<?> clazz = component.getType().getReturnedClass();
                    Type propertyType = getType(pc.getMappedClass(), clazz, name);
                    AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name);
                    Property property = createProperty(entityType, name, propertyType, annotated);
                    entityType.addProperty(property);
                    // handle component properties
                    EntityType embeddedType = createEmbeddableType(propertyType);
                    while (properties.hasNext()) {
                        handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next());
                    }
                }
            }
            // TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne
        }
        Iterator<?> properties = pc.getDeclaredPropertyIterator();
        while (properties.hasNext()) {
            handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
        }
    }

    // go through supertypes
    Set<Supertype> additions = Sets.newHashSet();
    for (Map.Entry<String, EntityType> entry : allTypes.entrySet()) {
        EntityType entityType = entry.getValue();
        if (entityType.getSuperType() != null
                && !allTypes.containsKey(entityType.getSuperType().getType().getFullName())) {
            additions.add(entityType.getSuperType());
        }
    }

    for (Supertype type : additions) {
        type.setEntityType(createEntityType(type.getType(), superTypes));
    }
}

From source file:com.querydsl.jpa.codegen.HibernateDomainExporter.java

License:Apache License

@Override
protected void collectTypes()
        throws IOException, XMLStreamException, ClassNotFoundException, NoSuchMethodException {
    // super classes
    Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings();
    while (superClassMappings.hasNext()) {
        MappedSuperclass msc = (MappedSuperclass) superClassMappings.next();
        EntityType entityType = createSuperType(msc.getMappedClass());
        if (msc.getDeclaredIdentifierProperty() != null) {
            handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty());
        }/*from  w  w w .j av a  2s  . c  om*/
        Iterator<?> properties = msc.getDeclaredPropertyIterator();
        while (properties.hasNext()) {
            handleProperty(entityType, msc.getMappedClass(),
                    (org.hibernate.mapping.Property) properties.next());
        }
    }

    // entity classes
    Iterator<?> classMappings = configuration.getClassMappings();
    while (classMappings.hasNext()) {
        PersistentClass pc = (PersistentClass) classMappings.next();
        EntityType entityType = createEntityType(pc.getMappedClass());
        if (pc.getDeclaredIdentifierProperty() != null) {
            handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty());
        } else if (!pc.isInherited() && pc.hasIdentifierProperty()) {
            logger.info(entityType.toString() + pc.getIdentifierProperty());
            handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty());
        } else if (pc.getIdentifier() != null) {
            KeyValue identifier = pc.getIdentifier();
            if (identifier instanceof Component) {
                Component component = (Component) identifier;
                Iterator<?> properties = component.getPropertyIterator();
                if (component.isEmbedded()) {
                    while (properties.hasNext()) {
                        handleProperty(entityType, pc.getMappedClass(),
                                (org.hibernate.mapping.Property) properties.next());
                    }
                } else {
                    String name = component.getNodeName();
                    Class<?> clazz = component.getType().getReturnedClass();
                    Type propertyType = getType(pc.getMappedClass(), clazz, name);
                    AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name);
                    Property property = createProperty(entityType, name, propertyType, annotated);
                    entityType.addProperty(property);
                    // handle component properties
                    EntityType embeddedType = createEmbeddableType(propertyType);
                    while (properties.hasNext()) {
                        handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next());
                    }
                }
            }
            // TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne
        }
        Iterator<?> properties = pc.getDeclaredPropertyIterator();
        while (properties.hasNext()) {
            handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
        }
    }
}

From source file:org.apache.ignite.cache.hibernate.HibernateL2CacheStrategySelfTest.java

License:Apache License

/**
 * @param accessType Cache access typr./* w  ww. jav a  2 s .c  om*/
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest
            .hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
    builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}

From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
// borrow from Configuration code
private Iterator<IdentifierGenerator> iterateGenerators(Configuration config, Dialect dialect)
        throws MappingException {

    TreeMap generators = new TreeMap();
    String defaultCatalog = sessionFactoryBean.getHibernateProperties()
            .getProperty(Environment.DEFAULT_CATALOG);
    String defaultSchema = sessionFactoryBean.getHibernateProperties().getProperty(Environment.DEFAULT_SCHEMA);

    for (Iterator<PersistentClass> pcIter = config.getClassMappings(); pcIter.hasNext();) {
        PersistentClass pc = pcIter.next();
        if (!pc.isInherited()) {
            IdentifierGenerator ig = pc.getIdentifier().createIdentifierGenerator(
                    config.getIdentifierGeneratorFactory(), dialect, defaultCatalog, defaultSchema,
                    (RootClass) pc);/*from   w ww .  j  a  va  2  s . c o  m*/

            if (ig instanceof PersistentIdentifierGenerator) {
                generators.put(((PersistentIdentifierGenerator) ig).generatorKey(), ig);
            } else if (ig instanceof IdentifierGeneratorAggregator) {
                ((IdentifierGeneratorAggregator) ig).registerPersistentGenerators(generators);
            }
        }
    }

    for (Iterator<Collection> collIter = config.getCollectionMappings(); collIter.hasNext();) {
        Collection collection = collIter.next();
        if (collection.isIdentified()) {
            IdentifierGenerator ig = ((IdentifierCollection) collection).getIdentifier()
                    .createIdentifierGenerator(config.getIdentifierGeneratorFactory(), dialect, defaultCatalog,
                            defaultSchema, null);

            if (ig instanceof PersistentIdentifierGenerator) {
                generators.put(((PersistentIdentifierGenerator) ig).generatorKey(), ig);
            }
        }
    }

    return generators.values().iterator();
}

From source file:org.infinispan.test.hibernate.cache.commons.stress.CorrectnessTestCase.java

License:LGPL

private Metadata buildMetadata(StandardServiceRegistry registry) {
    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }//from  w  ww  .  j av  a  2 s. c  o  m

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited()) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
        }
    }

    // Collections don't have integrated version, these piggyback on parent's owner version (for DB).
    // However, this version number isn't extractable and is not passed to cache methods.
    AccessType collectionAccessType = accessType == AccessType.NONSTRICT_READ_WRITE ? AccessType.READ_WRITE
            : accessType;
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy(collectionAccessType.getExternalName());
    }

    return metadata;
}

From source file:org.infinispan.test.hibernate.cache.commons.stress.SecondLevelCacheStressTestCase.java

License:LGPL

private static Metadata buildMetadata(StandardServiceRegistry registry) {
    final String cacheStrategy = "transactional";

    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }//from   w  w w . j  a va  2s  .co  m

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited()) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheStrategy);
        }
    }

    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy(cacheStrategy);
    }

    return metadata;
}

From source file:org.n52.sos.ds.datasource.CustomConfiguration.java

License:Open Source License

/**
 * Copied from/*from   w  ww  .ja v a 2  s  .com*/
 * {@link org.hibernate.cfg.Configuration#iterateGenerators(Dialect)}.
 */
private Iterator<PersistentIdentifierGenerator> iterateGenerators(final Dialect d, final String c,
        final String s) throws MappingException {
    final TreeMap<Object, PersistentIdentifierGenerator> generators = new TreeMap<Object, PersistentIdentifierGenerator>();
    for (final PersistentClass pc : classes.values()) {
        if (!pc.isInherited()) {
            final IdentifierGenerator ig = pc.getIdentifier()
                    .createIdentifierGenerator(getIdentifierGeneratorFactory(), d, c, s, (RootClass) pc);
            if (ig instanceof PersistentIdentifierGenerator) {
                final PersistentIdentifierGenerator pig = (PersistentIdentifierGenerator) ig;
                generators.put(pig.generatorKey(), pig);
            } else if (ig instanceof IdentifierGeneratorAggregator) {
                ((IdentifierGeneratorAggregator) ig).registerPersistentGenerators(generators);
            }
        }
    }
    for (final Collection collection : collections.values()) {
        if (collection.isIdentified()) {
            final IdentifierGenerator ig = ((IdentifierCollection) collection).getIdentifier()
                    .createIdentifierGenerator(getIdentifierGeneratorFactory(), d, c, s, null);
            if (ig instanceof PersistentIdentifierGenerator) {
                final PersistentIdentifierGenerator pig = (PersistentIdentifierGenerator) ig;
                generators.put(pig.generatorKey(), pig);
            }
        }
    }

    return generators.values().iterator();
}

From source file:test.hibernate.ExecutionEnvironment.java

License:Open Source License

@SuppressWarnings("unchecked")
private void applyCacheSettings(Configuration configuration) {
    if (settings.getCacheConcurrencyStrategy() != null) {
        Iterator iter = configuration.getClassMappings();
        while (iter.hasNext()) {
            PersistentClass clazz = (PersistentClass) iter.next();
            Iterator props = clazz.getPropertyClosureIterator();
            boolean hasLob = false;
            while (props.hasNext()) {
                Property prop = (Property) props.next();
                if (prop.getValue().isSimpleValue()) {
                    String type = ((SimpleValue) prop.getValue()).getTypeName();
                    if ("blob".equals(type) || "clob".equals(type)) {
                        hasLob = true;//  w ww .j  a v a2s. c  o m
                    }
                    if (Blob.class.getName().equals(type) || Clob.class.getName().equals(type)) {
                        hasLob = true;
                    }
                }
            }
            if (!hasLob && !clazz.isInherited() && settings.overrideCacheStrategy()) {
                configuration.setCacheConcurrencyStrategy(clazz.getEntityName(),
                        settings.getCacheConcurrencyStrategy());
            }
        }
        iter = configuration.getCollectionMappings();
        while (iter.hasNext()) {
            Collection coll = (Collection) iter.next();
            configuration.setCollectionCacheConcurrencyStrategy(coll.getRole(),
                    settings.getCacheConcurrencyStrategy());
        }
    }
}