Java Code Examples for org.hibernate.boot.model.relational.Namespace#locateTable()
The following examples show how to use
org.hibernate.boot.model.relational.Namespace#locateTable() .
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: InFlightMetadataCollectorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Table addTable( String schemaName, String catalogName, String name, String subselectFragment, boolean isAbstract) { final Namespace namespace = getDatabase().locateNamespace( getDatabase().toIdentifier( catalogName ), getDatabase().toIdentifier( schemaName ) ); // annotation binding depends on the "table name" for @Subselect bindings // being set into the generated table (mainly to avoid later NPE), but for now we need to keep that :( final Identifier logicalName; if ( name != null ) { logicalName = getDatabase().toIdentifier( name ); } else { logicalName = null; } if ( subselectFragment != null ) { return new Table( namespace, logicalName, subselectFragment, isAbstract ); } else { Table table = namespace.locateTable( logicalName ); if ( table != null ) { if ( !isAbstract ) { table.setAbstract( false ); } return table; } return namespace.createTable( logicalName, isAbstract ); } }
Example 2
Source File: InFlightMetadataCollectorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Table addDenormalizedTable( String schemaName, String catalogName, String name, boolean isAbstract, String subselectFragment, Table includedTable) throws DuplicateMappingException { final Namespace namespace = getDatabase().locateNamespace( getDatabase().toIdentifier( catalogName ), getDatabase().toIdentifier( schemaName ) ); // annotation binding depends on the "table name" for @Subselect bindings // being set into the generated table (mainly to avoid later NPE), but for now we need to keep that :( final Identifier logicalName; if ( name != null ) { logicalName = getDatabase().toIdentifier( name ); } else { logicalName = null; } if ( subselectFragment != null ) { return new DenormalizedTable( namespace, logicalName, subselectFragment, isAbstract, includedTable ); } else { Table table = namespace.locateTable( logicalName ); if ( table != null ) { throw new DuplicateMappingException( DuplicateMappingException.Type.TABLE, logicalName.toString() ); } else { table = namespace.createDenormalizedTable( logicalName, isAbstract, includedTable ); } return table; } }
Example 3
Source File: TableGenerator.java From lams with GNU General Public License v2.0 | 4 votes |
@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 4
Source File: TableStructure.java From lams with GNU General Public License v2.0 | 4 votes |
@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 5
Source File: MultipleHiLoPerTableGenerator.java From lams with GNU General Public License v2.0 | 4 votes |
@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 + "', ?)"; }