Java Code Examples for org.hibernate.engine.config.spi.ConfigurationService#getSetting()

The following examples show how to use org.hibernate.engine.config.spi.ConfigurationService#getSetting() . 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: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "UnusedParameters"})
private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) {
	final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class );
	if ( !cfgService.getSetting( BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, true  ) ) {
		LOG.debug( "Skipping application of relational constraints from legacy Hibernate Validator" );
		return;
	}

	final Set<ValidationMode> modes = activationContext.getValidationModes();
	if ( ! ( modes.contains( ValidationMode.DDL ) || modes.contains( ValidationMode.AUTO ) ) ) {
		return;
	}

	applyRelationalConstraints(
			factory,
			activationContext.getMetadata().getEntityBindings(),
			cfgService.getSettings(),
			activationContext.getServiceRegistry().getService( JdbcServices.class ).getDialect(),
			new ClassLoaderAccessImpl(
					null,
					activationContext.getServiceRegistry().getService( ClassLoaderService.class )
			)
	);
}
 
Example 2
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static ValidatorFactory resolveProvidedFactory(ConfigurationService cfgService) {
	return cfgService.getSetting(
			FACTORY_PROPERTY,
			new ConfigurationService.Converter<ValidatorFactory>() {
				@Override
				public ValidatorFactory convert(Object value) {
					try {
						return ValidatorFactory.class.cast( value );
					}
					catch ( ClassCastException e ) {
						throw new IntegrationException(
								String.format(
										Locale.ENGLISH,
										"ValidatorFactory reference (provided via `%s` setting) was not castable to %s : %s",
										FACTORY_PROPERTY,
										ValidatorFactory.class.getName(),
										value.getClass().getName()
								)
						);
					}
				}
			},
			null
	);
}
 
Example 3
Source File: DefaultIdentifierGeneratorFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
	this.serviceRegistry = serviceRegistry;
	this.dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect();
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	final boolean useNewIdentifierGenerators = configService.getSetting(
			AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
			StandardConverters.BOOLEAN,
			true
	);

	if(!useNewIdentifierGenerators) {
		register( "sequence", SequenceGenerator.class );
	}
}
 
Example 4
Source File: DefaultMergeEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
	final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
	if ( entityCopyObserverStrategy == null ) {
		final ConfigurationService configurationService
				= serviceRegistry.getService( ConfigurationService.class );
		entityCopyObserverStrategy = configurationService.getSetting(
				AvailableSettings.MERGE_ENTITY_COPY_OBSERVER,
				new ConfigurationService.Converter<String>() {
					@Override
					public String convert(Object value) {
						return value.toString();
					}
				},
				EntityCopyNotAllowedObserver.SHORT_NAME
		);
		LOG.debugf( "EntityCopyObserver strategy: %s", entityCopyObserverStrategy );
	}
	final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
	return strategySelector.resolveStrategy( EntityCopyObserver.class, entityCopyObserverStrategy );
}
 
Example 5
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ArrayList<MetadataSourceType> resolveInitialSourceProcessOrdering(ConfigurationService configService) {
	final ArrayList<MetadataSourceType> initialSelections = new ArrayList<>();

	final String sourceProcessOrderingSetting = configService.getSetting(
			AvailableSettings.ARTIFACT_PROCESSING_ORDER,
			StandardConverters.STRING
	);
	if ( sourceProcessOrderingSetting != null ) {
		final String[] orderChoices = StringHelper.split( ",; ", sourceProcessOrderingSetting, false );
		initialSelections.addAll( CollectionHelper.arrayList( orderChoices.length ) );
		for ( String orderChoice : orderChoices ) {
			initialSelections.add( MetadataSourceType.parsePrecedence( orderChoice ) );
		}
	}
	if ( initialSelections.isEmpty() ) {
		initialSelections.add( MetadataSourceType.HBM );
		initialSelections.add( MetadataSourceType.CLASS );
	}

	return initialSelections;
}
 
Example 6
Source File: PersistentTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
	final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
	final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	final String catalogName = configService.getSetting(
			CATALOG,
			StandardConverters.STRING,
			configService.getSetting( AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING )
	);
	final String schemaName = configService.getSetting(
			SCHEMA,
			StandardConverters.STRING,
			configService.getSetting( AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING )
	);

	this.catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier( catalogName );
	this.schema = jdbcEnvironment.getIdentifierHelper().toIdentifier( schemaName );

	this.dropIdTables = configService.getSetting(
			DROP_ID_TABLES,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 7
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 8
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static boolean logWarnings(ConfigurationService cfgService, Dialect dialect) {
	return cfgService.getSetting(
			AvailableSettings.LOG_JDBC_WARNINGS,
			StandardConverters.BOOLEAN,
			dialect.isJdbcLogWarningsEnabledByDefault()
	);
}
 
Example 9
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static boolean globalQuoting(ConfigurationService cfgService) {
	return cfgService.getSetting(
			AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 10
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean globalQuotingSkippedForColumnDefinitions(ConfigurationService cfgService) {
	return cfgService.getSetting(
			AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS_SKIP_COLUMN_DEFINITIONS,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 11
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static boolean autoKeywordQuoting(ConfigurationService cfgService) {
	return cfgService.getSetting(
			AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 12
Source File: Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void resolveLegacyLimitHandlerBehavior(ServiceRegistry serviceRegistry) {
	// HHH-11194
	// Temporary solution to set whether legacy limit handler behavior should be used.
	final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
	legacyLimitHandlerBehavior = configurationService.getSetting(
			AvailableSettings.USE_LEGACY_LIMIT_HANDLERS,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 13
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public MappingDefaultsImpl(StandardServiceRegistry serviceRegistry) {
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	this.implicitSchemaName = configService.getSetting(
			AvailableSettings.DEFAULT_SCHEMA,
			StandardConverters.STRING,
			null
	);

	this.implicitCatalogName = configService.getSetting(
			AvailableSettings.DEFAULT_CATALOG,
			StandardConverters.STRING,
			null
	);

	this.implicitlyQuoteIdentifiers = configService.getSetting(
			AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS,
			StandardConverters.BOOLEAN,
			false
	);

	this.implicitCacheAccessType = configService.getSetting(
			AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY,
			new ConfigurationService.Converter<AccessType>() {
				@Override
				public AccessType convert(Object value) {
					return AccessType.fromExternalName( value.toString() );
				}
			}
	);
}
 
Example 14
Source File: GlobalTemporaryTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
	final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
	this.dropIdTables = configService.getSetting(
			DROP_ID_TABLES,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example 15
Source File: SchemaManagementToolCoordinator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static void process(
		final Metadata metadata,
		final ServiceRegistry serviceRegistry,
		final Map configurationValues,
		DelayedDropRegistry delayedDropRegistry) {
	final ActionGrouping actions = ActionGrouping.interpret( configurationValues );

	if ( actions.getDatabaseAction() == Action.NONE && actions.getScriptAction() == Action.NONE ) {
		// no actions specified
		log.debug( "No actions specified; doing nothing" );
		return;
	}

	final SchemaManagementTool tool = serviceRegistry.getService( SchemaManagementTool.class );
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	boolean haltOnError = configService.getSetting( AvailableSettings.HBM2DDL_HALT_ON_ERROR, Boolean.class, false);

	final ExecutionOptions executionOptions = buildExecutionOptions(
			configurationValues,
			haltOnError ? ExceptionHandlerHaltImpl.INSTANCE :
					ExceptionHandlerLoggedImpl.INSTANCE
	);

	performScriptAction( actions.getScriptAction(), metadata, tool, serviceRegistry, executionOptions );
	performDatabaseAction( actions.getDatabaseAction(), metadata, tool, serviceRegistry, executionOptions );

	if ( actions.getDatabaseAction() == Action.CREATE_DROP ) {
		//noinspection unchecked
		delayedDropRegistry.registerOnCloseAction(
				tool.getSchemaDropper( configurationValues ).buildDelayedAction(
						metadata,
						executionOptions,
						buildDatabaseTargetDescriptor(
								configurationValues,
								DropSettingSelector.INSTANCE,
								serviceRegistry
						)
				)
		);
	}
}
 
Example 16
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
        )
    );
}