FileDocCategorySizeDatePackage
SequenceStructure.javaAPI DocHibernate 3.2.52848Thu Mar 15 04:33:16 GMT 2007org.hibernate.id.enhanced

SequenceStructure

public class SequenceStructure extends Object implements DatabaseStructure
Describes a sequence.
author
Steve Ebersole

Fields Summary
private static final Log
log
private final String
sequenceName
private final int
initialValue
private final int
incrementSize
private final String
sql
private boolean
applyIncrementSizeToSourceValues
private int
accessCounter
Constructors Summary
public SequenceStructure(org.hibernate.dialect.Dialect dialect, String sequenceName, int initialValue, int incrementSize)


	         
		this.sequenceName = sequenceName;
		this.initialValue = initialValue;
		this.incrementSize = incrementSize;
		sql = dialect.getSequenceNextValString( sequenceName );
	
Methods Summary
public AccessCallbackbuildCallback(org.hibernate.engine.SessionImplementor session)

		return new AccessCallback() {
			public long getNextValue() {
				accessCounter++;
				try {
					PreparedStatement st = session.getBatcher().prepareSelectStatement( sql );
					try {
						ResultSet rs = st.executeQuery();
						try {
							rs.next();
							long result = rs.getLong( 1 );
							if ( log.isDebugEnabled() ) {
								log.debug("Sequence identifier generated: " + result);
							}
							return result;
						}
						finally {
							try {
								rs.close();
							}
							catch( Throwable ignore ) {
								// intentionally empty
							}
						}
					}
					finally {
						session.getBatcher().closeStatement( st );
					}

				}
				catch ( SQLException sqle) {
					throw JDBCExceptionHelper.convert(
							session.getFactory().getSQLExceptionConverter(),
							sqle,
							"could not get next sequence value",
							sql
					);
				}
			}
		};
	
public intgetIncrementSize()

		return incrementSize;
	
public java.lang.StringgetName()

		return sequenceName;
	
public intgetTimesAccessed()

		return accessCounter;
	
public voidprepare(Optimizer optimizer)

		applyIncrementSizeToSourceValues = optimizer.applyIncrementSizeToSourceValues();
	
public java.lang.String[]sqlCreateStrings(org.hibernate.dialect.Dialect dialect)

		int sourceIncrementSize = applyIncrementSizeToSourceValues ? incrementSize : 1;
		return dialect.getCreateSequenceStrings( sequenceName, initialValue, sourceIncrementSize );
	
public java.lang.String[]sqlDropStrings(org.hibernate.dialect.Dialect dialect)

		return dialect.getDropSequenceStrings( sequenceName );