org.hibernate.boot.model.relational.Database Java Examples

The following examples show how to use org.hibernate.boot.model.relational.Database. 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
private static Metadata setupMetadataMock() {
  Metadata metadata = mock(Metadata.class);
  Database database = mock(Database.class);
  JdbcEnvironment jdbcEnvironment = mock(JdbcEnvironment.class);
  QualifiedObjectNameFormatter qualifiedObjectNameFormatter =
      mock(QualifiedObjectNameFormatter.class);

  when(metadata.getDatabase()).thenReturn(database);
  when(database.getJdbcEnvironment()).thenReturn(jdbcEnvironment);
  when(jdbcEnvironment.getQualifiedObjectNameFormatter())
      .thenReturn(qualifiedObjectNameFormatter);
  when(qualifiedObjectNameFormatter.format(any(QualifiedTableName.class), any()))
      .thenAnswer(invocation ->
          ((QualifiedTableName) invocation.getArguments()[0]).getTableName().getCanonicalName());

  return metadata;
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: AbstractSchemaMigrator.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void migrateTable(
		Table table,
		TableInformation tableInformation,
		Dialect dialect,
		Metadata metadata,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	final Database database = metadata.getDatabase();

	//noinspection unchecked
	applySqlStrings(
			false,
			table.sqlAlterStrings(
					dialect,
					metadata,
					tableInformation,
					getDefaultCatalogName( database, dialect ),
					getDefaultSchemaName( database, dialect )
			),
			formatter,
			options,
			targets
	);
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: SequenceStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void buildSequence(Database database) {
	final int sourceIncrementSize = getSourceIncrementSize();

	final Namespace namespace = database.locateNamespace(
			logicalQualifiedSequenceName.getCatalogName(),
			logicalQualifiedSequenceName.getSchemaName()
	);
	Sequence sequence = namespace.locateSequence( logicalQualifiedSequenceName.getObjectName() );
	if ( sequence != null ) {
		sequence.validate( initialValue, sourceIncrementSize );
	}
	else {
		sequence = namespace.createSequence( logicalQualifiedSequenceName.getObjectName(), initialValue, sourceIncrementSize );
	}

	this.sequenceName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
			sequence.getName(),
			database.getJdbcEnvironment().getDialect()
	);
}
 
Example #4
Source Project: hibernate-reactive   Author: hibernate   File: ReactiveGeneratorWrapper.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerExportables(Database database) {
	if (generator instanceof ExportableProducer) {
		((ExportableProducer) generator).registerExportables( database );
	}
	if (reactiveGenerator instanceof ExportableProducer) {
		((ExportableProducer) reactiveGenerator).registerExportables( database );
	}
}
 
Example #5
Source Project: lams   Author: lamsfoundation   File: Ejb3Column.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void addColumnBinding(SimpleValue value) {
	final String logicalColumnName;
	if ( StringHelper.isNotEmpty( this.logicalColumnName ) ) {
		logicalColumnName = this.logicalColumnName;
	}
	else {
		final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
		final Database database = context.getMetadataCollector().getDatabase();
		final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions()
				.getImplicitNamingStrategy();

		final Identifier implicitName = normalizer.normalizeIdentifierQuoting(
				implicitNamingStrategy.determineBasicColumnName(
						new ImplicitBasicColumnNameSource() {
							@Override
							public AttributePath getAttributePath() {
								return AttributePath.parse( propertyName );
							}

							@Override
							public boolean isCollectionElement() {
								return false;
							}

							@Override
							public MetadataBuildingContext getBuildingContext() {
								return context;
							}
						}
				)
		);
		logicalColumnName = implicitName.render( database.getDialect() );
	}
	context.getMetadataCollector().addColumnNameBinding( value.getTable(), logicalColumnName, getMappingColumn() );
}
 
Example #6
Source Project: lams   Author: lamsfoundation   File: ExportableColumn.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ExportableColumn(Database database, Table table, String name, BasicType type) {
	this(
			database,
			table,
			name,
			type,
			database.getDialect().getTypeName( type.sqlTypes( null )[0] )
	);
}
 
Example #7
Source Project: lams   Author: lamsfoundation   File: ExportableColumn.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ExportableColumn(
		Database database,
		Table table,
		String name,
		BasicType type,
		String dbTypeDeclaration) {
	super( name );
	setValue( new ValueImpl( this, table, type, database ) );
	setSqlType( dbTypeDeclaration );
}
 
Example #8
Source Project: lams   Author: lamsfoundation   File: SequenceGenerator.java    License: 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 #9
Source Project: lams   Author: lamsfoundation   File: InFlightMetadataCollectorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Database getDatabase() {
	// important to delay this instantiation until as late as possible.
	if ( database == null ) {
		this.database = new Database( options );
	}
	return database;
}
 
Example #10
Source Project: quarkus   Author: quarkusio   File: PrevalidatedQuarkusMetadata.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Database getDatabase() {
    return metadata.getDatabase();
}
 
Example #11
Source Project: lams   Author: lamsfoundation   File: Component.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	if ( ExportableProducer.class.isInstance( subGenerator ) ) {
		( (ExportableProducer) subGenerator ).registerExportables( database );
	}
}
 
Example #12
Source Project: lams   Author: lamsfoundation   File: AbstractSchemaMigrator.java    License: GNU General Public License v2.0 4 votes vote down vote up
private String getDefaultCatalogName(Database database, Dialect dialect) {
	final Identifier identifier = database.getDefaultNamespace().getPhysicalName().getCatalog();
	return identifier == null ? null : identifier.render( dialect );
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: AbstractSchemaMigrator.java    License: GNU General Public License v2.0 4 votes vote down vote up
private String getDefaultSchemaName(Database database, Dialect dialect) {
	final Identifier identifier = database.getDefaultNamespace().getPhysicalName().getSchema();
	return identifier == null ? null : identifier.render( dialect );
}
 
Example #14
Source Project: lams   Author: lamsfoundation   File: SequenceStyleGenerator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	databaseStructure.registerExportables( database );
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: TableGenerator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final Dialect dialect = database.getJdbcEnvironment().getDialect();

	final Namespace namespace = database.locateNamespace(
			qualifiedTableName.getCatalogName(),
			qualifiedTableName.getSchemaName()
	);

	Table table = namespace.locateTable( qualifiedTableName.getObjectName() );
	if ( table == null ) {
		table = namespace.createTable( qualifiedTableName.getObjectName(), false );

		// todo : note sure the best solution here.  do we add the columns if missing?  other?
		final Column segmentColumn = new ExportableColumn(
				database,
				table,
				segmentColumnName,
				StringType.INSTANCE,
				dialect.getTypeName( Types.VARCHAR, segmentValueLength, 0, 0 )
		);
		segmentColumn.setNullable( false );
		table.addColumn( segmentColumn );

		// lol
		table.setPrimaryKey( new PrimaryKey( table ) );
		table.getPrimaryKey().addColumn( segmentColumn );

		final Column valueColumn = new ExportableColumn(
				database,
				table,
				valueColumnName,
				LongType.INSTANCE
		);
		table.addColumn( valueColumn );
	}

	// allow physical naming strategies a chance to kick in
	this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			dialect
	);
	table.addInitCommand( generateInsertInitCommand() );

	this.selectQuery = buildSelectQuery( dialect );
	this.updateQuery = buildUpdateQuery();
	this.insertQuery = buildInsertQuery();
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: TableStructure.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
	final Dialect dialect = jdbcEnvironment.getDialect();

	final Namespace namespace = database.locateNamespace(
			logicalQualifiedTableName.getCatalogName(),
			logicalQualifiedTableName.getSchemaName()
	);

	Table table = namespace.locateTable( logicalQualifiedTableName.getObjectName() );
	if ( table == null ) {
		table = namespace.createTable( logicalQualifiedTableName.getObjectName(), false );
	}

	this.tableNameText = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			dialect
	);

	this.valueColumnNameText = logicalValueColumnNameIdentifier.render( dialect );


	this.selectQuery = "select " + valueColumnNameText + " as id_val" +
			" from " + dialect.appendLockHint( LockMode.PESSIMISTIC_WRITE, tableNameText ) +
			dialect.getForUpdateString();

	this.updateQuery = "update " + tableNameText +
			" set " + valueColumnNameText + "= ?" +
			" where " + valueColumnNameText + "=?";

	ExportableColumn valueColumn = new ExportableColumn(
			database,
			table,
			valueColumnNameText,
			LongType.INSTANCE
	);
	table.addColumn( valueColumn );

	table.addInitCommand(
			new InitCommand( "insert into " + tableNameText + " values ( " + initialValue + " )" )
	);
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: SequenceStructure.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	buildSequence( database );
	this.sql = database.getJdbcEnvironment().getDialect().getSequenceNextValString( sequenceName );
}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: MultipleHiLoPerTableGenerator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final Namespace namespace = database.locateNamespace(
			qualifiedTableName.getCatalogName(),
			qualifiedTableName.getSchemaName()
	);

	Table table = namespace.locateTable( qualifiedTableName.getObjectName() );
	if ( table == null ) {
		table = namespace.createTable( qualifiedTableName.getObjectName(), false );

		// todo : note sure the best solution here.  do we add the columns if missing?  other?
		table.setPrimaryKey( new PrimaryKey( table ) );

		final Column pkColumn = new ExportableColumn(
				database,
				table,
				segmentColumnName,
				StringType.INSTANCE,
				database.getDialect().getTypeName( Types.VARCHAR, keySize, 0, 0 )
		);
		pkColumn.setNullable( false );
		table.addColumn( pkColumn );
		table.getPrimaryKey().addColumn( pkColumn );

		final Column valueColumn = new ExportableColumn(
				database,
				table,
				valueColumnName,
				LongType.INSTANCE
		);
		table.addColumn( valueColumn );
	}

	final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();

	// allow physical naming strategies a chance to kick in
	tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			jdbcEnvironment.getDialect()
	);

	query = "select " +
			valueColumnName +
			" from " +
			jdbcEnvironment.getDialect().appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) +
			" where " + segmentColumnName + " = '" + segmentName + "'" +
			jdbcEnvironment.getDialect().getForUpdateString();

	update = "update " +
			tableName +
			" set " +
			valueColumnName +
			" = ? where " +
			valueColumnName +
			" = ? and " +
			segmentColumnName +
			" = '" +
			segmentName
			+ "'";

	insert = "insert into " + tableName +
			"(" + segmentColumnName + ", " + valueColumnName + ") " +
			"values('" + segmentName + "', ?)";



}
 
Example #19
Source Project: lams   Author: lamsfoundation   File: CompositeNestedGeneratedValueGenerator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	for (GenerationPlan plan : generationPlans) {
		plan.registerExportables( database );
	}
}
 
Example #20
Source Project: lams   Author: lamsfoundation   File: ExportableColumn.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ValueImpl(ExportableColumn column, Table table, BasicType type, Database database) {
	this.column = column;
	this.table = table;
	this.type = type;
	this.database = database;
}
 
Example #21
Source Project: lams   Author: lamsfoundation   File: AbstractDelegatingMetadata.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Database getDatabase() {
	return delegate.getDatabase();
}
 
Example #22
Source Project: lams   Author: lamsfoundation   File: ObjectNameNormalizer.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected Database database() {
	if ( database == null ) {
		database = getBuildingContext().getMetadataCollector().getDatabase();
	}
	return database;
}
 
Example #23
Source Project: lams   Author: lamsfoundation   File: MetadataImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
MetadataImpl(
		UUID uuid,
		MetadataBuildingOptions metadataBuildingOptions,
		MutableIdentifierGeneratorFactory identifierGeneratorFactory,
		Map<String, PersistentClass> entityBindingMap,
		Map<Class, MappedSuperclass> mappedSuperclassMap,
		Map<String, Collection> collectionBindingMap,
		Map<String, TypeDefinition> typeDefinitionMap,
		Map<String, FilterDefinition> filterDefinitionMap,
		Map<String, FetchProfile> fetchProfileMap,
		Map<String, String> imports,
		Map<String, IdentifierGeneratorDefinition> idGeneratorDefinitionMap,
		Map<String, NamedQueryDefinition> namedQueryMap,
		Map<String, NamedSQLQueryDefinition> namedNativeQueryMap,
		Map<String, NamedProcedureCallDefinition> namedProcedureCallMap,
		Map<String, ResultSetMappingDefinition> sqlResultSetMappingMap,
		Map<String, NamedEntityGraphDefinition> namedEntityGraphMap,
		Map<String, SQLFunction> sqlFunctionMap,
		java.util.Collection<DomainDataRegionConfigImpl.Builder> cacheRegionConfigBuilders,
		Database database,
		BootstrapContext bootstrapContext) {
	this.uuid = uuid;
	this.metadataBuildingOptions = metadataBuildingOptions;
	this.identifierGeneratorFactory = identifierGeneratorFactory;
	this.entityBindingMap = entityBindingMap;
	this.mappedSuperclassMap = mappedSuperclassMap;
	this.collectionBindingMap = collectionBindingMap;
	this.typeDefinitionMap = typeDefinitionMap;
	this.filterDefinitionMap = filterDefinitionMap;
	this.fetchProfileMap = fetchProfileMap;
	this.imports = imports;
	this.idGeneratorDefinitionMap = idGeneratorDefinitionMap;
	this.namedQueryMap = namedQueryMap;
	this.namedNativeQueryMap = namedNativeQueryMap;
	this.namedProcedureCallMap = namedProcedureCallMap;
	this.sqlResultSetMappingMap = sqlResultSetMappingMap;
	this.namedEntityGraphMap = namedEntityGraphMap;
	this.sqlFunctionMap = sqlFunctionMap;
	this.cacheRegionConfigBuilders = cacheRegionConfigBuilders;
	this.database = database;
	this.bootstrapContext = bootstrapContext;
}
 
Example #24
Source Project: lams   Author: lamsfoundation   File: MetadataImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Database getDatabase() {
	return database;
}
 
Example #25
Source Project: high-performance-java-persistence   Author: vladmihalcea   File: MetadataExtractorIntegrator.java    License: Apache License 2.0 4 votes vote down vote up
public Database getDatabase() {
	return database;
}
 
Example #26
Source Project: tutorials   Author: eugenp   File: MetadataExtractorIntegrator.java    License: MIT License 4 votes vote down vote up
public Database getDatabase() {
    return database;
}
 
Example #27
Source Project: lams   Author: lamsfoundation   File: Metadata.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieve the database model.
 *
 * @return The database model.
 */
Database getDatabase();