本文整理汇总了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 );
}
示例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;
}
示例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;
}
示例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 );
}
}
示例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;
}
示例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;
}
示例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 );
}
示例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 );
}
示例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
);
}
示例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;
}
};
}
示例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;
}
示例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;
}
示例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) );
}
}
示例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;
}
示例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"));
}