Java Code Examples for org.hibernate.internal.util.config.ConfigurationHelper#getString()

The following examples show how to use org.hibernate.internal.util.config.ConfigurationHelper#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String tableName = ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE );

	if ( tableName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( tableName );
	}
	else {
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
		);
	}
}
 
Example 2
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"StatementWithEmptyBody", "deprecation"})
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	returnClass = type.getReturnedClass();

	final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );

	qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment );

	segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment );
	keySize = ConfigurationHelper.getInt( PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH );
	segmentName = ConfigurationHelper.getString( PK_VALUE_NAME, params, params.getProperty( TABLE ) );

	valueColumnName = determineValueColumnName( params, jdbcEnvironment );

	//hilo config
	maxLo = ConfigurationHelper.getInt( MAX_LO, params, Short.MAX_VALUE );

	if ( maxLo >= 1 ) {
		hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( returnClass, maxLo );
	}
}
 
Example 3
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
protected RedissonClient createRedissonClient(Properties properties) {
    Config config = null;
    if (!properties.containsKey(REDISSON_CONFIG_PATH)) {
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.json");
        if (config == null) {
            config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.yaml");
        }
    } else {
        String configPath = ConfigurationHelper.getString(REDISSON_CONFIG_PATH, properties);
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), configPath);
        if (config == null) {
            config = loadConfig(configPath);
        }
    }
    
    if (config == null) {
        throw new CacheException("Unable to locate Redisson configuration");
    }
    
    return Redisson.create(config);
}
 
Example 4
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
protected RedissonClient createRedissonClient(Map properties) {
    Config config = null;
    if (!properties.containsKey(REDISSON_CONFIG_PATH)) {
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.json");
        if (config == null) {
            config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.yaml");
        }
    } else {
        String configPath = ConfigurationHelper.getString(REDISSON_CONFIG_PATH, properties);
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), configPath);
        if (config == null) {
            config = loadConfig(configPath);
        }
    }
    
    if (config == null) {
        throw new CacheException("Unable to locate Redisson configuration");
    }

    String fallbackValue = (String) properties.getOrDefault(FALLBACK, "false");
    fallback = Boolean.valueOf(fallbackValue);
    return Redisson.create(config);
}
 
Example 5
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
protected RedissonClient createRedissonClient(Properties properties) {
    Config config = null;
    if (!properties.containsKey(REDISSON_CONFIG_PATH)) {
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.json");
        if (config == null) {
            config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.yaml");
        }
    } else {
        String configPath = ConfigurationHelper.getString(REDISSON_CONFIG_PATH, properties);
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), configPath);
        if (config == null) {
            config = loadConfig(configPath);
        }
    }
    
    if (config == null) {
        throw new CacheException("Unable to locate Redisson configuration");
    }
    
    return Redisson.create(config);
}
 
Example 6
Source File: JmxServiceImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 )
	);
}
 
Example 7
Source File: HibernateSchemaManagementTool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
GenerationTarget[] buildGenerationTargets(
		TargetDescriptor targetDescriptor,
		DdlTransactionIsolator ddlTransactionIsolator,
		Map options) {
	final String scriptDelimiter = ConfigurationHelper.getString( HBM2DDL_DELIMITER, options );

	final GenerationTarget[] targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ];

	int index = 0;

	if ( targetDescriptor.getTargetTypes().contains( TargetType.STDOUT ) ) {
		targets[index] = new GenerationTargetToStdout( scriptDelimiter );
		index++;
	}

	if ( targetDescriptor.getTargetTypes().contains( TargetType.SCRIPT ) ) {
		if ( targetDescriptor.getScriptTargetOutput() == null ) {
			throw new SchemaManagementException( "Writing to script was requested, but no script file was specified" );
		}
		targets[index] = new GenerationTargetToScript( targetDescriptor.getScriptTargetOutput(), scriptDelimiter );
		index++;
	}

	if ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {
		targets[index] = new GenerationTargetToDatabase( ddlTransactionIsolator, false );
	}

	return targets;
}
 
Example 8
Source File: IdentifierGeneration.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine the name of the sequence (or table if this resolves to a physical table)
 * to use.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @return The sequence name
 */
static QualifiedName determineSequenceName(Properties params, ServiceRegistry serviceRegistry) {
	final String sequencePerEntitySuffix = ConfigurationHelper.getString( SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX );

	String fallbackSequenceName = SequenceStyleGenerator.DEF_SEQUENCE_NAME;
	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( Settings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackSequenceName = generatorName;
		}
	}

	// JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
	final String defaultSequenceName = ConfigurationHelper.getBoolean( SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
			? params.getProperty( SequenceStyleGenerator.JPA_ENTITY_NAME ) + sequencePerEntitySuffix
			: fallbackSequenceName;

	final String sequenceName = ConfigurationHelper.getString( SequenceStyleGenerator.SEQUENCE_PARAM, params, defaultSequenceName );
	if ( sequenceName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( sequenceName );
	}
	else {
		JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema =  jdbcEnvironment.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( sequenceName )
		);
	}
}
 
Example 9
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}
 
Example 10
Source File: UUIDHexGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	sep = ConfigurationHelper.getString( "separator", params, "" );
}
 
Example 11
Source File: TableReactiveIdentifierGenerator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
static String determineValueColumnNameForSequenceEmulation(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( SequenceStyleGenerator.VALUE_COLUMN_PARAM, params, SequenceStyleGenerator.DEF_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}
 
Example 12
Source File: TableReactiveIdentifierGenerator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected String determineValueColumnNameForTable(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString(TableGenerator.VALUE_COLUMN_PARAM, params, TableGenerator.DEF_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}
 
Example 13
Source File: SequenceStyleGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determine the name of the sequence (or table if this resolves to a physical table)
 * to use.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param dialect The dialect in effect
 * @param jdbcEnv The JdbcEnvironment
 * @return The sequence name
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected QualifiedName determineSequenceName(
		Properties params,
		Dialect dialect,
		JdbcEnvironment jdbcEnv,
		ServiceRegistry serviceRegistry) {
	final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX );

	String fallbackSequenceName = DEF_SEQUENCE_NAME;
	final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
	if ( preferGeneratorNameAsDefaultName ) {
		final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
		if ( StringHelper.isNotEmpty( generatorName ) ) {
			fallbackSequenceName = generatorName;
		}
	}

	// JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
	final String defaultSequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
			? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix
			: fallbackSequenceName;

	final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, defaultSequenceName );
	if ( sequenceName.contains( "." ) ) {
		return QualifiedNameParser.INSTANCE.parse( sequenceName );
	}
	else {
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema =  jdbcEnv.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnv.getIdentifierHelper().toIdentifier( sequenceName )
		);
	}
}
 
Example 14
Source File: StringSequenceIdentifier.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(
        Type type,
        Properties params,
        ServiceRegistry serviceRegistry)
    throws MappingException {

    final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(
            JdbcEnvironment.class
    );

    final Dialect dialect = jdbcEnvironment.getDialect();

    final ConfigurationService configurationService = serviceRegistry.getService(
            ConfigurationService.class
    );

    String globalEntityIdentifierPrefix = configurationService.getSetting(
        "entity.identifier.prefix",
        String.class,
        "SEQ_"
    );

    sequencePrefix = ConfigurationHelper.getString(
        SEQUENCE_PREFIX,
        params,
        globalEntityIdentifierPrefix
    );

    final String sequencePerEntitySuffix = ConfigurationHelper.getString(
        SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX,
        params,
        SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX
    );

    boolean preferSequencePerEntity = ConfigurationHelper.getBoolean(
        SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY,
        params,
        false
    );

    final String defaultSequenceName = preferSequencePerEntity
            ? params.getProperty(JPA_ENTITY_NAME) + sequencePerEntitySuffix
            : SequenceStyleGenerator.DEF_SEQUENCE_NAME;

    sequenceCallSyntax = dialect.getSequenceNextValString(
        ConfigurationHelper.getString(
            SequenceStyleGenerator.SEQUENCE_PARAM,
            params,
            defaultSequenceName
        )
    );
}
 
Example 15
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}
 
Example 16
Source File: SqlClientPool.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
private SqlConnectOptions sqlConnectOptions(URI uri) {

		String scheme = uri.getScheme();

		String database = uri.getPath().substring( 1 );
		if ( scheme.equals("db2") && database.indexOf( ':' ) > 0 ) {
			database = database.substring( 0, database.indexOf( ':' ) );
		}

		// FIXME: Check which values can be null
		String username = ConfigurationHelper.getString( Settings.USER, configurationValues );
		String password = ConfigurationHelper.getString( Settings.PASS, configurationValues );
		if (username==null || password==null) {
			String[] params = {};
			// DB2 URLs are a bit odd and have the format: jdbc:db2://<HOST>:<PORT>/<DB>:key1=value1;key2=value2;
			if ( scheme.equals("db2") ) {
				int queryIndex = uri.getPath().indexOf(':') + 1;
				if (queryIndex > 0) {
					params = uri.getPath().substring(queryIndex).split(";");
				}
			} else {
				params = uri.getQuery().split("&");
			}
			for (String param : params) {
				if ( param.startsWith("user=") ) {
					username = param.substring(5);
				}
				if ( param.startsWith("pass=") ) {
					password = param.substring(5);
				}
				if ( param.startsWith("password=") ) {
					password = param.substring(9);
				}
			}
		}

		int port = uri.getPort();
		if (port==-1) {
			switch (scheme) {
				case "postgresql": port = 5432; break;
				case "mysql": port = 3306; break;
				case "db2": port = 50000; break;
			}
		}

		SqlConnectOptions connectOptions = new SqlConnectOptions()
				.setHost( uri.getHost() )
				.setPort( port )
				.setDatabase( database )
				.setUser( username );
		if (password != null) {
			connectOptions.setPassword( password );
		}

		//enable the prepared statement cache by default (except for DB2)
		connectOptions.setCachePreparedStatements( !scheme.equals("db2") );

		final Integer cacheMaxSize = ConfigurationHelper.getInteger( Settings.PREPARED_STATEMENT_CACHE_MAX_SIZE, configurationValues );
		if (cacheMaxSize!=null) {
			if (cacheMaxSize <= 0) {
				CoreLogging.messageLogger(SqlClientPool.class).infof( "HRX000014: Prepared statement cache disabled", cacheMaxSize );
				connectOptions.setCachePreparedStatements(false);
			}
			else {
				CoreLogging.messageLogger(SqlClientPool.class).infof( "HRX000015: Prepared statement cache max size: %d", cacheMaxSize );
				connectOptions.setCachePreparedStatements(true);
				connectOptions.setPreparedStatementCacheMaxSize(cacheMaxSize);
			}
		}

		final Integer sqlLimit = ConfigurationHelper.getInteger( Settings.PREPARED_STATEMENT_CACHE_SQL_LIMIT, configurationValues );
		if (sqlLimit!=null) {
			CoreLogging.messageLogger(SqlClientPool.class).infof( "HRX000016: Prepared statement cache SQL limit: %d", sqlLimit );
			connectOptions.setPreparedStatementCacheSqlLimit(sqlLimit);
		}

		return connectOptions;
	}
 
Example 17
Source File: SequenceStyleGenerator.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determine the optimizer to use.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param incrementSize The {@link #determineIncrementSize determined increment size}
 * @return The optimizer strategy (name)
 */
@SuppressWarnings("WeakerAccess")
protected String determineOptimizationStrategy(Properties params, int incrementSize) {
	return ConfigurationHelper.getString(
			OPT_PARAM,
			params,
			OptimizerFactory.determineImplicitOptimizerName( incrementSize, params )
	);
}
 
Example 18
Source File: SequenceStyleGenerator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine the name of the column used to store the generator value in
 * the db.
 * <p/>
 * Called during {@link #configure configuration} <b>when resolving to a
 * physical table</b>.
 *
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param jdbcEnvironment The JDBC environment
 * @return The value column name
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected Identifier determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name );
}
 
Example 19
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine the name of the column used to indicate the segment for each
 * row.  This column acts as the primary key.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @see #getSegmentColumnName()
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param jdbcEnvironment The JDBC environment
 * @return The name of the segment column
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}
 
Example 20
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine the name of the column in which we will store the generator persistent value.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @see #getValueColumnName()
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param jdbcEnvironment The JDBC environment
 * @return The name of the value column
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}