Search in sources :

Example 1 with Collection

use of org.hibernate.mapping.Collection 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 Collection

use of org.hibernate.mapping.Collection 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 Collection

use of org.hibernate.mapping.Collection 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 Collection

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

the class AuditMetadataGenerator method addValueInSecondPass.

private void addValueInSecondPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, boolean insertable, boolean processModifiedFlag) {
    final Type type = value.getType();
    if (type instanceof ComponentType) {
        componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, false);
        // mod flag field has been already generated in first pass
        return;
    } else if (type instanceof ManyToOneType) {
        toOneRelationMetadataGenerator.addToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable);
    } else if (type instanceof OneToOneType) {
        final OneToOne oneToOne = (OneToOne) value;
        if (oneToOne.getReferencedPropertyName() != null) {
            toOneRelationMetadataGenerator.addOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName);
        } else {
            // @OneToOne relation marked with @PrimaryKeyJoinColumn
            toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value, currentMapper, entityName, insertable);
        }
    } else if (type instanceof CollectionType) {
        final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Collection) value, currentMapper, entityName, xmlMappingData, propertyAuditingData);
        collectionMetadataGenerator.addCollection();
    } else {
        return;
    }
    addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
}
Also used : CollectionType(org.hibernate.type.CollectionType) ManyToOneType(org.hibernate.type.ManyToOneType) ComponentType(org.hibernate.type.ComponentType) OneToOneType(org.hibernate.type.OneToOneType) TimestampType(org.hibernate.type.TimestampType) Type(org.hibernate.type.Type) ComponentType(org.hibernate.type.ComponentType) OneToOne(org.hibernate.mapping.OneToOne) ManyToOneType(org.hibernate.type.ManyToOneType) CollectionType(org.hibernate.type.CollectionType) Collection(org.hibernate.mapping.Collection) OneToOneType(org.hibernate.type.OneToOneType)

Example 5 with Collection

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

the class InFlightMetadataCollectorImpl method processExportableProducers.

private void processExportableProducers(MetadataBuildingContext buildingContext) {
    // for now we only handle id generators as ExportableProducers
    final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
    final String defaultCatalog = extractName(getDatabase().getDefaultNamespace().getName().getCatalog(), dialect);
    final String defaultSchema = extractName(getDatabase().getDefaultNamespace().getName().getSchema(), dialect);
    for (PersistentClass entityBinding : entityBindingMap.values()) {
        if (entityBinding.isInherited()) {
            continue;
        }
        handleIdentifierValueBinding(entityBinding.getIdentifier(), dialect, defaultCatalog, defaultSchema, (RootClass) entityBinding);
    }
    for (Collection collection : collectionBindingMap.values()) {
        if (!IdentifierCollection.class.isInstance(collection)) {
            continue;
        }
        handleIdentifierValueBinding(((IdentifierCollection) collection).getIdentifier(), dialect, defaultCatalog, defaultSchema, null);
    }
}
Also used : Dialect(org.hibernate.dialect.Dialect) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierCollection(org.hibernate.mapping.IdentifierCollection)

Aggregations

Collection (org.hibernate.mapping.Collection)107 Test (org.junit.Test)76 Bag (org.hibernate.mapping.Bag)41 IdentifierBag (org.hibernate.mapping.IdentifierBag)41 PersistentClass (org.hibernate.mapping.PersistentClass)22 SimpleValue (org.hibernate.mapping.SimpleValue)21 Table (org.hibernate.mapping.Table)19 Set (org.hibernate.mapping.Set)17 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)16 Property (org.hibernate.mapping.Property)11 Metadata (org.hibernate.boot.Metadata)9 MetadataSources (org.hibernate.boot.MetadataSources)9 Column (org.hibernate.mapping.Column)9 KeyValue (org.hibernate.mapping.KeyValue)9 ManyToOne (org.hibernate.mapping.ManyToOne)9 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)8 Iterator (java.util.Iterator)7 Component (org.hibernate.mapping.Component)7 OneToMany (org.hibernate.mapping.OneToMany)7 RootClass (org.hibernate.mapping.RootClass)6