Example usage for org.hibernate.mapping RootClass setCacheConcurrencyStrategy

List of usage examples for org.hibernate.mapping RootClass setCacheConcurrencyStrategy

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass setCacheConcurrencyStrategy.

Prototype

public void setCacheConcurrencyStrategy(String cacheConcurrencyStrategy) 

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindRootPersistentClassCommonValues(GrailsDomainClass domainClass, RootClass root,
        Mappings mappings, String sessionFactoryBeanName) {

    // get the schema and catalog names from the configuration
    Mapping m = getMapping(domainClass.getClazz());
    String schema = mappings.getSchemaName();
    String catalog = mappings.getCatalogName();

    if (m != null) {
        configureDerivedProperties(domainClass, m);
        CacheConfig cc = m.getCache();/* ww w  .j  ava2s  .  c om*/
        if (cc != null && cc.getEnabled()) {
            root.setCacheConcurrencyStrategy(cc.getUsage());
            if ("read-only".equals(cc.getUsage())) {
                root.setMutable(false);
            }
            root.setLazyPropertiesCacheable(!"non-lazy".equals(cc.getInclude()));
        }

        Integer bs = m.getBatchSize();
        if (bs != null) {
            root.setBatchSize(bs);
        }

        if (m.getDynamicUpdate()) {
            root.setDynamicUpdate(true);
        }
        if (m.getDynamicInsert()) {
            root.setDynamicInsert(true);
        }
    }

    final boolean hasTableDefinition = m != null && m.getTable() != null;
    if (hasTableDefinition && m.getTable().getSchema() != null) {
        schema = m.getTable().getSchema();
    }
    if (hasTableDefinition && m.getTable().getCatalog() != null) {
        catalog = m.getTable().getCatalog();
    }

    final boolean isAbstract = m != null && !m.getTablePerHierarchy() && m.isTablePerConcreteClass()
            && root.isAbstract();
    // create the table
    Table table = mappings.addTable(schema, catalog, getTableName(domainClass, sessionFactoryBeanName), null,
            isAbstract);
    root.setTable(table);

    if (LOG.isDebugEnabled()) {
        LOG.debug("[GrailsDomainBinder] Mapping Grails domain class: " + domainClass.getFullName() + " -> "
                + root.getTable().getName());
    }

    bindIdentity(domainClass, root, mappings, m, sessionFactoryBeanName);

    if (m == null) {
        bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
    } else {
        if (m.getVersioned()) {
            bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
        }
    }

    root.createPrimaryKey();

    createClassProperties(domainClass, root, mappings, sessionFactoryBeanName);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

private static void bindRootPersistentClassCommonValues(GrailsDomainClass domainClass, RootClass root,
        Mappings mappings, String sessionFactoryBeanName) {

    // get the schema and catalog names from the configuration
    Mapping m = getMapping(domainClass.getClazz());
    String schema = mappings.getSchemaName();
    String catalog = mappings.getCatalogName();

    if (m != null) {
        configureDerivedProperties(domainClass, m);
        CacheConfig cc = m.getCache();/*from w w w  .  j  av a  2s .  c om*/
        if (cc != null && cc.getEnabled()) {
            root.setCacheConcurrencyStrategy(cc.getUsage());
            if ("read-only".equals(cc.getUsage())) {
                root.setMutable(false);
            }
            root.setLazyPropertiesCacheable(!"non-lazy".equals(cc.getInclude()));
        }

        Integer bs = m.getBatchSize();
        if (bs != null) {
            root.setBatchSize(bs);
        }

        if (m.getDynamicUpdate()) {
            root.setDynamicUpdate(true);
        }
        if (m.getDynamicInsert()) {
            root.setDynamicInsert(true);
        }
    }

    final boolean hasTableDefinition = m != null && m.getTable() != null;
    if (hasTableDefinition && m.getTable().getSchema() != null) {
        schema = m.getTable().getSchema();
    }
    if (hasTableDefinition && m.getTable().getCatalog() != null) {
        catalog = m.getTable().getCatalog();
    }

    // create the table
    Table table = mappings.addTable(schema, catalog, getTableName(domainClass, sessionFactoryBeanName), null,
            false);
    root.setTable(table);

    if (LOG.isDebugEnabled()) {
        LOG.debug("[GrailsDomainBinder] Mapping Grails domain class: " + domainClass.getFullName() + " -> "
                + root.getTable().getName());
    }

    bindIdentity(domainClass, root, mappings, m, sessionFactoryBeanName);

    if (m != null) {
        if (m.getVersioned()) {
            bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
        }
    } else {
        bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
    }

    root.createPrimaryKey();

    createClassProperties(domainClass, root, mappings, sessionFactoryBeanName);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindRootPersistentClassCommonValues(HibernatePersistentEntity domainClass, RootClass root,
        Mappings mappings, String sessionFactoryBeanName) {

    // get the schema and catalog names from the configuration
    Mapping m = getMapping(domainClass.getJavaClass());
    String schema = mappings.getSchemaName();
    String catalog = mappings.getCatalogName();

    if (m != null) {
        configureDerivedProperties(domainClass, m);
        CacheConfig cc = m.getCache();//from  www.  j  ava2 s . c  o  m
        if (cc != null && cc.getEnabled()) {
            root.setCacheConcurrencyStrategy(cc.getUsage());
            if ("read-only".equals(cc.getUsage())) {
                root.setMutable(false);
            }
            root.setLazyPropertiesCacheable(!"non-lazy".equals(cc.getInclude()));
        }

        Integer bs = m.getBatchSize();
        if (bs != null) {
            root.setBatchSize(bs);
        }

        if (m.getDynamicUpdate()) {
            root.setDynamicUpdate(true);
        }
        if (m.getDynamicInsert()) {
            root.setDynamicInsert(true);
        }
    }

    final boolean hasTableDefinition = m != null && m.getTable() != null;
    if (hasTableDefinition && m.getTable().getSchema() != null) {
        schema = m.getTable().getSchema();
    }
    if (hasTableDefinition && m.getTable().getCatalog() != null) {
        catalog = m.getTable().getCatalog();
    }

    final boolean isAbstract = m != null && !m.getTablePerHierarchy() && m.isTablePerConcreteClass()
            && root.isAbstract();
    // create the table
    Table table = mappings.addTable(schema, catalog, getTableName(domainClass, sessionFactoryBeanName), null,
            isAbstract);
    root.setTable(table);

    if (LOG.isDebugEnabled()) {
        LOG.debug("[GrailsDomainBinder] Mapping Grails domain class: " + domainClass.getName() + " -> "
                + root.getTable().getName());
    }

    bindIdentity(domainClass, root, mappings, m, sessionFactoryBeanName);

    if (m == null) {
        bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
    } else {
        if (m.getVersioned()) {
            bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
        }
    }

    root.createPrimaryKey();

    createClassProperties(domainClass, root, mappings, sessionFactoryBeanName);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

protected void bindRootPersistentClassCommonValues(HibernatePersistentEntity domainClass, RootClass root,
        InFlightMetadataCollector mappings, String sessionFactoryBeanName) {

    // get the schema and catalog names from the configuration
    Mapping m = getMapping(domainClass.getJavaClass());

    String schema = getSchemaName(mappings);
    String catalog = getCatalogName(mappings);

    if (m != null) {
        configureDerivedProperties(domainClass, m);
        CacheConfig cc = m.getCache();// w w  w  . j a v  a 2 s .c o m
        if (cc != null && cc.getEnabled()) {
            root.setCacheConcurrencyStrategy(cc.getUsage());
            if ("read-only".equals(cc.getUsage())) {
                root.setMutable(false);
            }
            root.setLazyPropertiesCacheable(!"non-lazy".equals(cc.getInclude()));
        }

        Integer bs = m.getBatchSize();
        if (bs != null) {
            root.setBatchSize(bs);
        }

        if (m.getDynamicUpdate()) {
            root.setDynamicUpdate(true);
        }
        if (m.getDynamicInsert()) {
            root.setDynamicInsert(true);
        }
    }

    final boolean hasTableDefinition = m != null && m.getTable() != null;
    if (hasTableDefinition && m.getTable().getSchema() != null) {
        schema = m.getTable().getSchema();
    }
    if (hasTableDefinition && m.getTable().getCatalog() != null) {
        catalog = m.getTable().getCatalog();
    }

    final boolean isAbstract = m != null && !m.getTablePerHierarchy() && m.isTablePerConcreteClass()
            && root.isAbstract();
    // create the table
    Table table = mappings.addTable(schema, catalog, getTableName(domainClass, sessionFactoryBeanName), null,
            isAbstract);
    root.setTable(table);

    if (LOG.isDebugEnabled()) {
        LOG.debug("[GrailsDomainBinder] Mapping Grails domain class: " + domainClass.getName() + " -> "
                + root.getTable().getName());
    }

    bindIdentity(domainClass, root, mappings, m, sessionFactoryBeanName);

    if (m == null) {
        bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
    } else {
        if (m.getVersioned()) {
            bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName);
        }
    }

    root.createPrimaryKey();

    createClassProperties(domainClass, root, mappings, sessionFactoryBeanName);
}

From source file:org.infinispan.test.hibernate.cache.commons.tm.JBossStandaloneJtaExampleTest.java

License:LGPL

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 NarayanaStandaloneJtaPlatform())
            .applySetting(Environment.CACHE_REGION_FACTORY,
                    TestRegionFactoryProvider.load().getRegionFactoryClass().getName());

    StandardServiceRegistry serviceRegistry = ssrb.build();

    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    metadataSources.addResource("org/infinispan/test/hibernate/cache/commons/functional/entities/Item.hbm.xml");

    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (entityBinding instanceof RootClass) {
            RootClass rootClass = (RootClass) entityBinding;
            rootClass.setCacheConcurrencyStrategy("transactional");
            rootClass.setCachingExplicitlyRequested(true);
        }//from  ww w . ja  v a2s  . c  o  m
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy("transactional");
    }

    return metadata.buildSessionFactory();
}