当前位置: 首页>>代码示例>>Java>>正文


Java Environment类代码示例

本文整理汇总了Java中org.hibernate.cfg.Environment的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Environment类属于org.hibernate.cfg包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: determineDialect

import org.hibernate.cfg.Environment; //导入依赖的package包/类
/**
 * 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 );
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:25,代码来源:DialectFactory.java

示例2: getHibernateFactory

import org.hibernate.cfg.Environment; //导入依赖的package包/类
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;
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:HibernateServiceImpl.java

示例3: getJpaPropertyMap

import org.hibernate.cfg.Environment; //导入依赖的package包/类
@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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HibernateJpaVendorAdapter.java

示例4: initiateService

import org.hibernate.cfg.Environment; //导入依赖的package包/类
@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 );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:BatchBuilderInitiator.java

示例5: buildSQLExceptionConverter

import org.hibernate.cfg.Environment; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:SQLExceptionConverterFactory.java

示例6: getResourceAsStream

import org.hibernate.cfg.Environment; //导入依赖的package包/类
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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ConfigHelper.java

示例7: InterbaseDialect

import org.hibernate.cfg.Environment; //导入依赖的package包/类
/**
 * 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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:InterbaseDialect.java

示例8: JDataStoreDialect

import org.hibernate.cfg.Environment; //导入依赖的package包/类
/**
 * 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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:JDataStoreDialect.java

示例9: build

import org.hibernate.cfg.Environment; //导入依赖的package包/类
/**
 * 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
	);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:StandardServiceRegistryBuilder.java

示例10: getOptions

import org.hibernate.cfg.Environment; //导入依赖的package包/类
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;
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AbstractStandardBasicType.java

示例11: wrap

import org.hibernate.cfg.Environment; //导入依赖的package包/类
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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:CalendarDateTypeDescriptor.java

示例12: wrap

import org.hibernate.cfg.Environment; //导入依赖的package包/类
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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:CalendarTypeDescriptor.java

示例13: get

import org.hibernate.cfg.Environment; //导入依赖的package包/类
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {

		if ( Environment.useStreamsForBinary() ) {

			InputStream inputStream = rs.getBinaryStream(name);

			if (inputStream==null) return toExternalFormat( null ); // is this really necessary?

			ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
			byte[] buffer = new byte[2048];

			try {
				while (true) {
					int amountRead = inputStream.read(buffer);
					if (amountRead == -1) {
						break;
					}
					outputStream.write(buffer, 0, amountRead);
				}

				inputStream.close();
				outputStream.close();
			}
			catch (IOException ioe) {
				throw new HibernateException( "IOException occurred reading a binary value", ioe );
			}

			return toExternalFormat( outputStream.toByteArray() );

		}
		else {
			return toExternalFormat( rs.getBytes(name) );
		}
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:AbstractBynaryType.java

示例14: entityManagerFactory

import org.hibernate.cfg.Environment; //导入依赖的package包/类
@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;
}
 
开发者ID:SAP,项目名称:cloud-s4-sdk-examples,代码行数:19,代码来源:HibernateConfig.java

示例15: testLocalSessionFactoryBeanWithValidProperties

import org.hibernate.cfg.Environment; //导入依赖的package包/类
@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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:LocalSessionFactoryBeanTests.java


注:本文中的org.hibernate.cfg.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。