/**
* Determine the appropriate Dialect to use given the database product name
* and major version.
*
* @param databaseName The name of the database product (obtained from metadata).
* @param databaseMajorVersion The major version of the database product (obtained from metadata).
*
* @return An appropriate dialect instance.
*/
public static Dialect determineDialect(String databaseName, int databaseMajorVersion) {
if ( databaseName == null ) {
throw new HibernateException( "Hibernate Dialect must be explicitly set" );
}
DatabaseDialectMapper mapper = ( DatabaseDialectMapper ) MAPPERS.get( databaseName );
if ( mapper == null ) {
throw new HibernateException( "Hibernate Dialect must be explicitly set for database: " + databaseName );
}
String dialectName = mapper.getDialectClass( databaseMajorVersion );
// Push the dialect onto the system properties
System.setProperty(Environment.DIALECT, dialectName);
return buildDialect( dialectName );
}
java类org.hibernate.cfg.Environment的实例源码
DialectFactory.java 文件源码
项目:alfresco-core
阅读 41
收藏 0
点赞 0
评论 0
HibernateServiceImpl.java 文件源码
项目:Equella
阅读 29
收藏 0
点赞 0
评论 0
protected HibernateFactory getHibernateFactory(String name, boolean system)
{
Class<?>[] clazzes = hibernateService.getDomainClasses(name);
DataSourceHolder dataSource;
if( system )
{
dataSource = datasourceService.getSystemDataSource();
}
else
{
dataSource = new DataSourceHolder(institutionAwareDataSource, datasourceService.getDialect());
}
HibernateFactory factory = hibernateService.createConfiguration(dataSource, clazzes);
factory.setClassLoader(getClass().getClassLoader());
factory.setProperty(Environment.TRANSACTION_STRATEGY, SpringTransactionFactory.class.getName());
factory.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, SpringSessionContext.class.getName());
return factory;
}
HibernateJpaVendorAdapter.java 文件源码
项目:lams
阅读 31
收藏 0
点赞 0
评论 0
@Override
public Map<String, Object> getJpaPropertyMap() {
Map<String, Object> jpaProperties = new HashMap<String, Object>();
if (getDatabasePlatform() != null) {
jpaProperties.put(Environment.DIALECT, getDatabasePlatform());
}
else if (getDatabase() != null) {
Class<?> databaseDialectClass = determineDatabaseDialectClass(getDatabase());
if (databaseDialectClass != null) {
jpaProperties.put(Environment.DIALECT, databaseDialectClass.getName());
}
}
if (isGenerateDdl()) {
jpaProperties.put(Environment.HBM2DDL_AUTO, "update");
}
if (isShowSql()) {
jpaProperties.put(Environment.SHOW_SQL, "true");
}
return jpaProperties;
}
BatchBuilderInitiator.java 文件源码
项目:lams
阅读 51
收藏 0
点赞 0
评论 0
@Override
public BatchBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object builder = configurationValues.get( BUILDER );
if ( builder == null ) {
return new BatchBuilderImpl(
ConfigurationHelper.getInt( Environment.STATEMENT_BATCH_SIZE, configurationValues, 1 )
);
}
if ( BatchBuilder.class.isInstance( builder ) ) {
return (BatchBuilder) builder;
}
final String builderClassName = builder.toString();
try {
return (BatchBuilder) registry.getService( ClassLoaderService.class ).classForName( builderClassName ).newInstance();
}
catch (Exception e) {
throw new ServiceException( "Could not build explicit BatchBuilder [" + builderClassName + "]", e );
}
}
SQLExceptionConverterFactory.java 文件源码
项目:lams
阅读 28
收藏 0
点赞 0
评论 0
/**
* Build a SQLExceptionConverter instance.
* <p/>
* First, looks for a {@link Environment#SQL_EXCEPTION_CONVERTER} property to see
* if the configuration specified the class of a specific converter to use. If this
* property is set, attempt to construct an instance of that class. If not set, or
* if construction fails, the converter specific to the dialect will be used.
*
* @param dialect The defined dialect.
* @param properties The configuration properties.
* @return An appropriate SQLExceptionConverter instance.
* @throws HibernateException There was an error building the SQLExceptionConverter.
*/
public static SQLExceptionConverter buildSQLExceptionConverter(Dialect dialect, Properties properties) throws HibernateException {
SQLExceptionConverter converter = null;
String converterClassName = (String) properties.get( Environment.SQL_EXCEPTION_CONVERTER );
if ( StringHelper.isNotEmpty( converterClassName ) ) {
converter = constructConverter( converterClassName, dialect.getViolatedConstraintNameExtracter() );
}
if ( converter == null ) {
LOG.trace( "Using dialect defined converter" );
converter = dialect.buildSQLExceptionConverter();
}
if ( converter instanceof Configurable ) {
try {
( (Configurable) converter ).configure( properties );
}
catch (HibernateException e) {
LOG.unableToConfigureSqlExceptionConverter( e );
throw e;
}
}
return converter;
}
ConfigHelper.java 文件源码
项目:lams
阅读 28
收藏 0
点赞 0
评论 0
public static InputStream getResourceAsStream(String resource) {
String stripped = resource.startsWith("/") ?
resource.substring(1) : resource;
InputStream stream = null;
ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader();
if (classLoader!=null) {
stream = classLoader.getResourceAsStream( stripped );
}
if ( stream == null ) {
stream = Environment.class.getResourceAsStream( resource );
}
if ( stream == null ) {
stream = Environment.class.getClassLoader().getResourceAsStream( stripped );
}
if ( stream == null ) {
throw new HibernateException( resource + " not found" );
}
return stream;
}
InterbaseDialect.java 文件源码
项目:lams
阅读 25
收藏 0
点赞 0
评论 0
/**
* Constructs a InterbaseDialect
*/
public InterbaseDialect() {
super();
registerColumnType( Types.BIT, "smallint" );
registerColumnType( Types.BIGINT, "numeric(18,0)" );
registerColumnType( Types.SMALLINT, "smallint" );
registerColumnType( Types.TINYINT, "smallint" );
registerColumnType( Types.INTEGER, "integer" );
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.VARCHAR, "varchar($l)" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double precision" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARBINARY, "blob" );
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
registerColumnType( Types.BLOB, "blob" );
registerColumnType( Types.CLOB, "blob sub_type 1" );
registerColumnType( Types.BOOLEAN, "smallint" );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "(","||",")" ) );
registerFunction( "current_date", new NoArgSQLFunction( "current_date", StandardBasicTypes.DATE, false ) );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}
JDataStoreDialect.java 文件源码
项目:lams
阅读 36
收藏 0
点赞 0
评论 0
/**
* Creates new JDataStoreDialect
*/
public JDataStoreDialect() {
super();
registerColumnType( Types.BIT, "tinyint" );
registerColumnType( Types.BIGINT, "bigint" );
registerColumnType( Types.SMALLINT, "smallint" );
registerColumnType( Types.TINYINT, "tinyint" );
registerColumnType( Types.INTEGER, "integer" );
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.VARCHAR, "varchar($l)" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARBINARY, "varbinary($l)" );
registerColumnType( Types.NUMERIC, "numeric($p, $s)" );
registerColumnType( Types.BLOB, "varbinary" );
registerColumnType( Types.CLOB, "varchar" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
StandardServiceRegistryBuilder.java 文件源码
项目:lams
阅读 41
收藏 0
点赞 0
评论 0
/**
* Build the StandardServiceRegistry.
*
* @return The StandardServiceRegistry.
*/
@SuppressWarnings("unchecked")
public StandardServiceRegistry build() {
final Map<?,?> settingsCopy = new HashMap();
settingsCopy.putAll( settings );
Environment.verifyProperties( settingsCopy );
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
applyServiceContributingIntegrators();
applyServiceContributors();
return new StandardServiceRegistryImpl(
autoCloseRegistry,
bootstrapServiceRegistry,
initiators,
providedServices,
settingsCopy
);
}
AbstractStandardBasicType.java 文件源码
项目:lams
阅读 29
收藏 0
点赞 0
评论 0
private WrapperOptions getOptions(final SessionImplementor session) {
return new WrapperOptions() {
public boolean useStreamForLobBinding() {
return Environment.useStreamsForBinary()
|| session.getFactory().getDialect().useInputStreamToInsertBlob();
}
public LobCreator getLobCreator() {
return Hibernate.getLobCreator( session );
}
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
final SqlTypeDescriptor remapped = sqlTypeDescriptor.canBeRemapped()
? session.getFactory().getDialect().remapSqlTypeDescriptor( sqlTypeDescriptor )
: sqlTypeDescriptor;
return remapped == null ? sqlTypeDescriptor : remapped;
}
};
}
CalendarDateTypeDescriptor.java 文件源码
项目:lams
阅读 41
收藏 0
点赞 0
评论 0
public <X> Calendar wrap(X value, WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( Calendar.class.isInstance( value ) ) {
return (Calendar) value;
}
if ( ! Date.class.isInstance( value ) ) {
throw unknownWrap( value.getClass() );
}
Calendar cal = new GregorianCalendar();
if ( Environment.jvmHasTimestampBug() ) {
final long milliseconds = ( (Date) value ).getTime();
final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
? ( (java.sql.Timestamp) value ).getNanos()
: 0;
cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) );
}
else {
cal.setTime( (Date) value );
}
return cal;
}
CalendarTimeTypeDescriptor.java 文件源码
项目:lams
阅读 36
收藏 0
点赞 0
评论 0
public <X> Calendar wrap(X value, WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( Calendar.class.isInstance( value ) ) {
return (Calendar) value;
}
if ( ! Date.class.isInstance( value ) ) {
throw unknownWrap( value.getClass() );
}
Calendar cal = new GregorianCalendar();
if ( Environment.jvmHasTimestampBug() ) {
final long milliseconds = ( (Date) value ).getTime();
final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
? ( (java.sql.Timestamp) value ).getNanos()
: 0;
cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) );
}
else {
cal.setTime( (Date) value );
}
return cal;
}
CalendarTypeDescriptor.java 文件源码
项目:lams
阅读 27
收藏 0
点赞 0
评论 0
public <X> Calendar wrap(X value, WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( Calendar.class.isInstance( value ) ) {
return (Calendar) value;
}
if ( ! java.util.Date.class.isInstance( value ) ) {
throw unknownWrap( value.getClass() );
}
Calendar cal = new GregorianCalendar();
if ( Environment.jvmHasTimestampBug() ) {
final long milliseconds = ( (java.util.Date) value ).getTime();
final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
? ( (java.sql.Timestamp) value ).getNanos()
: 0;
cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) );
}
else {
cal.setTime( (java.util.Date) value );
}
return cal;
}
HibernateConfig.java 文件源码
项目:cloud-s4-sdk-examples
阅读 37
收藏 0
点赞 0
评论 0
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider multiTenantConnectionProvider,
CurrentTenantIdentifierResolver tenantIdentifierResolver) {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.mycompany.models");
em.setJpaVendorAdapter(this.jpaVendorAdapter());
final Map<String, Object> jpaProperties = new HashMap<>();
jpaProperties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
jpaProperties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
jpaProperties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantIdentifierResolver);
jpaProperties.put(Environment.FORMAT_SQL, true);
em.setJpaPropertyMap(jpaProperties);
return em;
}
HibernateJpaVendorAdapter.java 文件源码
项目:spring4-understanding
阅读 26
收藏 0
点赞 0
评论 0
@Override
public Map<String, Object> getJpaPropertyMap() {
Map<String, Object> jpaProperties = new HashMap<String, Object>();
if (getDatabasePlatform() != null) {
jpaProperties.put(Environment.DIALECT, getDatabasePlatform());
}
else if (getDatabase() != null) {
Class<?> databaseDialectClass = determineDatabaseDialectClass(getDatabase());
if (databaseDialectClass != null) {
jpaProperties.put(Environment.DIALECT, databaseDialectClass.getName());
}
}
if (isGenerateDdl()) {
jpaProperties.put(Environment.HBM2DDL_AUTO, "update");
}
if (isShowSql()) {
jpaProperties.put(Environment.SHOW_SQL, "true");
}
return jpaProperties;
}
LocalSessionFactoryBeanTests.java 文件源码
项目:spring4-understanding
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void testLocalSessionFactoryBeanWithValidProperties() throws Exception {
final Set invocations = new HashSet();
LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
@Override
protected SessionFactory newSessionFactory(Configuration config) {
assertEquals(UserSuppliedConnectionProvider.class.getName(),
config.getProperty(Environment.CONNECTION_PROVIDER));
assertEquals("myValue", config.getProperty("myProperty"));
invocations.add("newSessionFactory");
return null;
}
};
Properties prop = new Properties();
prop.setProperty(Environment.CONNECTION_PROVIDER, UserSuppliedConnectionProvider.class.getName());
prop.setProperty("myProperty", "myValue");
sfb.setHibernateProperties(prop);
sfb.afterPropertiesSet();
assertTrue(sfb.getConfiguration() != null);
assertTrue(invocations.contains("newSessionFactory"));
}
SessionFactoryController.java 文件源码
项目:openbravo-brazil
阅读 28
收藏 0
点赞 0
评论 0
private Properties getPostgresHbProps(Properties obProps) {
isPostgresDatabase = true;
final Properties props = new Properties();
props.setProperty(Environment.DIALECT, PostgreSQLDialect.class.getName());
if (isJNDIModeOn(obProps)) {
setJNDI(obProps, props);
} else {
props.setProperty(Environment.DRIVER, "org.postgresql.Driver");
props.setProperty(Environment.URL,
obProps.getProperty("bbdd.url") + "/" + obProps.getProperty("bbdd.sid"));
props.setProperty(Environment.USER, obProps.getProperty("bbdd.user"));
props.setProperty(Environment.PASS, obProps.getProperty("bbdd.password"));
}
return props;
}
JpaConfig.java 文件源码
项目:bag-database
阅读 28
收藏 0
点赞 0
评论 0
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
myLogger.info("entityManagerFactory");
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPackagesToScan("com.github.swrirobotics");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties jpaProperties = new Properties();
// Disable HBM2DDL; we use Liquibase to create our database
jpaProperties.put(Environment.HBM2DDL_AUTO, "");
// Set a large batch size for better performance over slow network links
jpaProperties.put(Environment.STATEMENT_BATCH_SIZE, "100");
jpaProperties.put(Environment.ORDER_INSERTS, "true");
jpaProperties.put(Environment.ORDER_UPDATES, "true");
jpaProperties.put(Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
HibernateTemplate.java 文件源码
项目:ERDesignerNG
阅读 34
收藏 0
点赞 0
评论 0
protected Configuration createConfiguration(Class aHibernateDialectClass) {
Configuration theConfiguration = new Configuration();
theConfiguration.addClass(DomainEntity.class);
theConfiguration.addClass(CustomTypeEntity.class);
theConfiguration.addClass(TableEntity.class);
theConfiguration.addClass(AttributeEntity.class);
theConfiguration.addClass(IndexEntity.class);
theConfiguration.addClass(RelationEntity.class);
theConfiguration.addClass(CommentEntity.class);
theConfiguration.addClass(SubjectAreaEntity.class);
theConfiguration.addClass(RepositoryEntity.class);
theConfiguration.addClass(ChangeEntity.class);
theConfiguration.addClass(ViewEntity.class);
theConfiguration.setProperty(Environment.DIALECT, aHibernateDialectClass.getName());
theConfiguration.setProperty(Environment.HBM2DDL_AUTO, "update");
theConfiguration.setProperty(Environment.CONNECTION_PROVIDER, ThreadbasedConnectionProvider.class.getName());
return theConfiguration;
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate5
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testNamedInstance() {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new Config();
config.setInstanceName("hibernate");
HazelcastInstance hz = factory.newHazelcastInstance(config);
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf)));
sf.close();
assertTrue(hz.getLifecycleService().isRunning());
factory.shutdownAll();
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate5
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testNamedClient_noInstance() throws Exception {
exception.expect(ServiceException.class);
exception.expectCause(allOf(isA(CacheException.class), new BaseMatcher<CacheException>() {
@Override
public boolean matches(Object item) {
return ((CacheException) item).getMessage().contains("No client with name [dev-custom] could be found.");
}
@Override
public void describeTo(Description description) {
}
}));
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_INSTANCE_NAME, "dev-custom");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
sf.close();
}
HibernateConfig.java 文件源码
项目:spring-boot-multitenant
阅读 36
收藏 0
点赞 0
评论 0
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.srai");
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
CommunoteSessionFactoryBean.java 文件源码
项目:communote-server
阅读 33
收藏 0
点赞 0
评论 0
@Override
protected void postProcessConfiguration(Configuration config) throws HibernateException {
ConfigurationManager propsManager = CommunoteRuntime.getInstance()
.getConfigurationManager();
// TODO this is ugly. Actually the ConfigurationManager should take care of the
// factory by itself but due to package structure this won't compile. We need to clean up
// and move stuff to api package and an impl of ConfigurationManager to core.
if (databaseConfigFactory == null) {
propsManager
.setDatabaseConfigurationFactory(new HibernateDatabaseConfigurationFactory());
} else {
propsManager.setDatabaseConfigurationFactory(databaseConfigFactory);
}
DatabaseConfiguration databaseConfig = propsManager.getDatabaseConfiguration();
configConnectionProvider(config, databaseConfig);
configFulltext(config, databaseConfig);
String hibernateDialect = propsManager.getStartupProperties().getHibernateDialect();
if (hibernateDialect != null) {
// set dialect if available, if not the dialect will be provided by the driver
config.setProperty(Environment.DIALECT, hibernateDialect);
}
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void testNamedInstance() {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new Config();
config.setInstanceName("hibernate");
HazelcastInstance hz = factory.newHazelcastInstance(config);
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf)));
sf.close();
assertTrue(hz.getLifecycleService().isRunning());
factory.shutdownAll();
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void testNamedClient_noInstance() throws Exception {
exception.expect(ServiceException.class);
exception.expectCause(allOf(isA(CacheException.class), new BaseMatcher<CacheException>() {
@Override
public boolean matches(Object item) {
return ((CacheException) item).getMessage().contains("No client with name [dev-custom] could be found.");
}
@Override
public void describeTo(Description description) {
}
}));
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_INSTANCE_NAME, "dev-custom");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
sf.close();
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void testNamedInstance() {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new Config();
config.setInstanceName("hibernate");
HazelcastInstance hz = factory.newHazelcastInstance(config);
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf)));
sf.close();
assertTrue(hz.getLifecycleService().isRunning());
factory.shutdownAll();
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void testNamedInstance_noInstance() {
exception.expect(CacheException.class);
exception.expectMessage("No instance with name [hibernate] could be found.");
Config config = new Config();
config.setInstanceName("hibernate");
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
sf.close();
}
CustomPropertiesTest.java 文件源码
项目:hazelcast-hibernate
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void testNamedClient_noInstance() throws Exception {
exception.expect(CacheException.class);
exception.expectMessage("No client with name [dev-custom] could be found.");
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_INSTANCE_NAME, "dev-custom");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
Configuration configuration = new Configuration();
configuration.addProperties(props);
SessionFactory sf = configuration.buildSessionFactory();
sf.close();
}
JTATransactionFactory.java 文件源码
项目:cacheonix-core
阅读 33
收藏 0
点赞 0
评论 0
public void configure(Properties props) throws HibernateException {
try {
context = NamingHelper.getInitialContext(props);
}
catch (NamingException ne) {
log.error("Could not obtain initial context", ne);
throw new HibernateException( "Could not obtain initial context", ne );
}
utName = props.getProperty(Environment.USER_TRANSACTION);
if (utName==null) {
TransactionManagerLookup lookup = TransactionManagerLookupFactory.getTransactionManagerLookup(props);
if (lookup!=null) utName = lookup.getUserTransactionName();
}
if (utName==null) utName = DEFAULT_USER_TRANSACTION_NAME;
}
TransactionManagerLookupFactory.java 文件源码
项目:cacheonix-core
阅读 42
收藏 0
点赞 0
评论 0
public static final TransactionManagerLookup getTransactionManagerLookup(Properties props) throws HibernateException {
String tmLookupClass = props.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
if (tmLookupClass==null) {
log.info("No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)");
return null;
}
else {
log.info("instantiating TransactionManagerLookup: " + tmLookupClass);
try {
TransactionManagerLookup lookup = (TransactionManagerLookup) ReflectHelper.classForName(tmLookupClass).newInstance();
log.info("instantiated TransactionManagerLookup");
return lookup;
}
catch (Exception e) {
log.error("Could not instantiate TransactionManagerLookup", e);
throw new HibernateException("Could not instantiate TransactionManagerLookup '" + tmLookupClass + "'");
}
}
}