Methods Summary |
---|
public void | configure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.dialect.Dialect dialect)
tableName = PropertiesHelper.getString(TABLE, params, DEFAULT_TABLE_NAME);
columnName = PropertiesHelper.getString(COLUMN, params, DEFAULT_COLUMN_NAME);
String schemaName = params.getProperty(SCHEMA);
String catalogName = params.getProperty(CATALOG);
if ( tableName.indexOf( '." )<0 ) {
tableName = Table.qualify( catalogName, schemaName, tableName );
}
query = "select " +
columnName +
" from " +
dialect.appendLockHint(LockMode.UPGRADE, tableName) +
dialect.getForUpdateString();
update = "update " +
tableName +
" set " +
columnName +
" = ? where " +
columnName +
" = ?";
|
public java.io.Serializable | doWorkInCurrentTransaction(java.sql.Connection conn, java.lang.String sql)
int result;
int rows;
do {
// The loop ensures atomicity of the
// select + update even for no transaction
// or read committed isolation level
sql = query;
SQL.debug(query);
PreparedStatement qps = conn.prepareStatement(query);
try {
ResultSet rs = qps.executeQuery();
if ( !rs.next() ) {
String err = "could not read a hi value - you need to populate the table: " + tableName;
log.error(err);
throw new IdentifierGenerationException(err);
}
result = rs.getInt(1);
rs.close();
}
catch (SQLException sqle) {
log.error("could not read a hi value", sqle);
throw sqle;
}
finally {
qps.close();
}
sql = update;
SQL.debug(update);
PreparedStatement ups = conn.prepareStatement(update);
try {
ups.setInt( 1, result + 1 );
ups.setInt( 2, result );
rows = ups.executeUpdate();
}
catch (SQLException sqle) {
log.error("could not update hi value in: " + tableName, sqle);
throw sqle;
}
finally {
ups.close();
}
}
while (rows==0);
return new Integer(result);
|
public synchronized java.io.Serializable | generate(org.hibernate.engine.SessionImplementor session, java.lang.Object object)
int result = ( (Integer) doWorkInNewTransaction(session) ).intValue();
return new Integer(result);
|
public java.lang.Object | generatorKey()
return tableName;
|
public java.lang.String[] | sqlCreateStrings(org.hibernate.dialect.Dialect dialect)
return new String[] {
dialect.getCreateTableString() + " " + tableName + " ( " + columnName + " " + dialect.getTypeName(Types.INTEGER) + " )",
"insert into " + tableName + " values ( 0 )"
};
|
public java.lang.String[] | sqlDropStrings(org.hibernate.dialect.Dialect dialect)
StringBuffer sqlDropString = new StringBuffer( "drop table " );
if ( dialect.supportsIfExistsBeforeTableName() ) {
sqlDropString.append( "if exists " );
}
sqlDropString.append( tableName ).append( dialect.getCascadeConstraintsString() );
if ( dialect.supportsIfExistsAfterTableName() ) {
sqlDropString.append( " if exists" );
}
return new String[] { sqlDropString.toString() };
|