org.hibernate.mapping.Index Java Examples
The following examples show how to use
org.hibernate.mapping.Index.
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 |
@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: SpannerTableStatements.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 5 votes |
private Set<String> getTableIndices(Table table) { Set<String> tableIndices = new HashSet<>(); Iterator<Index> indexIterator = table.getIndexIterator(); while (indexIterator.hasNext()) { tableIndices.add(indexIterator.next().getName()); } Iterator<UniqueKey> keyIterator = table.getUniqueKeyIterator(); while (keyIterator.hasNext()) { tableIndices.add(keyIterator.next().getName()); } return tableIndices; }
Example #3
Source File: SpannerTableStatementsTests.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testDropTableStatement_withIndex() { Table table = new Table(); table.setName("House"); Index index = new Index(); index.setName("address"); table.addIndex(index); List<String> statements = spannerTableStatements.dropTable(table); assertThat(statements).containsExactly("drop index address", "drop table House"); }
Example #4
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void applyIndexes( Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { final Exporter<Index> exporter = dialect.getIndexExporter(); final Iterator<Index> indexItr = table.getIndexIterator(); while ( indexItr.hasNext() ) { final Index index = indexItr.next(); if ( !StringHelper.isEmpty( index.getName() ) ) { IndexInformation existingIndex = null; if ( tableInformation != null ) { existingIndex = findMatchingIndex( index, tableInformation ); } if ( existingIndex == null ) { applySqlStrings( false, exporter.getSqlCreateStrings( index, metadata ), formatter, options, targets ); } } } }
Example #5
Source File: IgniteCacheInitializer.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 5 votes |
/** * Create indexes for {@code @Index} annotations * @param queryEntity * @param context */ private void addUserIndexes(QueryEntity queryEntity, SchemaDefinitionContext context, String tableName) { Namespace namespace = context.getDatabase().getDefaultNamespace(); Optional<Table> tableOptional = namespace.getTables().stream().filter( currentTable -> currentTable.getName().equals( tableName ) ).findFirst(); if ( tableOptional.isPresent() ) { Table table = tableOptional.get(); for ( Iterator<Index> indexIterator = table.getIndexIterator(); indexIterator.hasNext(); ) { Index index = indexIterator.next(); appendIndex( queryEntity, index, context ); } } }
Example #6
Source File: IgniteCacheInitializer.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 5 votes |
private void appendIndex(QueryEntity queryEntity, Index index, SchemaDefinitionContext context) { QueryIndex queryIndex = new QueryIndex(); queryIndex.setName( index.getName() ); queryIndex.setIndexType( QueryIndexType.SORTED ); LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>(); for ( Iterator<Column> columnIterator = index.getColumnIterator(); columnIterator.hasNext(); ) { Column currentColumn = columnIterator.next(); fields.put( currentColumn.getName(), true ); } queryIndex.setFields( fields ); Set<QueryIndex> indexes = new HashSet<>( queryEntity.getIndexes() ); indexes.add( queryIndex ); queryEntity.setIndexes( indexes ); }
Example #7
Source File: SpannerUniqueDelegate.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 4 votes |
@Override public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { return Index.buildSqlCreateIndexString( dialect, uniqueKey.getName(), uniqueKey.getTable(), uniqueKey.columnIterator(), uniqueKey.getColumnOrderMap(), true, metadata); }
Example #8
Source File: StandardIndexExporter.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public String[] getSqlCreateStrings(Index index, Metadata metadata) { final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( index.getTable().getQualifiedTableName(), dialect ); final String indexNameForCreation; if ( dialect.qualifyIndexName() ) { indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format( new QualifiedNameImpl( index.getTable().getQualifiedTableName().getCatalogName(), index.getTable().getQualifiedTableName().getSchemaName(), jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getQuotedName( dialect ) ) ), jdbcEnvironment.getDialect() ); } else { indexNameForCreation = index.getName(); } final StringBuilder buf = new StringBuilder() .append( "create index " ) .append( indexNameForCreation ) .append( " on " ) .append( tableName ) .append( " (" ); boolean first = true; final Iterator<Column> columnItr = index.getColumnIterator(); final Map<Column, String> columnOrderMap = index.getColumnOrderMap(); while ( columnItr.hasNext() ) { final Column column = columnItr.next(); if ( first ) { first = false; } else { buf.append( ", " ); } buf.append( ( column.getQuotedName( dialect ) ) ); if ( columnOrderMap.containsKey( column ) ) { buf.append( " " ).append( columnOrderMap.get( column ) ); } } buf.append( ")" ); return new String[] { buf.toString() }; }
Example #9
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 4 votes |
private IndexInformation findMatchingIndex(Index index, TableInformation tableInformation) { return tableInformation.getIndex( Identifier.toIdentifier( index.getName() ) ); }
Example #10
Source File: Teradata14Dialect.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public Exporter<Index> getIndexExporter() { return TeraIndexExporter; }
Example #11
Source File: Teradata14Dialect.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public String[] getSqlCreateStrings(Index index, Metadata metadata) { final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( index.getTable().getQualifiedTableName(), jdbcEnvironment.getDialect() ); final String indexNameForCreation; if ( getDialect().qualifyIndexName() ) { indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format( new QualifiedNameImpl( index.getTable().getQualifiedTableName().getCatalogName(), index.getTable().getQualifiedTableName().getSchemaName(), jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getName() ) ), jdbcEnvironment.getDialect() ); } else { indexNameForCreation = index.getName(); } StringBuilder colBuf = new StringBuilder(""); boolean first = true; Iterator<Column> columnItr = index.getColumnIterator(); while ( columnItr.hasNext() ) { final Column column = columnItr.next(); if ( first ) { first = false; } else { colBuf.append( ", " ); } colBuf.append( ( column.getQuotedName( jdbcEnvironment.getDialect() )) ); } colBuf.append( ")" ); final StringBuilder buf = new StringBuilder() .append( "create index " ) .append( indexNameForCreation ) .append( "(" + colBuf ) .append( " on " ) .append( tableName ); return new String[] { buf.toString() }; }
Example #12
Source File: Dialect.java From lams with GNU General Public License v2.0 | 4 votes |
public Exporter<Index> getIndexExporter() { return indexExporter; }
Example #13
Source File: DelegatingDialect.java From keycloak with Apache License 2.0 | 4 votes |
@Override public Exporter<Index> getIndexExporter() { return getInstance().getIndexExporter(); }