Java 类org.hibernate.cfg.AvailableSettings 实例源码

项目:testee.fi    文件:PropertyContributor.java   
@Override
public void contribute(final Properties properties, final String provider) {
    if (!provider.equals(HIBERNATE_PROVIDER)) {
        return;
    }
    properties.put(
            AvailableSettings.SCANNER_ARCHIVE_INTERPRETER,
            new TestEEfiArchiveDescriptorFactory()
    );
    // TODO find out why eclipselink allows TX access by default while Hibernate doesn't
    properties.put(
            AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS,
            true
    );
    properties.put(
            AvailableSettings.JTA_PLATFORM,
            new TestEEfiJtaPlatform(transactionManager(), transactionServices)
    );
}
项目:endpoint-health    文件:EndPointHealthServletContextListener.java   
@Override
protected Injector getInjector() {
    final Properties persistenceUnitProperties = new Properties();

    persistenceUnitProperties.put(AvailableSettings.JPA_JDBC_URL,
        Utils.getDatabaseUrl(endPointHealthConfiguration.databaseFile()));

    persistenceUnitProperties.put(AvailableSettings.JPA_JDBC_USER,
        endPointHealthConfiguration.databaseUser());

    persistenceUnitProperties.put(AvailableSettings.JPA_JDBC_PASSWORD,
        endPointHealthConfiguration.databasePassword());

    return Guice.createInjector(
        new JpaPersistModule(PERSISTENCE_UNIT).properties(persistenceUnitProperties),
        new EndPointHealthServletModule());
}
项目:lams    文件:LocalSessionFactoryBuilder.java   
/**
 * Build the {@code SessionFactory}.
 */
@Override
@SuppressWarnings("deprecation")
public SessionFactory buildSessionFactory() throws HibernateException {
    ClassLoader appClassLoader = (ClassLoader) getProperties().get(AvailableSettings.APP_CLASSLOADER);
    Thread currentThread = Thread.currentThread();
    ClassLoader threadContextClassLoader = currentThread.getContextClassLoader();
    boolean overrideClassLoader =
            (appClassLoader != null && !appClassLoader.equals(threadContextClassLoader));
    if (overrideClassLoader) {
        currentThread.setContextClassLoader(appClassLoader);
    }
    try {
        return super.buildSessionFactory();
    }
    finally {
        if (overrideClassLoader) {
            currentThread.setContextClassLoader(threadContextClassLoader);
        }
    }
}
项目:lams    文件:SchemaExport.java   
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) {
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
            serviceRegistry.getService( ConnectionProvider.class )
    );
    this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
    this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            configuration.getProperties(),
            DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams    文件:SchemaExport.java   
public SchemaExport(MetadataImplementor metadata) {
    ServiceRegistry serviceRegistry = metadata.getServiceRegistry();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
            serviceRegistry.getService( ConnectionProvider.class )
    );
       JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
    this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            serviceRegistry.getService( ConfigurationService.class ).getSettings(),
            DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = jdbcServices.getDialect();
    this.dropSQL = metadata.getDatabase().generateDropSchemaScript( dialect );
    this.createSQL = metadata.getDatabase().generateSchemaCreationScript( dialect );
}
项目:lams    文件:SchemaExport.java   
/**
 * Create a schema exporter for the given Configuration, with the given
 * database connection properties.
 *
 * @param configuration The configuration from which to build a schema export.
 * @param properties The properties from which to configure connectivity etc.
 * @throws HibernateException Indicates problem preparing for schema export.
 *
 * @deprecated properties may be specified via the Configuration object
 */
@Deprecated
   public SchemaExport(Configuration configuration, Properties properties) throws HibernateException {
    final Dialect dialect = Dialect.getDialect( properties );

    Properties props = new Properties();
    props.putAll( dialect.getDefaultProperties() );
    props.putAll( properties );
    this.connectionHelper = new ManagedProviderConnectionHelper( props );

    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
    this.sqlExceptionHelper = new SqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            properties,
            DEFAULT_IMPORT_FILE
    );

    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams    文件:SchemaExport.java   
/**
 * Create a schema exporter for the given Configuration, using the supplied connection for connectivity.
 *
 * @param configuration The configuration to use.
 * @param connection The JDBC connection to use.
 * @throws HibernateException Indicates problem preparing for schema export.
 */
public SchemaExport(Configuration configuration, Connection connection) throws HibernateException {
    this.connectionHelper = new SuppliedConnectionHelper( connection );

    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
    this.sqlExceptionHelper = new SqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            configuration.getProperties(),
            DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = Dialect.getDialect( configuration.getProperties() );
    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams    文件:JmxServiceImpl.java   
@Override
public void registerService(Manageable service, Class<? extends Service> serviceRole) {
    final String domain = service.getManagementDomain() == null
            ? AvailableSettings.JMX_DEFAULT_OBJ_NAME_DOMAIN
            : service.getManagementDomain();
    final String serviceType = service.getManagementServiceType() == null
            ? service.getClass().getName()
            : service.getManagementServiceType();
    try {
        final ObjectName objectName = new ObjectName(
                String.format(
                        OBJ_NAME_TEMPLATE,
                        domain,
                        sessionFactoryName,
                        serviceRole.getName(),
                        serviceType
                )
        );
        registerMBean( objectName, service.getManagementBean() );
    }
    catch ( MalformedObjectNameException e ) {
        throw new HibernateException( "Unable to generate service IbjectName", e );
    }
}
项目:rjb-blog-multitenancy    文件:HibernateConfig.java   
protected LocalSessionFactoryBean createSessionFactoryBean() {

        LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
        factoryBean.setDataSource(this.dataSourceConfig.dataSource());

        if (StringUtil.isEmpty(this.propertiesConfig.hibernateDialect())) {
            throw new IllegalStateException("hibernateDialect is required");
        }

        factoryBean.getHibernateProperties().setProperty(AvailableSettings.DIALECT,
                this.propertiesConfig.hibernateDialect());

        if (!ArrayUtil.isEmpty(this.propertiesConfig.hibernateMappingLocations())) {
            factoryBean
                    .setMappingLocations(this.propertiesConfig.hibernateMappingLocations());
        }

        return factoryBean;

    }
项目:spring4-understanding    文件:LocalSessionFactoryBuilder.java   
/**
 * Build the {@code SessionFactory}.
 */
@Override
@SuppressWarnings("deprecation")
public SessionFactory buildSessionFactory() throws HibernateException {
    ClassLoader appClassLoader = (ClassLoader) getProperties().get(AvailableSettings.APP_CLASSLOADER);
    Thread currentThread = Thread.currentThread();
    ClassLoader threadContextClassLoader = currentThread.getContextClassLoader();
    boolean overrideClassLoader =
            (appClassLoader != null && !appClassLoader.equals(threadContextClassLoader));
    if (overrideClassLoader) {
        currentThread.setContextClassLoader(appClassLoader);
    }
    try {
        return super.buildSessionFactory();
    }
    finally {
        if (overrideClassLoader) {
            currentThread.setContextClassLoader(threadContextClassLoader);
        }
    }
}
项目:spring4-understanding    文件:HibernateTransactionManagerTests.java   
@Test
public void testSetJtaTransactionManager() throws Exception {
    DataSource ds = mock(DataSource.class);
    TransactionManager tm = mock(TransactionManager.class);
    UserTransaction ut = mock(UserTransaction.class);
    TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
    JtaTransactionManager jtm = new JtaTransactionManager();
    jtm.setTransactionManager(tm);
    jtm.setUserTransaction(ut);
    jtm.setTransactionSynchronizationRegistry(tsr);
    LocalSessionFactoryBuilder lsfb = new LocalSessionFactoryBuilder(ds);
    lsfb.setJtaTransactionManager(jtm);
    Object jtaPlatform = lsfb.getProperties().get(AvailableSettings.JTA_PLATFORM);
    assertNotNull(jtaPlatform);
    assertSame(tm, jtaPlatform.getClass().getMethod("retrieveTransactionManager").invoke(jtaPlatform));
    assertSame(ut, jtaPlatform.getClass().getMethod("retrieveUserTransaction").invoke(jtaPlatform));
    assertTrue(lsfb.getProperties().get(AvailableSettings.TRANSACTION_STRATEGY) instanceof CMTTransactionFactory);
}
项目:HikariCP    文件:HikariConfigurationUtil.java   
/**
 * Create/load a HikariConfig from Hibernate properties.
 *
 * @param props a map of Hibernate properties
 * @return a HikariConfig
 */
@SuppressWarnings("rawtypes")
public static HikariConfig loadConfiguration(Map props)
{
   Properties hikariProps = new Properties();
   copyProperty(AvailableSettings.ISOLATION, props, "transactionIsolation", hikariProps);
   copyProperty(AvailableSettings.AUTOCOMMIT, props, "autoCommit", hikariProps);
   copyProperty(AvailableSettings.DRIVER, props, "driverClassName", hikariProps);
   copyProperty(AvailableSettings.URL, props, "jdbcUrl", hikariProps);
   copyProperty(AvailableSettings.USER, props, "username", hikariProps);
   copyProperty(AvailableSettings.PASS, props, "password", hikariProps);

   for (Object keyo : props.keySet()) {
      String key = (String) keyo;
      if (key.startsWith(CONFIG_PREFIX)) {
         hikariProps.setProperty(key.substring(CONFIG_PREFIX.length()), (String) props.get(key));
      }
   }

   return new HikariConfig(hikariProps);
}
项目:appengine-hibernate    文件:Hibernate.java   
private static EntityManagerFactory newFactory(Map<String, String> extraProperties) {

    LOGGER.info("Creating EntityManagerFactory...");

    try {

        Map<String, String> properties = new HashMap<>();
        properties.putAll(extraProperties);


        if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
            properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.GoogleDriver");
            properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url"));
        } else {
            properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
            properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url.dev"));
        }

        properties.put(org.hibernate.ejb.AvailableSettings.INTERCEPTOR, TimingInterceptor.class.getName());

        return Persistence.createEntityManagerFactory("Demo", properties);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to create EntityManagerFactory", e);
        throw e;
    }
}
项目:cosmo    文件:ItemDaoImpl.java   
@SuppressWarnings("unchecked")
public <STAMP_TYPE extends Stamp> STAMP_TYPE findStampByInternalItemUid(String internalItemUid,
        Class<STAMP_TYPE> clazz) {
    try (StatelessSession session = this.openStatelessSession()){

        List<Stamp> stamps = (List<Stamp>) session.createNamedQuery("item.stamps.by.uid")
                .setParameter("uid", internalItemUid)
                .setHint(AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, null)
                .setHint(AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE, null)
                .getResultList();
        for (Stamp stamp : stamps) {
            if (clazz.isInstance(stamp)) {
                return clazz.cast(stamp);
            }
        }
    } catch (HibernateException e) {
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
    return null;
}
项目:class-guard    文件:LocalSessionFactoryBuilder.java   
/**
 * Build the {@code SessionFactory}.
 */
@Override
@SuppressWarnings("deprecation")
public SessionFactory buildSessionFactory() throws HibernateException {
    ClassLoader appClassLoader = (ClassLoader) getProperties().get(AvailableSettings.APP_CLASSLOADER);
    Thread currentThread = Thread.currentThread();
    ClassLoader threadContextClassLoader = currentThread.getContextClassLoader();
    boolean overrideClassLoader =
            (appClassLoader != null && !appClassLoader.equals(threadContextClassLoader));
    if (overrideClassLoader) {
        currentThread.setContextClassLoader(appClassLoader);
    }
    try {
        return super.buildSessionFactory();
    }
    finally {
        if (overrideClassLoader) {
            currentThread.setContextClassLoader(threadContextClassLoader);
        }
    }
}
项目:org.fastnate    文件:HibernateProvider.java   
private static Class<? extends GeneratorDialect> getGeneratorDialectFromConnectionDriver(
        final Properties settings) {
    final String connectionDriver = settings.getProperty(AvailableSettings.DRIVER);
    if (connectionDriver != null) {
        if (connectionDriver.contains("postgresql")) {
            return PostgresDialect.class;
        }
        if (connectionDriver.contains("mysql")) {
            return MySqlDialect.class;
        }
        if (connectionDriver.contains("sqlserver")) {
            return MsSqlDialect.class;
        }
        if (connectionDriver.contains(".h2.")) {
            return H2Dialect.class;
        }
        if (connectionDriver.contains("oracle")) {
            return OracleDialect.class;
        }
    }
    return null;
}
项目:org.fastnate    文件:HibernateProvider.java   
private static Class<? extends GeneratorDialect> getGeneratorDialectFromConnectionUrl(final Properties settings) {
    final String connectionUrl = settings.getProperty(AvailableSettings.URL);
    if (connectionUrl != null) {
        if (connectionUrl.contains(":oracle:")) {
            return OracleDialect.class;
        }
        if (connectionUrl.contains(":postgresql:")) {
            return PostgresDialect.class;
        }
        if (connectionUrl.contains(":mysql:")) {
            return MySqlDialect.class;
        }
        if (connectionUrl.contains(":sqlserver:")) {
            return MsSqlDialect.class;
        }
        if (connectionUrl.contains(":h2:")) {
            return H2Dialect.class;
        }
    }
    return null;
}
项目:org.fastnate    文件:HibernateProvider.java   
private static Class<? extends GeneratorDialect> getGeneratorDialectFromHibernateDialect(
        final Properties settings) {
    final String hibernateDialect = settings.getProperty(AvailableSettings.DIALECT);
    if (hibernateDialect != null) {
        if (hibernateDialect.contains("Oracle")) {
            return OracleDialect.class;
        }
        if (hibernateDialect.contains("PostgreSQL")) {
            return PostgresDialect.class;
        }
        if (hibernateDialect.contains("MySQL")) {
            return MySqlDialect.class;
        }
        if (hibernateDialect.contains("SQLServer")) {
            return MsSqlDialect.class;
        }
        if (hibernateDialect.contains("H2Dialect")) {
            return H2Dialect.class;
        }
    }
    return null;
}
项目:hibernate4-memcached    文件:EntityTestUtils.java   
public static void init() {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, true);
    props.put(AvailableSettings.USE_QUERY_CACHE, true);
    props.put(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, CacheConcurrencyStrategy.NONSTRICT_READ_WRITE);
    props.put(AvailableSettings.CACHE_REGION_FACTORY, Hibernate4MemcachedRegionFactory.class.getName());
    props.put(AvailableSettings.CACHE_REGION_PREFIX, "cachetest");
    props.put(AvailableSettings.CACHE_PROVIDER_CONFIG, "META-INF/h4m-properties.xml");
    props.put(AvailableSettings.HBM2DDL_AUTO, "create");
    props.put(AvailableSettings.USE_STRUCTURED_CACHE, "false");
    props.put(Hibernate4MemcachedRegionFactory.MEMCACHED_ADAPTER_CLASS_PROPERTY_KEY,
            SpyMemcachedAdapter.class.getName());
    props.put(SpyMemcachedAdapter.HOST_PROPERTY_KEY, "localhost:11211");
    props.put(SpyMemcachedAdapter.HASH_ALGORITHM_PROPERTY_KEY, DefaultHashAlgorithm.KETAMA_HASH.name());
    props.put(SpyMemcachedAdapter.OPERATION_TIMEOUT_MILLIS_PROPERTY_KEY, "5000");
    props.put(SpyMemcachedAdapter.TRANSCODER_PROPERTY_KEY, KryoTranscoder.class.getName());
    props.put(SpyMemcachedAdapter.CACHE_KEY_PREFIX_PROPERTY_KEY, "h4m");
    props.put(KryoTranscoder.COMPRESSION_THREASHOLD_PROPERTY_KEY, "20000");

    emf = Persistence.createEntityManagerFactory("cachetest", props);
}
项目:osgi-hibernate    文件:HibernatePersistenceProvider.java   
protected Map<?, ?> generateExtendedSettings(final Map<?, ?> map) {
    Map<Object, Object> result = null;
    if (map == null) {
        result = new ConcurrentHashMap<Object, Object>();
    } else {
        result = new ConcurrentHashMap<Object, Object>(map);
    }
    result.put("javax.persistence.validation.factory", getValidatorFactory());
    result.put(AvailableSettings.JTA_CACHE_TM, false);
    result.put(AvailableSettings.JTA_CACHE_UT, false);

    OsgiJtaPlatform osgiJtaPlatform = new OsgiJtaPlatform(transactionManagerTracker, userTransactionTracker);
    osgiJtaPlatform.configure(result);
    result.put(AvailableSettings.JTA_PLATFORM, osgiJtaPlatform);
    return result;
}
项目:dropwizard-routing    文件:RoutingSessionFactoryFactory.java   
/**
 * Builds a {@link SessionFactory}
 * @param bundle
 *            the bundle
 * @param dbConfig
 *            the dbconfig
 * @param connectionProvider
 *            the connection provider
 * @param properties
 *            the hibernate properties
 * @param entities
 *            the persistent entities
 * @return {@link SessionFactory}
 */
private SessionFactory buildSessionFactory(RoutingHibernateBundle<?> bundle, DataSourceFactory dbConfig,
        ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS,
            Boolean.toString(dbConfig.isAutoCommentsEnabled()));
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
    configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
    for (Map.Entry<String, String> property : properties.entrySet()) {
        configuration.setProperty(property.getKey(), property.getValue());
    }

    addAnnotatedClasses(configuration, entities);
    bundle.configure(configuration);

    final ServiceRegistry registry = new StandardServiceRegistryBuilder()
            .addService(ConnectionProvider.class, connectionProvider).applySettings(properties).build();

    return configuration.buildSessionFactory(registry);
}
项目:jipijapa    文件:InfinispanRegionFactory.java   
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
    // Find a suitable service name to represent this session factory instance
    String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
    String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
    HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);

    Properties cacheSettings = new Properties();
    cacheSettings.put(HibernateSecondLevelCache.CACHE_TYPE,CACHE_PRIVATE);
    cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
    if (name != null) {
        cacheSettings.put(HibernateSecondLevelCache.NAME, name);
    }

    try {
        // start a private cache for non-JPA use and return the started cache.
        wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
        return (EmbeddedCacheManager)wrapper.getValue();
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
项目:jipijapa    文件:InfinispanRegionFactory.java   
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
    // Find a suitable service name to represent this session factory instance
    String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
    String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
    HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);

    Properties cacheSettings = new Properties();
    cacheSettings.put(HibernateSecondLevelCache.CACHE_TYPE,CACHE_PRIVATE);
    cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
    if (name != null) {
        cacheSettings.put(HibernateSecondLevelCache.NAME, name);
    }


    try {
        // start a private cache for non-JPA use and return the started cache.
        wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
        return (EmbeddedCacheManager)wrapper.getValue();
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
项目:ToDoApp-Spring    文件:HibernateConfig.java   
Properties getHibernateProperties() {
    return new Properties() {
        {
            setProperty(AvailableSettings.DIALECT, env.getRequiredProperty("hibernate.dialect"));
            setProperty(AvailableSettings.SHOW_SQL, env.getRequiredProperty("hibernate.show_sql"));
            setProperty(AvailableSettings.HBM2DDL_AUTO, env.getRequiredProperty("hibernate.hbm2ddl.auto"));
            setProperty(AvailableSettings.STATEMENT_BATCH_SIZE, env.getRequiredProperty("hibernate.batch.size"));
            setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, env.getRequiredProperty("hibernate.current.session.context.class"));
        }
    };
}
项目:lams    文件:LocalSessionFactoryBuilder.java   
/**
 * Create a new LocalSessionFactoryBuilder for the given DataSource.
 * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using
 * (may be {@code null})
 * @param resourceLoader the ResourceLoader to load application classes from
 */
@SuppressWarnings("deprecation")  // to be able to build against Hibernate 4.3
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
    getProperties().put(Environment.CURRENT_SESSION_CONTEXT_CLASS, SpringSessionContext.class.getName());
    if (dataSource != null) {
        getProperties().put(Environment.DATASOURCE, dataSource);
    }
    // APP_CLASSLOADER is deprecated as of Hibernate 4.3 but we need to remain compatible with 4.0+
    getProperties().put(AvailableSettings.APP_CLASSLOADER, resourceLoader.getClassLoader());
    this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
}
项目:lams    文件:LocalSessionFactoryBuilder.java   
/**
 * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager}
 * to be used with Hibernate, if any. Allows for using a Spring-managed transaction
 * manager for Hibernate 4's session and cache synchronization, with the
 * "hibernate.transaction.jta.platform" automatically set to it. Also sets
 * "hibernate.transaction.factory_class" to {@link CMTTransactionFactory},
 * instructing Hibernate to interact with externally managed transactions.
 * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA
 * {@link TransactionManager} reference to be usable here, except for the WebSphere
 * case where we'll automatically set {@code WebSphereExtendedJtaPlatform} accordingly.
 * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform
 * setting to avoid meaningless double configuration.
 */
public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) {
    Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null");
    if (jtaTransactionManager instanceof JtaTransactionManager) {
        boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager", getClass().getClassLoader());
        if (webspherePresent) {
            getProperties().put(AvailableSettings.JTA_PLATFORM,
                    ConfigurableJtaPlatform.getJtaPlatformBasePackage() + "internal.WebSphereExtendedJtaPlatform");
        }
        else {
            JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager;
            if (jtaTm.getTransactionManager() == null) {
                throw new IllegalArgumentException(
                        "Can only apply JtaTransactionManager which has a TransactionManager reference set");
            }
            getProperties().put(AvailableSettings.JTA_PLATFORM,
                    new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction(),
                            jtaTm.getTransactionSynchronizationRegistry()).getJtaPlatformProxy());
        }
    }
    else if (jtaTransactionManager instanceof TransactionManager) {
        getProperties().put(AvailableSettings.JTA_PLATFORM,
                new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null, null).getJtaPlatformProxy());
    }
    else {
        throw new IllegalArgumentException(
                "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName());
    }
    getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory());
    return this;
}
项目:lams    文件:IdentifierGeneratorResolver.java   
@SuppressWarnings( {"unchecked"} )
void resolve() {
    for ( EntityBinding entityBinding : metadata.getEntityBindings() ) {
        if ( entityBinding.isRoot() ) {
            Properties properties = new Properties( );
            properties.putAll(
                    metadata.getServiceRegistry()
                            .getService( ConfigurationService.class )
                            .getSettings()
            );
            //TODO: where should these be added???
            if ( ! properties.contains( AvailableSettings.PREFER_POOLED_VALUES_LO ) ) {
                properties.put( AvailableSettings.PREFER_POOLED_VALUES_LO, "false" );
            }
            if ( ! properties.contains( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER ) ) {
                properties.put(
                        PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
                        new ObjectNameNormalizerImpl( metadata )
                );
            }
            entityBinding.getHierarchyDetails().getEntityIdentifier().createIdentifierGenerator(
                    metadata.getIdentifierGeneratorFactory(),
                    properties
            );
        }
    }
}
项目:lams    文件:DatabaseMetadata.java   
public DatabaseMetadata(Connection connection, Dialect dialect, Configuration config, boolean extras)
        throws SQLException {
    sqlExceptionConverter = dialect.buildSQLExceptionConverter();
    meta = connection.getMetaData();
    this.extras = extras;
    initSequences( connection, dialect );
    if ( config != null
            && ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, config.getProperties(), false ) ) {
        types = new String[] { "TABLE", "VIEW", "SYNONYM" };
    }
    else {
        types = new String[] { "TABLE", "VIEW" };
    }
}
项目:lams    文件:JmxServiceImpl.java   
public JmxServiceImpl(Map configValues) {
    usePlatformServer = ConfigurationHelper.getBoolean( AvailableSettings.JMX_PLATFORM_SERVER, configValues );
    agentId = (String) configValues.get( AvailableSettings.JMX_AGENT_ID );
    defaultDomain = (String) configValues.get( AvailableSettings.JMX_DOMAIN_NAME );
    sessionFactoryName = ConfigurationHelper.getString(
            AvailableSettings.JMX_SF_NAME,
            configValues,
            ConfigurationHelper.getString( Environment.SESSION_FACTORY_NAME, configValues )
    );
}
项目:lams    文件:JtaPlatformResolverInitiator.java   
@Override
public JtaPlatformResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER );
    final JtaPlatformResolver resolver = registry.getService( StrategySelector.class )
            .resolveStrategy( JtaPlatformResolver.class, setting );
    if ( resolver == null ) {
        log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() );
        return StandardJtaPlatformResolver.INSTANCE;
    }
    return resolver;
}
项目:lams    文件:JtaPlatformInitiator.java   
@Override
@SuppressWarnings( {"unchecked"})
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
    final JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
    if ( platform == null ) {
        LOG.debugf( "No JtaPlatform was specified, checking resolver" );
        return registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
    }
    return platform;
}
项目:lams    文件:AbstractJtaPlatform.java   
public void configure(Map configValues) {
    cacheTransactionManager = ConfigurationHelper.getBoolean(
            AvailableSettings.JTA_CACHE_TM,
            configValues,
            canCacheTransactionManagerByDefault()
    );
    cacheUserTransaction = ConfigurationHelper.getBoolean(
            AvailableSettings.JTA_CACHE_UT,
            configValues,
            canCacheUserTransactionByDefault()
    );
}
项目:lams    文件:TransactionFactoryInitiator.java   
@Override
@SuppressWarnings({"unchecked"})
public TransactionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_STRATEGY );

    if ( strategy == null ) {
        LOG.usingDefaultTransactionStrategy();
        return new JdbcTransactionFactory();
    }

    return registry.getService( StrategySelector.class ).resolveStrategy( TransactionFactory.class, strategy );
}
项目:lams    文件:DriverManagerConnectionProviderImpl.java   
private ConnectionCreator buildCreator(Map configurationValues) {
    final ConnectionCreatorBuilder connectionCreatorBuilder = new ConnectionCreatorBuilder( serviceRegistry );

    final String driverClassName = (String) configurationValues.get( AvailableSettings.DRIVER );
    connectionCreatorBuilder.setDriver( loadDriverIfPossible( driverClassName ) );

    final String url = (String) configurationValues.get( AvailableSettings.URL );
    if ( url == null ) {
        final String msg = log.jdbcUrlNotSpecified( AvailableSettings.URL );
        log.error( msg );
        throw new HibernateException( msg );
    }
    connectionCreatorBuilder.setUrl( url );

    log.usingDriver( driverClassName, url );

    final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( configurationValues );

    // if debug level is enabled, then log the password, otherwise mask it
    if ( log.isDebugEnabled() ) {
        log.connectionProperties( connectionProps );
    }
    else {
        log.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) );
    }
    connectionCreatorBuilder.setConnectionProps( connectionProps );

    final boolean autoCommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, configurationValues, false );
    log.autoCommitMode( autoCommit );
    connectionCreatorBuilder.setAutoCommit( autoCommit );

    final Integer isolation = ConfigurationHelper.getInteger( AvailableSettings.ISOLATION, configurationValues );
    if ( isolation != null ) {
        log.jdbcIsolationLevel( Environment.isolationLevelToString( isolation ) );
    }
    connectionCreatorBuilder.setIsolation( isolation );

    return connectionCreatorBuilder.build();
}
项目:lams    文件:ConnectionProviderInitiator.java   
private static boolean c3p0ConfigDefined(Map configValues) {
    for ( Object key : configValues.keySet() ) {
        if ( String.class.isInstance( key )
                && ( (String) key ).startsWith( AvailableSettings.C3P0_CONFIG_PREFIX ) ) {
            return true;
        }
    }
    return false;
}
项目:lams    文件:ConnectionProviderInitiator.java   
private static boolean proxoolConfigDefined(Map configValues) {
    for ( Object key : configValues.keySet() ) {
        if ( String.class.isInstance( key )
                && ( (String) key ).startsWith( AvailableSettings.PROXOOL_CONFIG_PREFIX ) ) {
            return true;
        }
    }
    return false;
}
项目:lams    文件:DialectFactoryImpl.java   
@Override
public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
    final String dialectName = (String) configValues.get( AvailableSettings.DIALECT );
    if ( !StringHelper.isEmpty( dialectName ) ) {
        return constructDialect( dialectName );
    }
    else {
        return determineDialect( resolutionInfoSource );
    }
}
项目:lams    文件:SessionFactoryImpl.java   
@SuppressWarnings({ "unchecked" })
private CurrentTenantIdentifierResolver determineCurrentTenantIdentifierResolver(
        CurrentTenantIdentifierResolver explicitResolver) {
    if ( explicitResolver != null ) {
        return explicitResolver;
    }
    return serviceRegistry.getService( ConfigurationService.class )
            .getSetting(
                    AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER,
                    CurrentTenantIdentifierResolver.class,
                    null
            );

}
项目:lams    文件:JaccIntegrator.java   
private void doIntegration(
        Map properties,
        JaccPermissionDeclarations permissionDeclarations,
        SessionFactoryServiceRegistry serviceRegistry) {
    boolean isSecurityEnabled = properties.containsKey( AvailableSettings.JACC_ENABLED );
    if ( ! isSecurityEnabled ) {
        log.debug( "Skipping JACC integration as it was not enabled" );
        return;
    }

    final String contextId = (String) properties.get( AvailableSettings.JACC_CONTEXT_ID );
    if ( contextId == null ) {
        throw new IntegrationException( "JACC context id must be specified" );
    }

    final JaccService jaccService = serviceRegistry.getService( JaccService.class );
    if ( jaccService == null ) {
        throw new IntegrationException( "JaccService was not set up" );
    }

    if ( permissionDeclarations != null ) {
        for ( GrantedPermission declaration : permissionDeclarations.getPermissionDeclarations() ) {
            jaccService.addPermission( declaration );
        }
    }

    final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
    eventListenerRegistry.addDuplicationStrategy( DUPLICATION_STRATEGY );

    eventListenerRegistry.prependListeners( EventType.PRE_DELETE, new JaccPreDeleteEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_INSERT, new JaccPreInsertEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_UPDATE, new JaccPreUpdateEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_LOAD, new JaccPreLoadEventListener() );
}
项目:lams    文件:ClassLoaderServiceImpl.java   
/**
 * No longer used/supported!
 *
 * @param configValues The config values
 *
 * @return The built service
 *
 * @deprecated No longer used/supported!
 */
@Deprecated
@SuppressWarnings({"UnusedDeclaration", "unchecked", "deprecation"})
public static ClassLoaderServiceImpl fromConfigSettings(Map configValues) {
    final List<ClassLoader> providedClassLoaders = new ArrayList<ClassLoader>();

    final Collection<ClassLoader> classLoaders = (Collection<ClassLoader>) configValues.get( AvailableSettings.CLASSLOADERS );
    if ( classLoaders != null ) {
        for ( ClassLoader classLoader : classLoaders ) {
            providedClassLoaders.add( classLoader );
        }
    }

    addIfSet( providedClassLoaders, AvailableSettings.APP_CLASSLOADER, configValues );
    addIfSet( providedClassLoaders, AvailableSettings.RESOURCES_CLASSLOADER, configValues );
    addIfSet( providedClassLoaders, AvailableSettings.HIBERNATE_CLASSLOADER, configValues );
    addIfSet( providedClassLoaders, AvailableSettings.ENVIRONMENT_CLASSLOADER, configValues );

    if ( providedClassLoaders.isEmpty() ) {
        log.debugf( "Incoming config yielded no classloaders; adding standard SE ones" );
        final ClassLoader tccl = locateTCCL();
        if ( tccl != null ) {
            providedClassLoaders.add( tccl );
        }
        providedClassLoaders.add( ClassLoaderServiceImpl.class.getClassLoader() );
    }

    return new ClassLoaderServiceImpl( providedClassLoaders );
}