org.hibernate.service.ServiceRegistry Java Examples

The following examples show how to use org.hibernate.service.ServiceRegistry. 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: JdbcEnvironmentImpl.java    From lams with 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 #2
Source File: DatabaseInformationImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public DatabaseInformationImpl(
		ServiceRegistry serviceRegistry,
		JdbcEnvironment jdbcEnvironment,
		DdlTransactionIsolator ddlTransactionIsolator,
		Namespace.Name defaultNamespace) throws SQLException {
	this.jdbcEnvironment = jdbcEnvironment;

	this.extractionContext = new ImprovedExtractionContextImpl(
			serviceRegistry,
			jdbcEnvironment,
			ddlTransactionIsolator,
			defaultNamespace.getCatalog(),
			defaultNamespace.getSchema(),
			this
	);

	// todo : make this pluggable
	this.extractor = new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext );

	// because we do not have defined a way to locate sequence info by name
	initializeSequences();
}
 
Example #3
Source File: SchemaExport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void execute(EnumSet<TargetType> targetTypes, Action action, Metadata metadata, ServiceRegistry serviceRegistry) {
	if ( action == Action.NONE ) {
		LOG.debug( "Skipping SchemaExport as Action.NONE was passed" );
		return;
	}

	if ( targetTypes.isEmpty() ) {
		LOG.debug( "Skipping SchemaExport as no targets were specified" );
		return;
	}

	exceptions.clear();

	LOG.runningHbm2ddlSchemaExport();

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

	doExecution( action, needsJdbcConnection( targetTypes ), metadata, serviceRegistry, targetDescriptor );
}
 
Example #4
Source File: Oracle12cDialect.java    From lams with 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 #5
Source File: SchemaExport.java    From lams with 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 #6
Source File: PostgreSQLJsonBinaryTypeProgrammaticConfigurationTest.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    CustomObjectMapperSupplier customObjectMapperSupplier = new CustomObjectMapperSupplier();
    final JsonBinaryType jsonBinaryType = new JsonBinaryType(customObjectMapperSupplier.get(), Location.class);

    properties.put( "hibernate.type_contributors", new TypeContributorList() {
        @Override
        public List<TypeContributor> getTypeContributors() {
            List<TypeContributor> typeContributors = new ArrayList<TypeContributor>();
            typeContributors.add(new TypeContributor() {
                @Override
                public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                    typeContributions.contributeType(
                        jsonBinaryType, "location"
                    );
                }
            });
            return typeContributors;
        }
    });
}
 
Example #7
Source File: SequenceGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("StatementWithEmptyBody")
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	DeprecationLogger.DEPRECATION_LOGGER.deprecatedSequenceGenerator( getClass().getName() );

	identifierType = type;

	final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER );
	logicalQualifiedSequenceName = QualifiedNameParser.INSTANCE.parse(
			ConfigurationHelper.getString( SEQUENCE, params, "hibernate_sequence" ),
			normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ),
			normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) )
	);

	if ( params.containsKey( PARAMETERS ) ) {
		LOG.warn(
				"Use of 'parameters' config setting is no longer supported; " +
						"to specify initial-value or increment use the " +
						"org.hibernate.id.enhanced.SequenceStyleGenerator generator instead."
		);
	}
}
 
Example #8
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 #9
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
	if ( serviceRegistry == null ) {
		throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
	}

	if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
		return ( StandardServiceRegistry ) serviceRegistry;
	}
	else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
		log.debugf(
				"ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
						"if attempt is made to build SessionFactory"
		);
		return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
	}
	else {
		throw new HibernateException(
				String.format(
						"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
						serviceRegistry.getClass().getName()
				)
		);
	}
}
 
Example #10
Source File: SchemaValidator.java    From lams with 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 #11
Source File: HibernateUtil.java    From lambda-rds-mysql with Apache License 2.0 6 votes vote down vote up
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;
    
    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");
    
    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
 
Example #12
Source File: SequenceHiLoGenerator.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 {
	super.configure( type, params, serviceRegistry );

	maxLo = ConfigurationHelper.getInt( MAX_LO, params, 9 );

	if ( maxLo >= 1 ) {
		hiloOptimizer = new LegacyHiLoAlgorithmOptimizer(
				getIdentifierType().getReturnedClass(),
				maxLo
		);
	}
}
 
Example #13
Source File: SchemaCreatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void doCreation(
		Metadata metadata,
		final ServiceRegistry serviceRegistry,
		final Map settings,
		final boolean manageNamespaces,
		GenerationTarget... targets) {
	doCreation(
			metadata,
			serviceRegistry.getService( JdbcEnvironment.class ).getDialect(),
			new ExecutionOptions() {
				@Override
				public boolean shouldManageNamespaces() {
					return manageNamespaces;
				}

				@Override
				public Map getConfigurationValues() {
					return settings;
				}

				@Override
				public ExceptionHandler getExceptionHandler() {
					return ExceptionHandlerLoggedImpl.INSTANCE;
				}
			},
			new SourceDescriptor() {
				@Override
				public SourceType getSourceType() {
					return SourceType.METADATA;
				}

				@Override
				public ScriptSourceInput getScriptSourceInput() {
					return null;
				}
			},
			targets
	);
}
 
Example #14
Source File: ExtractionContextImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ExtractionContextImpl(
		ServiceRegistry serviceRegistry,
		JdbcEnvironment jdbcEnvironment,
		JdbcConnectionAccess jdbcConnectionAccess,
		DatabaseObjectAccess registeredTableAccess,
		Identifier defaultCatalogName,
		Identifier defaultSchemaName) {
	this.serviceRegistry = serviceRegistry;
	this.jdbcEnvironment = jdbcEnvironment;
	this.jdbcConnectionAccess = jdbcConnectionAccess;
	this.registeredTableAccess = registeredTableAccess;
	this.defaultCatalogName = defaultCatalogName;
	this.defaultSchemaName = defaultSchemaName;
}
 
Example #15
Source File: SchemaUpdate.java    From lams with 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 #16
Source File: Property.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ServiceRegistry resolveServiceRegistry() {
	if ( getPersistentClass() != null ) {
		return getPersistentClass().getServiceRegistry();
	}
	if ( getValue() != null ) {
		return getValue().getServiceRegistry();
	}
	throw new HibernateException( "Could not resolve ServiceRegistry" );
}
 
Example #17
Source File: ReactiveServiceRegistryBuilder.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Destroy a service registry.  Applications should only destroy registries they have explicitly created.
 *
 * @param serviceRegistry The registry to be closed.
 */
public static void destroy(ServiceRegistry serviceRegistry) {
    if ( serviceRegistry == null ) {
        return;
    }

    ( (StandardServiceRegistryImpl) serviceRegistry ).destroy();
}
 
Example #18
Source File: SchemaBuilderUtility.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
public static Metadata generateHbmModel(ConnectionProvider provider, Dialect dialect) throws SQLException {
    MetadataSources metadataSources = new MetadataSources();
    ServiceRegistry registry = metadataSources.getServiceRegistry();

    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
            .addService(ConnectionProvider.class, provider).addService(JdbcEnvironment.class,
                    new JdbcEnvironmentImpl(provider.getConnection().getMetaData(), dialect))
            .build();

    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContext bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );

    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();

    InFlightMetadataCollectorImpl metadataCollector =  new InFlightMetadataCollectorImpl(bootstrapContext, options);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, options,
            metadataCollector);

    JDBCBinder binder = new JDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy, false);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));
    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        public Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.start();
    return metadata;
}
 
Example #19
Source File: SchemaCreatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SchemaCreatorImpl(ServiceRegistry serviceRegistry, SchemaFilter schemaFilter) {
	SchemaManagementTool smt = serviceRegistry.getService( SchemaManagementTool.class );
	if ( smt == null || !HibernateSchemaManagementTool.class.isInstance( smt ) ) {
		smt = new HibernateSchemaManagementTool();
		( (HibernateSchemaManagementTool) smt ).injectServices( (ServiceRegistryImplementor) serviceRegistry );
	}

	this.tool = (HibernateSchemaManagementTool) smt;
	this.schemaFilter = schemaFilter;
}
 
Example #20
Source File: SchemaCreatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For testing...
 *
 * @param metadata The metadata for which to generate the creation commands.
 *
 * @return The generation commands
 */
public List<String> generateCreationCommands(Metadata metadata, final boolean manageNamespaces) {
	final JournalingGenerationTarget target = new JournalingGenerationTarget();

	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions()
			.getServiceRegistry();
	final Dialect dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect();

	final ExecutionOptions options = new ExecutionOptions() {
		@Override
		public boolean shouldManageNamespaces() {
			return manageNamespaces;
		}

		@Override
		public Map getConfigurationValues() {
			return Collections.emptyMap();
		}

		@Override
		public ExceptionHandler getExceptionHandler() {
			return ExceptionHandlerHaltImpl.INSTANCE;
		}
	};

	createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );

	return target.commands;
}
 
Example #21
Source File: SchemaCreatorImpl.java    From lams with 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 #22
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 #23
Source File: HibernateSchemaManagementTool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JdbcContextBuilder(ServiceRegistry serviceRegistry) {
	this.serviceRegistry = serviceRegistry;
	final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
	this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
	this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();

	this.dialect = jdbcServices.getJdbcEnvironment().getDialect();
	this.jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
}
 
Example #24
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the table name to use for the generator values.
 * <p/>
 * Called during {@link #configure configuration}.
 *
 * @see #getTableName()
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param jdbcEnvironment The JDBC environment
 * @return The table name to use.
 */
@SuppressWarnings({"UnusedParameters", "WeakerAccess"})
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry) {

	String fallbackTableName = DEF_TABLE;

	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 ) ) {
			fallbackTableName = generatorName;
		}
	}


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

	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 #25
Source File: SchemaDropperImpl.java    From lams with 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 #26
Source File: SchemaDropperImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void perform(ServiceRegistry serviceRegistry) {
	log.startingDelayedSchemaDrop();

	final JdbcContext jdbcContext = new JdbcContextDelayedDropImpl( serviceRegistry );
	final GenerationTargetToDatabase target = new GenerationTargetToDatabase(
			serviceRegistry.getService( TransactionCoordinatorBuilder.class ).buildDdlTransactionIsolator( jdbcContext ),
			true
	);

	target.prepare();
	try {
		for ( String command : commands ) {
			try {
				target.accept( command );
			}
			catch (CommandAcceptanceException e) {
				// implicitly we do not "halt on error", but we do want to
				// report the problem
				log.unsuccessfulSchemaManagementCommand( command );
				log.debugf( e, "Error performing delayed DROP command [%s]", command );
			}
		}
	}
	finally {
		target.release();
	}
}
 
Example #27
Source File: PostgreSQL82Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
	super.contributeTypes( typeContributions, serviceRegistry );

	// HHH-9562
	typeContributions.contributeType( PostgresUUIDType.INSTANCE );
}
 
Example #28
Source File: ForeignGenerator.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 {
	propertyName = params.getProperty( "property" );
	entityName = params.getProperty( ENTITY_NAME );
	if ( propertyName==null ) {
		throw new MappingException( "param named \"property\" is required for foreign id generation strategy" );
	}
}
 
Example #29
Source File: ResultSetWrapperProxy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a proxy wrapping the ResultSet.
 *
 * @param resultSet The resultSet to wrap.
 * @param columnNameCache The cache storing data for converting column names to column indexes.
 * @param serviceRegistry Access to any needed services
 *
 * @return The generated proxy.
 */
public static ResultSet generateProxy(
		ResultSet resultSet,
		ColumnNameCache columnNameCache,
		ServiceRegistry serviceRegistry) {
	return serviceRegistry.getService( ClassLoaderService.class ).generateProxy(
			new ResultSetWrapperProxy( resultSet, columnNameCache ),
			ResultSet.class
	);
}
 
Example #30
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 );
}