Java Code Examples for org.hibernate.engine.config.spi.ConfigurationService

The following examples show how to use org.hibernate.engine.config.spi.ConfigurationService. These examples are extracted from open source projects. 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 Project: lams   Source File: TypeSafeActivator.java    License: 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 Project: lams   Source File: TypeSafeActivator.java    License: 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 Project: lams   Source File: SchemaExport.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static TargetDescriptor buildTargetDescriptor(
		EnumSet<TargetType> targetTypes,
		String outputFile,
		ServiceRegistry serviceRegistry) {
	final ScriptTargetOutput scriptTarget;
	if ( targetTypes.contains( TargetType.SCRIPT ) ) {
		if ( outputFile == null ) {
			throw new SchemaManagementException( "Writing to script was requested, but no script file was specified" );
		}
		scriptTarget = Helper.interpretScriptTargetSetting(
				outputFile,
				serviceRegistry.getService( ClassLoaderService.class ),
				(String) serviceRegistry.getService( ConfigurationService.class ).getSettings().get( AvailableSettings.HBM2DDL_CHARSET_NAME )
		);
	}
	else {
		scriptTarget = null;
	}

	return new TargetDescriptorImpl( targetTypes, scriptTarget );
}
 
Example 4
Source Project: lams   Source File: SchemaValidator.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void validate(Metadata metadata, ServiceRegistry serviceRegistry) {
	LOG.runningSchemaValidator();

	Map config = new HashMap();
	config.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() );

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

	final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions(
			config,
			ExceptionHandlerHaltImpl.INSTANCE
	);

	tool.getSchemaValidator( config ).doValidation( metadata, executionOptions );
}
 
Example 5
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private String determineCurrentSchemaName(
		DatabaseMetaData databaseMetaData,
		ServiceRegistry serviceRegistry,
		Dialect dialect) throws SQLException {
	final SchemaNameResolver schemaNameResolver;

	final Object setting = serviceRegistry.getService( ConfigurationService.class ).getSettings().get( SCHEMA_NAME_RESOLVER );
	if ( setting == null ) {
		schemaNameResolver = dialect.getSchemaNameResolver();
	}
	else {
		schemaNameResolver = serviceRegistry.getService( StrategySelector.class ).resolveDefaultableStrategy(
				SchemaNameResolver.class,
				setting,
				dialect.getSchemaNameResolver()
		);
	}

	try {
		return schemaNameResolver.resolveSchemaName( databaseMetaData.getConnection(), dialect );
	}
	catch (Exception e) {
		log.debug( "Unable to resolve connection default schema", e );
		return null;
	}
}
 
Example 6
@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 7
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void prepareEventListeners(MetadataImplementor metadata) {
	final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
	final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );

	eventListenerRegistry.prepare( metadata );

	for ( Map.Entry entry : ( (Map<?, ?>) cfgService.getSettings() ).entrySet() ) {
		if ( !String.class.isInstance( entry.getKey() ) ) {
			continue;
		}
		final String propertyName = (String) entry.getKey();
		if ( !propertyName.startsWith( org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX ) ) {
			continue;
		}
		final String eventTypeName = propertyName.substring(
				org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX.length() + 1
		);
		final EventType eventType = EventType.resolveEventTypeByName( eventTypeName );
		final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
		for ( String listenerImpl : ( (String) entry.getValue() ).split( " ," ) ) {
			eventListenerGroup.appendListener( instantiate( listenerImpl, classLoaderService ) );
		}
	}
}
 
Example 8
Source Project: lams   Source File: Oracle12cDialect.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
	super.contributeTypes( typeContributions, serviceRegistry );

	// account for Oracle's deprecated support for LONGVARBINARY...
	// 		prefer BLOB, unless the user opts out of it
	boolean preferLong = serviceRegistry.getService( ConfigurationService.class ).getSetting(
			PREFER_LONG_RAW,
			StandardConverters.BOOLEAN,
			false
	);

	if ( !preferLong ) {
		typeContributions.contributeType( MaterializedBlobType.INSTANCE, "byte[]", byte[].class.getName() );
		typeContributions.contributeType( WrappedMaterializedBlobType.INSTANCE, "Byte[]", Byte[].class.getName() );
	}
}
 
Example 9
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 10
Source Project: lams   Source File: MetadataBuilderImpl.java    License: 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 11
@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 12
/**
 * 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 13
static QualifiedName determineTableName(Properties params, ServiceRegistry serviceRegistry) {
	String fallbackTableName = TableGenerator.DEF_TABLE;
	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 ) ) {
			fallbackTableName = generatorName;
		}
	}

	String tableName = ConfigurationHelper.getString( TableGenerator.TABLE_PARAM, params, fallbackTableName );

	QualifiedNameParser.NameParts qualifiedTableName;
	if ( tableName.contains( "." ) ) {
		qualifiedTableName = QualifiedNameParser.INSTANCE.parse( tableName );
	}
	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 )
		);
		qualifiedTableName = new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
		);
	}
	return qualifiedTableName;
}
 
Example 14
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
	Dialect dialect = jdbcEnvironment.getDialect();

	if (sequenceEmulator) {
		//it's a SequenceStyleGenerator backed by a table
		qualifiedTableName = determineSequenceName( params, serviceRegistry );
		valueColumnName = determineValueColumnNameForSequenceEmulation( params, jdbcEnvironment );
		segmentColumnName = null;
		segmentValue = null;
		initialValue = determineInitialValueForSequenceEmulation( params );

		storeLastUsedValue = false;
	}
	else {
		//It's a regular TableGenerator
		qualifiedTableName = determineTableName( params, serviceRegistry );
		segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment );
		valueColumnName = determineValueColumnNameForTable( params, jdbcEnvironment );
		segmentValue = determineSegmentValue( params );
		initialValue = determineInitialValueForTable( params );

		storeLastUsedValue = serviceRegistry.getService( ConfigurationService.class )
				.getSetting( Settings.TABLE_GENERATOR_STORE_LAST_USED, StandardConverters.BOOLEAN, true );
	}

	// allow physical naming strategies a chance to kick in
	renderedTableName = jdbcEnvironment.getQualifiedObjectNameFormatter()
			.format( qualifiedTableName, dialect );

	selectQuery = buildSelectQuery( dialect );
	updateQuery = buildUpdateQuery( dialect );
	insertQuery = buildInsertQuery( dialect );
}
 
Example 15
Source Project: lams   Source File: TypeSafeActivator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings( {"UnusedDeclaration"})
public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) {
	final Set<ValidationMode> modes = activationContext.getValidationModes();
	if ( ! ( modes.contains( ValidationMode.CALLBACK ) || modes.contains( ValidationMode.AUTO ) ) ) {
		return;
	}

	final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class );
	final ClassLoaderService classLoaderService = activationContext.getServiceRegistry().getService( ClassLoaderService.class );

	// de-activate not-null tracking at the core level when Bean Validation is present unless the user explicitly
	// asks for it
	if ( cfgService.getSettings().get( Environment.CHECK_NULLABILITY ) == null ) {
		activationContext.getSessionFactory().getSessionFactoryOptions().setCheckNullability( false );
	}

	final BeanValidationEventListener listener = new BeanValidationEventListener(
			validatorFactory,
			cfgService.getSettings(),
			classLoaderService
	);

	final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry()
			.getService( EventListenerRegistry.class );

	listenerRegistry.addDuplicationStrategy( DuplicationStrategyImpl.INSTANCE );

	listenerRegistry.appendListeners( EventType.PRE_INSERT, listener );
	listenerRegistry.appendListeners( EventType.PRE_UPDATE, listener );
	listenerRegistry.appendListeners( EventType.PRE_DELETE, listener );

	listener.initialize( cfgService.getSettings(), classLoaderService );
}
 
Example 16
Source Project: lams   Source File: TypeSafeActivator.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) {
	// IMPL NOTE : We can either be provided a ValidatorFactory or make one.  We can be provided
	// a ValidatorFactory in 2 different ways.  So here we "get" a ValidatorFactory in the following order:
	//		1) Look into SessionFactoryOptions.getValidatorFactoryReference()
	//		2) Look into ConfigurationService
	//		3) build a new ValidatorFactory

	// 1 - look in SessionFactoryOptions.getValidatorFactoryReference()
	ValidatorFactory factory = resolveProvidedFactory( activationContext.getSessionFactory().getSessionFactoryOptions() );
	if ( factory != null ) {
		return factory;
	}

	// 2 - look in ConfigurationService
	factory = resolveProvidedFactory( activationContext.getServiceRegistry().getService( ConfigurationService.class ) );
	if ( factory != null ) {
		return factory;
	}

	// 3 - build our own
	try {
		return Validation.buildDefaultValidatorFactory();
	}
	catch ( Exception e ) {
		throw new IntegrationException( "Unable to build the default ValidatorFactory", e );
	}
}
 
Example 17
private BeanContainer resoveBeanContainer(Map configurationValues, ServiceRegistryImplementor serviceRegistry) {
	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
	final ConfigurationService cfgSvc = serviceRegistry.getService( ConfigurationService.class );

	// was a specific container explicitly specified?
	final Object explicitBeanContainer = configurationValues.get( AvailableSettings.BEAN_CONTAINER );
	if ( explicitBeanContainer != null ) {
		return interpretExplicitBeanContainer( explicitBeanContainer, classLoaderService, serviceRegistry );
	}

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// simplified CDI support

	final boolean isCdiAvailable = isCdiAvailable( classLoaderService );
	final Object beanManagerRef = cfgSvc.getSettings().get( AvailableSettings.CDI_BEAN_MANAGER );
	if ( beanManagerRef != null ) {
		if ( !isCdiAvailable ) {
			BeansMessageLogger.BEANS_LOGGER.beanManagerButCdiNotAvailable( beanManagerRef );
		}

		return CdiBeanContainerBuilder.fromBeanManagerReference( beanManagerRef, serviceRegistry );
	}
	else {
		if ( isCdiAvailable ) {
			BeansMessageLogger.BEANS_LOGGER.noBeanManagerButCdiAvailable();
		}
	}

	return null;
}
 
Example 18
Source Project: lams   Source File: SchemaUpdate.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void execute(EnumSet<TargetType> targetTypes, Metadata metadata, ServiceRegistry serviceRegistry) {
	if ( targetTypes.isEmpty() ) {
		LOG.debug( "Skipping SchemaExport as no targets were specified" );
		return;
	}

	exceptions.clear();
	LOG.runningHbm2ddlSchemaUpdate();

	Map config = new HashMap();
	config.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() );
	config.put( AvailableSettings.HBM2DDL_DELIMITER, delimiter );
	config.put( AvailableSettings.FORMAT_SQL, format );

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

	final ExceptionHandler exceptionHandler = haltOnError
			? ExceptionHandlerHaltImpl.INSTANCE
			: new ExceptionHandlerCollectingImpl();

	final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions(
			config,
			exceptionHandler
	);

	final TargetDescriptor targetDescriptor = SchemaExport.buildTargetDescriptor( targetTypes, outputFile, serviceRegistry );

	try {
		tool.getSchemaMigrator( config ).doMigration( metadata, executionOptions, targetDescriptor );
	}
	finally {
		if ( exceptionHandler instanceof ExceptionHandlerCollectingImpl ) {
			exceptions.addAll( ( (ExceptionHandlerCollectingImpl) exceptionHandler ).getExceptions() );
		}
	}
}
 
Example 19
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 20
Source Project: lams   Source File: SchemaCreatorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void doCreation(
		Metadata metadata,
		final boolean manageNamespaces,
		GenerationTarget... targets) {
	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry();
	doCreation(
			metadata,
			serviceRegistry,
			serviceRegistry.getService( ConfigurationService.class ).getSettings(),
			manageNamespaces,
			targets
	);
}
 
Example 21
Source Project: lams   Source File: AbstractSchemaMigrator.java    License: GNU General Public License v2.0 5 votes vote down vote up
private UniqueConstraintSchemaUpdateStrategy determineUniqueConstraintSchemaUpdateStrategy(Metadata metadata) {
	final ConfigurationService cfgService = ((MetadataImplementor) metadata).getMetadataBuildingOptions()
			.getServiceRegistry()
			.getService( ConfigurationService.class );

	return UniqueConstraintSchemaUpdateStrategy.interpret(
			cfgService.getSetting( UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY, StandardConverters.STRING )
	);
}
 
Example 22
Source Project: lams   Source File: SchemaDropperImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * For tests
 */
public void doDrop(Metadata metadata, boolean manageNamespaces, GenerationTarget... targets) {
	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry();
	doDrop(
			metadata,
			serviceRegistry,
			serviceRegistry.getService( ConfigurationService.class ).getSettings(),
			manageNamespaces,
			targets
	);
}
 
Example 23
Source Project: lams   Source File: ComponentMetamodel.java    License: 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 24
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: 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 25
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: 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 26
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: 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 27
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: 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 28
Source Project: lams   Source File: StatisticsInitiator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) {
	final Object configValue = context.getServiceRegistry()
			.getService( ConfigurationService.class )
			.getSettings()
			.get( STATS_BUILDER );
	return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() );
}
 
Example 29
Source Project: lams   Source File: StatisticsInitiator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public StatisticsImplementor initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	final Object configValue = registry
			.getService( ConfigurationService.class )
			.getSettings()
			.get( STATS_BUILDER );
	return initiateServiceInternal( sessionFactory, configValue, registry );
}
 
Example 30
Source Project: lams   Source File: TableGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	storeLastUsedValue = serviceRegistry.getService( ConfigurationService.class )
			.getSetting( AvailableSettings.TABLE_GENERATOR_STORE_LAST_USED, StandardConverters.BOOLEAN, true );
	identifierType = type;

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

	qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment, serviceRegistry );
	segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment );
	valueColumnName = determineValueColumnName( params, jdbcEnvironment );

	segmentValue = determineSegmentValue( params );

	segmentValueLength = determineSegmentColumnSize( params );
	initialValue = determineInitialValue( params );
	incrementSize = determineIncrementSize( params );

	final String optimizationStrategy = ConfigurationHelper.getString(
			OPT_PARAM,
			params,
			OptimizerFactory.determineImplicitOptimizerName( incrementSize, params )
	);
	int optimizerInitialValue = ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 );
	optimizer = OptimizerFactory.buildOptimizer(
			optimizationStrategy,
			identifierType.getReturnedClass(),
			incrementSize,
			optimizerInitialValue
	);
}