Search in sources :

Example 1 with RootClass

use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.

the class PutFromLoadStressTestCase method beforeClass.

@BeforeClass
public static void beforeClass() {
    // Extra options located in src/test/resources/hibernate.properties
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.CACHE_REGION_FACTORY, "org.hibernate.cache.infinispan.InfinispanRegionFactory").applySetting(Environment.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform").applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.HBM2DDL_AUTO, "create-drop");
    StandardServiceRegistry serviceRegistry = ssrb.build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry).addResource("cache/infinispan/functional/Item.hbm.xml").addResource("cache/infinispan/functional/Customer.hbm.xml").addResource("cache/infinispan/functional/Contact.hbm.xml").addAnnotatedClass(Age.class);
    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (entityBinding instanceof RootClass) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional");
        }
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy("transactional");
    }
    sessionFactory = metadata.buildSessionFactory();
    tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) BeforeClass(org.junit.BeforeClass)

Example 2 with RootClass

use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.

the class SecondLevelCacheStressTestCase method buildMetadata.

private static Metadata buildMetadata(StandardServiceRegistry registry) {
    final String cacheStrategy = "transactional";
    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }
    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;
}
Also used : RootClass(org.hibernate.mapping.RootClass) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 3 with RootClass

use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.

the class JBossStandaloneJtaExampleTest method buildSessionFactory.

private SessionFactory buildSessionFactory() {
    // Extra options located in src/test/resources/hibernate.properties
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()).applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory").applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()).applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta").applySetting(Environment.RELEASE_CONNECTIONS, "auto").applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.JTA_PLATFORM, new JBossStandAloneJtaPlatform()).applySetting(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName());
    StandardServiceRegistry serviceRegistry = ssrb.build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    metadataSources.addResource("org/hibernate/test/cache/infinispan/functional/entities/Item.hbm.xml");
    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (entityBinding instanceof RootClass) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional");
        }
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy("transactional");
    }
    return metadata.buildSessionFactory();
}
Also used : RootClass(org.hibernate.mapping.RootClass) JtaAwareConnectionProviderImpl(org.hibernate.testing.jta.JtaAwareConnectionProviderImpl) JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) JBossStandAloneJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 4 with RootClass

use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.

the class AbstractFunctionalTest method afterMetadataBuilt.

@Override
protected void afterMetadataBuilt(Metadata metadata) {
    if (addVersions) {
        for (PersistentClass clazz : metadata.getEntityBindings()) {
            if (clazz.getVersion() != null) {
                continue;
            }
            try {
                clazz.getMappedClass().getMethod("getVersion");
                clazz.getMappedClass().getMethod("setVersion", long.class);
            } catch (NoSuchMethodException e) {
                continue;
            }
            RootClass rootClazz = clazz.getRootClass();
            Property versionProperty = new Property();
            versionProperty.setName("version");
            SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable());
            value.setTypeName("long");
            Column column = new Column();
            column.setValue(value);
            column.setName("version");
            value.addColumn(column);
            rootClazz.getTable().addColumn(column);
            versionProperty.setValue(value);
            rootClazz.setVersion(versionProperty);
            rootClazz.addProperty(versionProperty);
        }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Column(org.hibernate.mapping.Column) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 5 with RootClass

use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.

the class ModelBinder method bindEntityHierarchy.

public void bindEntityHierarchy(EntityHierarchySourceImpl hierarchySource) {
    final RootClass rootEntityDescriptor = new RootClass(metadataBuildingContext);
    bindRootEntity(hierarchySource, rootEntityDescriptor);
    hierarchySource.getRoot().getLocalMetadataBuildingContext().getMetadataCollector().addEntityBinding(rootEntityDescriptor);
    switch(hierarchySource.getHierarchyInheritanceType()) {
        case NO_INHERITANCE:
            {
                // nothing to do
                break;
            }
        case DISCRIMINATED:
            {
                bindDiscriminatorSubclassEntities(hierarchySource.getRoot(), rootEntityDescriptor);
                break;
            }
        case JOINED:
            {
                bindJoinedSubclassEntities(hierarchySource.getRoot(), rootEntityDescriptor);
                break;
            }
        case UNION:
            {
                bindUnionSubclassEntities(hierarchySource.getRoot(), rootEntityDescriptor);
                break;
            }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass)

Aggregations

RootClass (org.hibernate.mapping.RootClass)223 Test (org.junit.Test)172 SimpleValue (org.hibernate.mapping.SimpleValue)89 Component (org.hibernate.mapping.Component)59 PersistentClass (org.hibernate.mapping.PersistentClass)55 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)55 Table (org.hibernate.mapping.Table)48 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)33 Column (org.hibernate.mapping.Column)28 Configuration (org.hibernate.cfg.Configuration)27 MetadataSources (org.hibernate.boot.MetadataSources)25 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 OneToOne (org.hibernate.mapping.OneToOne)25 Property (org.hibernate.mapping.Property)25 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)24 ArrayList (java.util.ArrayList)21 Method (java.lang.reflect.Method)20 HashMap (java.util.HashMap)20 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)20 ServiceRegistry (org.hibernate.service.ServiceRegistry)19