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

The following examples show how to use org.hibernate.internal.util.config.ConfigurationHelper#getBoolean() . 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: OptimizerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determine the optimizer to use when there was not one explicitly specified.
 */
public static String determineImplicitOptimizerName(int incrementSize, Properties configSettings) {
	if ( incrementSize <= 1 ) {
		return StandardOptimizerDescriptor.NONE.getExternalName();
	}

	// see if the user defined a preferred pooled optimizer...
	final String preferredPooledOptimizerStrategy = configSettings.getProperty( AvailableSettings.PREFERRED_POOLED_OPTIMIZER );
	if ( StringHelper.isNotEmpty( preferredPooledOptimizerStrategy ) ) {
		return preferredPooledOptimizerStrategy;
	}

	// otherwise fallback to the fallback strategy (considering the deprecated PREFER_POOLED_VALUES_LO setting)
	return ConfigurationHelper.getBoolean( AvailableSettings.PREFER_POOLED_VALUES_LO, configSettings, false )
			? StandardOptimizerDescriptor.POOLED_LO.getExternalName()
			: StandardOptimizerDescriptor.POOLED.getExternalName();
}
 
Example 2
Source File: DriverManagerConnectionProviderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private PooledConnections buildPool(Map configurationValues) {
	final boolean autoCommit = ConfigurationHelper.getBoolean(
			AvailableSettings.AUTOCOMMIT,
			configurationValues,
			false
	);
	final int minSize = ConfigurationHelper.getInt( MIN_SIZE, configurationValues, 1 );
	final int maxSize = ConfigurationHelper.getInt( AvailableSettings.POOL_SIZE, configurationValues, 20 );
	final int initialSize = ConfigurationHelper.getInt( INITIAL_SIZE, configurationValues, minSize );

	ConnectionCreator connectionCreator = buildCreator( configurationValues );
	PooledConnections.Builder pooledConnectionBuilder = new PooledConnections.Builder(
			connectionCreator,
			autoCommit
	);
	pooledConnectionBuilder.initialSize( initialSize );
	pooledConnectionBuilder.minSize( minSize );
	pooledConnectionBuilder.maxSize( maxSize );

	return pooledConnectionBuilder.build();
}
 
Example 3
Source File: MutableJpaComplianceImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
public MutableJpaComplianceImpl(Map configurationSettings, boolean jpaByDefault) {
	final Object legacyQueryCompliance = configurationSettings.get( AvailableSettings.JPAQL_STRICT_COMPLIANCE );

	queryCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_QUERY_COMPLIANCE,
			configurationSettings,
			ConfigurationHelper.toBoolean( legacyQueryCompliance, jpaByDefault )
	);
	transactionCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_TRANSACTION_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
	listCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_LIST_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
	closedCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_CLOSED_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
	proxyCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_PROXY_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
	cachingCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_CACHING_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
	globalGeneratorNameScopeCompliance = ConfigurationHelper.getBoolean(
			AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE,
			configurationSettings,
			jpaByDefault
	);
}
 
Example 4
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void logIfEmptyCompositesEnabled(Map<String, Object> props ) {
	final boolean isEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
			AvailableSettings.CREATE_EMPTY_COMPOSITES_ENABLED,
			props,
			false
	);
	if ( isEmptyCompositesEnabled ) {
		// It would be nice to do this logging in ComponentMetamodel, where
		// AvailableSettings.CREATE_EMPTY_COMPOSITES_ENABLED is actually used.
		// Unfortunately that would end up logging a message several times for
		// each embeddable/composite. Doing it here will log the message only
		// once.
		LOG.emptyCompositesEnabled();
	}
}
 
Example 5
Source File: SequenceStyleGenerator.java    From lams with GNU General Public License v2.0 5 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();

	this.identifierType = type;
	boolean forceTableUse = ConfigurationHelper.getBoolean( FORCE_TBL_PARAM, params, false );

	final QualifiedName sequenceName = determineSequenceName( params, dialect, jdbcEnvironment, serviceRegistry );

	final int initialValue = determineInitialValue( params );
	int incrementSize = determineIncrementSize( params );

	final String optimizationStrategy = determineOptimizationStrategy( params, incrementSize );
	incrementSize = determineAdjustedIncrementSize( optimizationStrategy, incrementSize );

	if ( dialect.supportsSequences() && !forceTableUse ) {
		if ( !dialect.supportsPooledSequences() && OptimizerFactory.isPooledOptimizer( optimizationStrategy ) ) {
			forceTableUse = true;
			LOG.forcingTableUse();
		}
	}

	this.databaseStructure = buildDatabaseStructure(
			type,
			params,
			jdbcEnvironment,
			forceTableUse,
			sequenceName,
			initialValue,
			incrementSize
	);
	this.optimizer = OptimizerFactory.buildOptimizer(
			optimizationStrategy,
			identifierType.getReturnedClass(),
			incrementSize,
			ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 )
	);
	this.databaseStructure.prepare( optimizer );
}
 
Example 6
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AbstractServiceRegistryImpl(
		BootstrapServiceRegistry bootstrapServiceRegistry,
		boolean autoCloseRegistry) {
	if ( ! ServiceRegistryImplementor.class.isInstance( bootstrapServiceRegistry ) ) {
		throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
	}
	this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
	this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );

	this.autoCloseRegistry = autoCloseRegistry;
	this.parent.registerChild( this );
}
 
Example 7
Source File: DriverManagerConnectionProviderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 = ConnectionProviderInitiator.extractIsolation( configurationValues );
	if ( isolation != null ) {
		log.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
	}
	connectionCreatorBuilder.setIsolation( isolation );

	return connectionCreatorBuilder.build();
}
 
Example 8
Source File: AbstractJtaPlatform.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void configure(Map configValues) {
	cacheTransactionManager = ConfigurationHelper.getBoolean(
			AvailableSettings.JTA_CACHE_TM,
			configValues,
			canCacheTransactionManagerByDefault()
	);
	cacheUserTransaction = ConfigurationHelper.getBoolean(
			AvailableSettings.JTA_CACHE_UT,
			configValues,
			canCacheUserTransactionByDefault()
	);
}
 
Example 9
Source File: SqlClientPool.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void configure(Map configurationValues) {
	//TODO: actually extract the configuration values we need rather than keeping a reference to the whole map.
	this.configurationValues = configurationValues;

	showSQL = ConfigurationHelper.getBoolean( Settings.SHOW_SQL, configurationValues, false );
	formatSQL = ConfigurationHelper.getBoolean( Settings.FORMAT_SQL, configurationValues, false );
	usePostgresStyleParameters =
			serviceRegistry.getService(JdbcEnvironment.class).getDialect() instanceof PostgreSQL9Dialect;
}
 
Example 10
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 11
Source File: ComponentMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ComponentMetamodel(Component component, ComponentTuplizerFactory componentTuplizerFactory){
	this.role = component.getRoleName();
	this.isKey = component.isKey();
	propertySpan = component.getPropertySpan();
	properties = new StandardProperty[propertySpan];
	Iterator itr = component.getPropertyIterator();
	int i = 0;
	while ( itr.hasNext() ) {
		Property property = ( Property ) itr.next();
		properties[i] = PropertyFactory.buildStandardProperty( property, false );
		propertyIndexes.put( property.getName(), i );
		i++;
	}

	entityMode = component.hasPojoRepresentation() ? EntityMode.POJO : EntityMode.MAP;

	// todo : move this to SF per HHH-3517; also see HHH-1907 and ComponentMetamodel
	final String tuplizerClassName = component.getTuplizerImplClassName( entityMode );
	this.componentTuplizer = tuplizerClassName == null ? componentTuplizerFactory.constructDefaultTuplizer(
			entityMode,
			component
	) : componentTuplizerFactory.constructTuplizer( tuplizerClassName, component );

	final ConfigurationService cs = component.getMetadata().getMetadataBuildingOptions().getServiceRegistry()
			.getService(ConfigurationService.class);

	this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
			Environment.CREATE_EMPTY_COMPOSITES_ENABLED,
			cs.getSettings(),
			false
	);
}
 
Example 12
Source File: Helper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static boolean interpretFormattingEnabled(Map configurationValues) {
	return ConfigurationHelper.getBoolean(
			AvailableSettings.FORMAT_SQL,
			configurationValues,
			false
	);
}
 
Example 13
Source File: Helper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static boolean interpretNamespaceHandling(Map configurationValues) {
	// prefer the JPA setting...
	return ConfigurationHelper.getBoolean(
			AvailableSettings.HBM2DLL_CREATE_SCHEMAS,
			configurationValues,
			ConfigurationHelper.getBoolean(
					AvailableSettings.HBM2DLL_CREATE_NAMESPACES,
					configurationValues,
					false
			)
	);
}
 
Example 14
Source File: InformationExtractorJdbcDatabaseMetaDataImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public InformationExtractorJdbcDatabaseMetaDataImpl(ExtractionContext extractionContext) {
	this.extractionContext = extractionContext;

	ConfigurationService configService = extractionContext.getServiceRegistry()
			.getService( ConfigurationService.class );

	final String extraPhysycalTableTypesConfig = configService.getSetting(
			AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES,
			StandardConverters.STRING,
			""
	);
	if ( !"".equals( extraPhysycalTableTypesConfig.trim() ) ) {
		this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
				",;",
				extraPhysycalTableTypesConfig,
				false
		);
	}

	final List<String> tableTypesList = new ArrayList<>();
	tableTypesList.add( "TABLE" );
	tableTypesList.add( "VIEW" );
	if ( ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, configService.getSettings(), false ) ) {
		tableTypesList.add( "SYNONYM" );
	}
	if ( extraPhysicalTableTypes != null ) {
		Collections.addAll( tableTypesList, extraPhysicalTableTypes );
	}
	extractionContext.getJdbcEnvironment().getDialect().augmentRecognizedTableTypes( tableTypesList );

	this.tableTypes = tableTypesList.toArray( new String[ tableTypesList.size() ] );
}
 
Example 15
Source File: DisabledJMXInitiator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public JmxService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    if (ConfigurationHelper.getBoolean(AvailableSettings.JMX_ENABLED, configurationValues, false)) {
        Logger.getLogger(DisabledJMXInitiator.class)
                .warn("Enabling JMX is not allowed in Quarkus: forcefully disabled. Ignoring property:"
                        + AvailableSettings.JMX_ENABLED);
    }
    return DisabledJmxServiceImpl.INSTANCE;
}
 
Example 16
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 17
Source File: JmxServiceInitiator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JmxService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return ConfigurationHelper.getBoolean( AvailableSettings.JMX_ENABLED, configurationValues, false )
			? new JmxServiceImpl( configurationValues )
			: DisabledJmxServiceImpl.INSTANCE;
}
 
Example 18
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 19
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 20
Source File: TableReactiveIdentifierGenerator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected String determineDefaultSegmentValue(Properties params) {
	final boolean preferSegmentPerEntity = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEGMENT_PER_ENTITY, params, false );
	return preferSegmentPerEntity ? params.getProperty( TABLE ) : DEF_SEGMENT_VALUE;
}