/** * Determine the name of the sequence (or table if this resolves to a physical table) * to use. * <p/> * Called during {@link #configure configuration}. * * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The sequence name */ protected String determineSequenceName(Properties params, Dialect dialect) { final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX ); // JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides. String sequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false ) ? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix : DEF_SEQUENCE_NAME; final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, sequenceName ); if ( sequenceName.indexOf( '.' ) < 0 ) { sequenceName = normalizer.normalizeIdentifierQuoting( sequenceName ); final String schemaName = params.getProperty( SCHEMA ); final String catalogName = params.getProperty( CATALOG ); sequenceName = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( sequenceName ) ); } // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. return sequenceName; }
/** * 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 dialect The dialect in effect * @return The table name to use. */ protected String determineGeneratorTableName(Properties params, Dialect dialect) { String name = ConfigurationHelper.getString( TABLE_PARAM, params, DEF_TABLE ); final boolean isGivenNameUnqualified = name.indexOf( '.' ) < 0; if ( isGivenNameUnqualified ) { final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); name = normalizer.normalizeIdentifierQuoting( name ); // if the given name is un-qualified we may neen to qualify it final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ); final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ); name = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( name) ); } // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. return name; }
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER ); sequenceName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( SEQUENCE, params, "hibernate_sequence" ) ); parameters = params.getProperty( PARAMETERS ); if ( sequenceName.indexOf( '.' ) < 0 ) { final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ); final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ); sequenceName = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( sequenceName ) ); } else { // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. } this.identifierType = type; sql = dialect.getSequenceNextValString( sequenceName ); }
public static Table buildAndFillTable( String schema, String catalog, ObjectNameSource nameSource, ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper, boolean isAbstract, List<UniqueConstraintHolder> uniqueConstraints, String constraints, Table denormalizedSuperTable, Mappings mappings, String subselect) { return buildAndFillTable( schema, catalog, nameSource, namingStrategyHelper, isAbstract, uniqueConstraints, null, constraints , denormalizedSuperTable, mappings, subselect); }
public void configure(Type type, Properties params, Dialect dialect) { identifierType = type; ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER ); tableName = ConfigurationHelper.getString( TABLE, params, DEFAULT_TABLE_NAME ); if ( tableName.indexOf( '.' ) < 0 ) { final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ); final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ); tableName = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( tableName ) ); } else { // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. } columnName = dialect.quote( normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( COLUMN, params, DEFAULT_COLUMN_NAME ) ) ); query = "select " + columnName + " from " + dialect.appendLockHint(LockMode.PESSIMISTIC_WRITE, tableName) + dialect.getForUpdateString(); update = "update " + tableName + " set " + columnName + " = ? where " + columnName + " = ?"; }
public static Table buildAndFillTable( String schema, String catalog, ObjectNameSource nameSource, ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper, boolean isAbstract, List<UniqueConstraintHolder> uniqueConstraints, List<JPAIndexHolder> jpaIndexHolders, String constraints, Table denormalizedSuperTable, Mappings mappings, String subselect){ schema = BinderHelper.isEmptyAnnotationValue( schema ) ? mappings.getSchemaName() : schema; catalog = BinderHelper.isEmptyAnnotationValue( catalog ) ? mappings.getCatalogName() : catalog; String realTableName = mappings.getObjectNameNormalizer().normalizeDatabaseIdentifier( nameSource.getExplicitName(), namingStrategyHelper ); final Table table; if ( denormalizedSuperTable != null ) { table = mappings.addDenormalizedTable( schema, catalog, realTableName, isAbstract, subselect, denormalizedSuperTable ); } else { table = mappings.addTable( schema, catalog, realTableName, subselect, isAbstract ); } if ( CollectionHelper.isNotEmpty( uniqueConstraints ) ) { mappings.addUniqueConstraintHolders( table, uniqueConstraints ); } if ( CollectionHelper.isNotEmpty( jpaIndexHolders ) ) { mappings.addJpaIndexHolders( table, jpaIndexHolders ); } if ( constraints != null ) table.addCheckConstraint( constraints ); // logicalName is null if we are in the second pass final String logicalName = nameSource.getLogicalName(); if ( logicalName != null ) { mappings.addTableBinding( schema, catalog, logicalName, realTableName, denormalizedSuperTable ); } return table; }
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER ); tableName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE ) ); if ( tableName.indexOf( '.' ) < 0 ) { tableName = dialect.quote( tableName ); final String schemaName = dialect.quote( normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ) ); final String catalogName = dialect.quote( normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ) ); tableName = Table.qualify( catalogName, schemaName, tableName ); } else { // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. } pkColumnName = dialect.quote( normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN ) ) ); valueColumnName = dialect.quote( normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN ) ) ); keySize = ConfigurationHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH); String keyValue = ConfigurationHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE) ); query = "select " + valueColumnName + " from " + dialect.appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) + " where " + pkColumnName + " = '" + keyValue + "'" + dialect.getForUpdateString(); update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and " + pkColumnName + " = '" + keyValue + "'"; insert = "insert into " + tableName + "(" + pkColumnName + ", " + valueColumnName + ") " + "values('"+ keyValue +"', ?)"; //hilo config maxLo = ConfigurationHelper.getInt(MAX_LO, params, Short.MAX_VALUE); returnClass = type.getReturnedClass(); if ( maxLo >= 1 ) { hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( returnClass, maxLo ); } }
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { returnClass = type.getReturnedClass(); ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER ); String column = params.getProperty( "column" ); if ( column == null ) { column = params.getProperty( PersistentIdentifierGenerator.PK ); } column = dialect.quote( normalizer.normalizeIdentifierQuoting( column ) ); String tableList = params.getProperty( "tables" ); if ( tableList == null ) { tableList = params.getProperty( PersistentIdentifierGenerator.TABLES ); } String[] tables = StringHelper.split( ", ", tableList ); final String schema = dialect.quote( normalizer.normalizeIdentifierQuoting( params.getProperty( PersistentIdentifierGenerator.SCHEMA ) ) ); final String catalog = dialect.quote( normalizer.normalizeIdentifierQuoting( params.getProperty( PersistentIdentifierGenerator.CATALOG ) ) ); StringBuilder buf = new StringBuilder(); for ( int i=0; i < tables.length; i++ ) { final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) ); if ( tables.length > 1 ) { buf.append( "select max(" ).append( column ).append( ") as mx from " ); } buf.append( Table.qualify( catalog, schema, tableName ) ); if ( i < tables.length-1 ) { buf.append( " union " ); } } if ( tables.length > 1 ) { buf.insert( 0, "( " ).append( " ) ids_" ); column = "ids_.mx"; } sql = "select max(" + column + ") from " + buf.toString(); }
@Override public void configure(Type type, Properties params, Dialect dialect) { String sequence = params.getProperty(SEQUENCE); if (ConventionUtils.isEmpty(sequence)) { String entityName = params.getProperty(ENTITY_NAME); String table = params.getProperty(TABLE); ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER); ConventionNamingStrategy strategy = ConventionUtils.extractNameStrategy(normalizer); sequence = strategy.sequenceName(entityName, table); params.setProperty(SEQUENCE, sequence); } super.configure(type, params, dialect); }
public static ConventionNamingStrategy extractNameStrategy(ObjectNameNormalizer normalizer) { return (ConventionNamingStrategy) invokeMethod("getNamingStrategy", normalizer); }
/** * Determine the name of the column used to store the generator value in * the db. * <p/> * Called during {@link #configure configuration} <b>when resolving to a * physical table</b>. * * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect. * @return The value column name */ protected String determineValueColumnName(Properties params, Dialect dialect) { final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN ); return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) ); }
/** * Determine the name of the column used to indicate the segment for each * row. This column acts as the primary key. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentColumnName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The name of the segment column */ protected String determineSegmentColumnName(Properties params, Dialect dialect) { final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); final String name = ConfigurationHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN ); return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) ); }
/** * Determine the name of the column in which we will store the generator persistent value. * <p/> * Called during {@link #configure configuration}. * * @see #getValueColumnName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The name of the value column */ protected String determineValueColumnName(Properties params, Dialect dialect) { final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN ); return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) ); }