FileDocCategorySizeDatePackage
SequenceGenerator.javaAPI DocHibernate 3.2.53421Mon Mar 27 10:47:06 BST 2006org.hibernate.id

SequenceGenerator

public class SequenceGenerator extends Object implements PersistentIdentifierGenerator, Configurable
sequence

Generates long values using an oracle-style sequence. A higher performance algorithm is SequenceHiLoGenerator.

Mapping parameters supported: sequence, parameters.
see
SequenceHiLoGenerator
see
TableHiLoGenerator
author
Gavin King

Fields Summary
public static final String
SEQUENCE
The sequence parameter
public static final String
PARAMETERS
The parameters parameter, appended to the create sequence DDL. For example (Oracle): INCREMENT BY 1 START WITH 1 MAXVALUE 100 NOCACHE.
private String
sequenceName
private String
parameters
private org.hibernate.type.Type
identifierType
private String
sql
private static final Log
log
Constructors Summary
Methods Summary
public voidconfigure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.dialect.Dialect dialect)


	          
		sequenceName = PropertiesHelper.getString(SEQUENCE, params, "hibernate_sequence");
		parameters = params.getProperty(PARAMETERS);
		String schemaName = params.getProperty(SCHEMA);
		String catalogName = params.getProperty(CATALOG);

		if (sequenceName.indexOf( '." ) < 0) {
			sequenceName = Table.qualify( catalogName, schemaName, sequenceName );
		}

		this.identifierType = type;
		sql = dialect.getSequenceNextValString(sequenceName);
	
public java.io.Serializablegenerate(org.hibernate.engine.SessionImplementor session, java.lang.Object obj)

		
		try {

			PreparedStatement st = session.getBatcher().prepareSelectStatement(sql);
			try {
				ResultSet rs = st.executeQuery();
				try {
					rs.next();
					Serializable result = IdentifierGeneratorFactory.get(
							rs, identifierType
						);
					if ( log.isDebugEnabled() ) {
						log.debug("Sequence identifier generated: " + result);
					}
					return result;
				}
				finally {
					rs.close();
				}
			}
			finally {
				session.getBatcher().closeStatement(st);
			}
			
		}
		catch (SQLException sqle) {
			throw JDBCExceptionHelper.convert(
					session.getFactory().getSQLExceptionConverter(),
					sqle,
					"could not get next sequence value",
					sql
				);
		}

	
public java.lang.ObjectgeneratorKey()

		return sequenceName;
	
public java.lang.StringgetSequenceName()

		return sequenceName;
	
public java.lang.String[]sqlCreateStrings(org.hibernate.dialect.Dialect dialect)

		String[] ddl = dialect.getCreateSequenceStrings(sequenceName);
		if ( parameters != null ) {
			ddl[ddl.length - 1] += ' " + parameters;
		}
		return ddl;
	
public java.lang.String[]sqlDropStrings(org.hibernate.dialect.Dialect dialect)

		return dialect.getDropSequenceStrings(sequenceName);