org.hibernate.engine.jdbc.env.spi.JdbcEnvironment Java Examples

The following examples show how to use org.hibernate.engine.jdbc.env.spi.JdbcEnvironment. 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: StandardIndexExporter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String[] getSqlDropStrings(Index index, Metadata metadata) {
	if ( !dialect.dropConstraints() ) {
		return NO_COMMANDS;
	}

	final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
	final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			index.getTable().getQualifiedTableName(),
			dialect
	);

	final String indexNameForCreation;
	if ( dialect.qualifyIndexName() ) {
		indexNameForCreation = StringHelper.qualify( tableName, index.getName() );
	}
	else {
		indexNameForCreation = index.getName();
	}

	return new String[] { "drop index " + indexNameForCreation };
}
 
Example #2
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"StatementWithEmptyBody", "deprecation"})
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
	returnClass = type.getReturnedClass();

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

	qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment );

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

	valueColumnName = determineValueColumnName( params, jdbcEnvironment );

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

	if ( maxLo >= 1 ) {
		hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( returnClass, maxLo );
	}
}
 
Example #3
Source File: 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: 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 #5
Source File: Index.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static String buildSqlCreateIndexString(
		Dialect dialect,
		String name,
		Table table,
		Iterator<Column> columns,
		java.util.Map<Column, String> columnOrderMap,
		boolean unique,
		Metadata metadata) {
	final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();

	final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			dialect
	);

	return buildSqlCreateIndexString(
			dialect,
			name,
			tableName,
			columns,
			columnOrderMap,
			unique
	);
}
 
Example #6
Source File: Helper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static DatabaseInformation buildDatabaseInformation(
		ServiceRegistry serviceRegistry,
		DdlTransactionIsolator ddlTransactionIsolator,
		Namespace.Name defaultNamespace) {
	final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
	try {
		return new DatabaseInformationImpl(
				serviceRegistry,
				jdbcEnvironment,
				ddlTransactionIsolator,
				defaultNamespace
		);
	}
	catch (SQLException e) {
		throw jdbcEnvironment.getSqlExceptionHelper().convert( e, "Unable to build DatabaseInformation" );
	}
}
 
Example #7
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String determineTableName(Table table, JdbcEnvironment jdbcEnvironment) {
	if ( table.getSubselect() != null ) {
		return "( " + table.getSubselect() + " )";
	}

	return jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			jdbcEnvironment.getDialect()
	);
}
 
Example #8
Source File: TableGenerator.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 {
	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
	);
}
 
Example #9
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 #10
Source File: SequenceGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final Namespace namespace = database.locateNamespace(
			logicalQualifiedSequenceName.getCatalogName(),
			logicalQualifiedSequenceName.getSchemaName()
	);
	Sequence sequence = namespace.locateSequence( logicalQualifiedSequenceName.getObjectName() );
	if ( sequence != null ) {
		sequence.validate( 1, 1 );
	}
	else {
		sequence = namespace.createSequence(
				logicalQualifiedSequenceName.getObjectName(),
				1,
				1
		);
	}

	final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
	final Dialect dialect = jdbcEnvironment.getDialect();

	this.sequenceName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			sequence.getName(),
			dialect
	);
	this.sql = jdbcEnvironment.getDialect().getSequenceNextValString( sequenceName );
}
 
Example #11
Source File: AbstractMultiTableBulkIdStrategyImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String buildIdTableDropStatement(Table idTable, JdbcServices jdbcServices) {
	final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
	final Dialect dialect = jdbcEnvironment.getDialect();

	return getIdTableSupport().getDropIdTableCommand() + " "
			+ jdbcEnvironment.getQualifiedObjectNameFormatter().format( idTable.getQualifiedTableName(), dialect );
}
 
Example #12
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 #13
Source File: StandardSequenceExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) {
	final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
	return dialect.getCreateSequenceStrings(
			jdbcEnvironment.getQualifiedObjectNameFormatter().format(
					sequence.getName(),
					jdbcEnvironment.getDialect()
			),
			sequence.getInitialValue(),
			sequence.getIncrementSize()
	);
}
 
Example #14
Source File: Database.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Database(MetadataBuildingOptions buildingOptions, JdbcEnvironment jdbcEnvironment) {
	this.buildingOptions = buildingOptions;

	this.jdbcEnvironment = jdbcEnvironment;

	this.dialect = determineDialect( buildingOptions );

	this.implicitNamespace = makeNamespace(
			new Namespace.Name(
					toIdentifier( buildingOptions.getMappingDefaults().getImplicitCatalogName() ),
					toIdentifier( buildingOptions.getMappingDefaults().getImplicitSchemaName() )
			)
	);
}
 
Example #15
Source File: ProcedureParameterImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean canDoNameParameterBinding(Type hibernateType) {
	final ExtractedDatabaseMetaData databaseMetaData = procedureCall.getSession()
			.getJdbcCoordinator()
			.getJdbcSessionOwner()
			.getJdbcSessionContext()
			.getServiceRegistry().getService( JdbcEnvironment.class )
			.getExtractedDatabaseMetaData();
	return
			databaseMetaData.supportsNamedParameters()
					&& ProcedureParameterNamedBinder.class.isInstance( hibernateType )
					&& ((ProcedureParameterNamedBinder) hibernateType).canDoSetting();
}
 
Example #16
Source File: SequenceStyleGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected DatabaseStructure buildSequenceStructure(
		Type type,
		Properties params,
		JdbcEnvironment jdbcEnvironment,
		QualifiedName sequenceName,
		int initialValue,
		int incrementSize) {
	return new SequenceStructure( jdbcEnvironment, sequenceName, initialValue, incrementSize, type.getReturnedClass() );
}
 
Example #17
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 #18
Source File: PersistentTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected QualifiedTableName determineIdTableName(
		JdbcEnvironment jdbcEnvironment,
		PersistentClass entityBinding) {
	return new QualifiedTableName(
			catalog,
			schema,
			super.determineIdTableName( jdbcEnvironment, entityBinding ).getTableName()
	);
}
 
Example #19
Source File: IdentifierGeneration.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #20
Source File: SchemaDropperImpl.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> generateDropCommands(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;
		}
	};

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

	return target.commands;
}
 
Example #21
Source File: NomulusNamingStrategy.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
  if (name.isQuoted()) {
    return name;
  }
  // Convert the lowerCamelCase field name into the snake_case column name
  return jdbcEnvironment
      .getIdentifierHelper()
      .toIdentifier(
          CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name.getText()),
          /* quoted= */ false);
}
 
Example #22
Source File: DefaultUniqueDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
	final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();

	final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			uniqueKey.getTable().getQualifiedTableName(),
			dialect
	);

	final String constraintName = dialect.quote( uniqueKey.getName() );
	return dialect.getAlterTableString( tableName )
			+ " add constraint " + constraintName + " " + uniqueConstraintSql( uniqueKey );
}
 
Example #23
Source File: QuarkusNoJdbcEnvironmentInitiator.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Class<JdbcEnvironment> getServiceInitiated() {
    return JdbcEnvironment.class;
}
 
Example #24
Source File: RobeHibernateNamingStrategy.java    From robe with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Identifier toPhysicalColumnName(Identifier identifier, JdbcEnvironment jdbcEnv) {
    return identifier;
}
 
Example #25
Source File: DatabaseNamingStrategy.java    From WeBASE-Collect-Bee with Apache License 2.0 4 votes vote down vote up
@Override
public Identifier toPhysicalSchemaName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
    return identifier;
}
 
Example #26
Source File: PrefixPhysicalNamingStrategy.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {
    return Identifier.toIdentifier("SEQ_" + name.getText());
}
 
Example #27
Source File: PrefixPhysicalNamingStrategy.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
    return Identifier.toIdentifier("COL_" + name.getText());
}
 
Example #28
Source File: CamelCaseToSnakeCaseNamingStrategy.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment context) {
    return formatIdentifier(super.toPhysicalSchemaName(name, context));
}
 
Example #29
Source File: Database.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Database(MetadataBuildingOptions buildingOptions) {
	this( buildingOptions, buildingOptions.getServiceRegistry().getService( JdbcEnvironment.class ) );
}
 
Example #30
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
	final String name = ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN );
	return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
}