FileDocCategorySizeDatePackage
QuerySequence.javaAPI DocGlassfish v2 API12142Tue May 22 16:54:52 BST 2007oracle.toplink.essentials.sequencing

QuerySequence

public class QuerySequence extends StandardSequence

Purpose: An abstract class adding queries to StandardSequence

Fields Summary
protected ValueReadQuery
selectQuery
protected DataModifyQuery
updateQuery
protected boolean
shouldAcquireValueAfterInsert
protected boolean
shouldUseTransaction
protected boolean
shouldSkipUpdate
protected boolean
shouldSelectBeforeUpdate
protected boolean
wasSelectQueryCreated
protected boolean
wasUpdateQueryCreated
Constructors Summary
public QuerySequence()

        super();
    
public QuerySequence(String name)

        super(name);
    
public QuerySequence(String name, int size)

        super(name, size);
    
public QuerySequence(String name, int size, int initialValue)

        super(name, size, initialValue);
    
public QuerySequence(boolean shouldAcquireValueAfterInsert, boolean shouldUseTransaction)

        super();
        setShouldAcquireValueAfterInsert(shouldAcquireValueAfterInsert);
        setShouldUseTransaction(shouldUseTransaction);
    
public QuerySequence(String name, boolean shouldAcquireValueAfterInsert, boolean shouldUseTransaction)

        super(name);
        setShouldAcquireValueAfterInsert(shouldAcquireValueAfterInsert);
        setShouldUseTransaction(shouldUseTransaction);
    
public QuerySequence(String name, int size, boolean shouldAcquireValueAfterInsert, boolean shouldUseTransaction)

        super(name, size);
        setShouldAcquireValueAfterInsert(shouldAcquireValueAfterInsert);
        setShouldUseTransaction(shouldUseTransaction);
    
public QuerySequence(String name, int size, int initialValue, boolean shouldAcquireValueAfterInsert, boolean shouldUseTransaction)

        super(name, size, initialValue);
        setShouldAcquireValueAfterInsert(shouldAcquireValueAfterInsert);
        setShouldUseTransaction(shouldUseTransaction);
    
Methods Summary
protected oracle.toplink.essentials.queryframework.ValueReadQuerybuildSelectQuery()
INTERNAL:

        return null;
    
protected oracle.toplink.essentials.queryframework.ValueReadQuerybuildSelectQuery(java.lang.String seqName, java.lang.Integer size)
INTERNAL:

        return null;
    
protected oracle.toplink.essentials.queryframework.DataModifyQuerybuildUpdateQuery()
INTERNAL:

        return null;
    
protected oracle.toplink.essentials.queryframework.DataModifyQuerybuildUpdateQuery(java.lang.String seqName, java.lang.Number sizeOrNewValue)
INTERNAL:

        return null;
    
protected java.util.VectorcreateArguments(oracle.toplink.essentials.queryframework.DatabaseQuery query, java.lang.String seqName, java.lang.Number sizeOrNewValue)
INTERNAL:

        int nArgs = query.getArguments().size();
        if (nArgs > 0) {
            Vector args = new Vector(nArgs);
            args.addElement(seqName);
            if (nArgs > 1) {
                args.addElement(sizeOrNewValue);
            }
            return args;
        } else {
            return null;
        }
    
public booleanequals(java.lang.Object obj)

        if (obj instanceof QuerySequence && super.equals(obj)) {
            QuerySequence other = (QuerySequence)obj;
            return (getSelectQuery() == other.getSelectQuery()) && (getUpdateQuery() == other.getUpdateQuery()) && (shouldAcquireValueAfterInsert() == other.shouldAcquireValueAfterInsert()) && (shouldUseTransaction() == other.shouldUseTransaction()) && (shouldSkipUpdate() == other.shouldSkipUpdate()) && (shouldSelectBeforeUpdate() == other.shouldSelectBeforeUpdate());

        } else {
            return false;
        }
    
public oracle.toplink.essentials.queryframework.ValueReadQuerygetSelectQuery()
PUBLIC:

        return selectQuery;
    
public oracle.toplink.essentials.queryframework.DataModifyQuerygetUpdateQuery()
PUBLIC:

        return updateQuery;
    
public voidonConnect()
INTERNAL:

        super.onConnect();
        if (getSelectQuery() == null) {
            setSelectQuery(buildSelectQuery());
            wasSelectQueryCreated = getSelectQuery() != null;
        }
        if ((getUpdateQuery() == null) && !shouldSkipUpdate()) {
            setUpdateQuery(buildUpdateQuery());
            wasUpdateQueryCreated = getUpdateQuery() != null;
        }
    
public voidonDisconnect()
INTERNAL:

        if (wasSelectQueryCreated) {
            setSelectQuery(null);
            wasSelectQueryCreated = false;
        }
        if (wasUpdateQueryCreated) {
            setUpdateQuery(null);
            wasUpdateQueryCreated = false;
        }
        super.onDisconnect();
    
protected java.lang.Objectselect(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, java.lang.Integer size)
INTERNAL:

        ValueReadQuery query = getSelectQuery();
        if (query != null) {
            if (accessor != null) {
                // PERF: Prepare the query before being cloned.
                // Also BUG: SQLCall could not be prepared concurrently by different queries.
                // Setting user define allow custom SQL query to be prepared without translation row.
                query.setIsUserDefined(true);
                query.checkPrepare(writeSession, null);
                query = (ValueReadQuery)query.clone();
                query.setAccessor(accessor);
            }
        } else {
            query = buildSelectQuery(seqName, size);
            if (accessor != null) {
                query.setAccessor(accessor);
            }
        }
        Vector args = createArguments(query, seqName, size);
        if (args != null) {
            return writeSession.executeQuery(query, args);
        } else {
            return writeSession.executeQuery(query);
        }
    
public voidsetSelectQuery(oracle.toplink.essentials.queryframework.ValueReadQuery query)
PUBLIC:

        selectQuery = query;
    
public voidsetShouldAcquireValueAfterInsert(boolean shouldAcquireValueAfterInsert)
PUBLIC:

        this.shouldAcquireValueAfterInsert = shouldAcquireValueAfterInsert;
    
public voidsetShouldSelectBeforeUpdate(boolean shouldSelectBeforeUpdate)
PUBLIC:

        this.shouldSelectBeforeUpdate = shouldSelectBeforeUpdate;
    
public voidsetShouldSkipUpdate(boolean shouldSkipUpdate)
PUBLIC:

        this.shouldSkipUpdate = shouldSkipUpdate;
    
public voidsetShouldUseTransaction(boolean shouldUseTransaction)
PUBLIC:

        this.shouldUseTransaction = shouldUseTransaction;
    
public voidsetUpdateQuery(oracle.toplink.essentials.queryframework.DataModifyQuery query)
PUBLIC:

        updateQuery = query;
    
public booleanshouldAcquireValueAfterInsert()
PUBLIC:

        return shouldAcquireValueAfterInsert;
    
public booleanshouldSelectBeforeUpdate()
PUBLIC:

        return shouldSelectBeforeUpdate;
    
public booleanshouldSkipUpdate()
PUBLIC:

        return shouldSkipUpdate;
    
public booleanshouldUseTransaction()
PUBLIC:

        return shouldUseTransaction;
    
protected voidupdate(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, java.lang.Number sizeOrNewValue)
INTERNAL:

        DataModifyQuery query = getUpdateQuery();
        if (query != null) {
            if (accessor != null) {
                // PERF: Prepare the query before being cloned.
                // Also BUG: SQLCall could not be prepared concurrently by different queries.
                // Setting user define allow custom SQL query to be prepared without translation row.
                query.setIsUserDefined(true);
                query.checkPrepare(writeSession, null);
                query = (DataModifyQuery)query.clone();
                query.setAccessor(accessor);
            }
        } else {
            query = buildUpdateQuery(seqName, sizeOrNewValue);
            if (query == null) {
                return;
            }
            if (accessor != null) {
                query.setAccessor(accessor);
            }
        }
        Vector args = createArguments(query, seqName, sizeOrNewValue);
        if (args != null) {
            writeSession.executeQuery(query, args);
        } else {
            writeSession.executeQuery(query);
        }
    
protected java.lang.NumberupdateAndSelectSequence(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, int size)
INTERNAL:

        Integer sizeInteger = new Integer(size);
        if (shouldSkipUpdate()) {
            return (Number)select(accessor, writeSession, seqName, sizeInteger);
        } else {
            if (shouldSelectBeforeUpdate()) {
                Object result = select(accessor, writeSession, seqName, sizeInteger);
                BigDecimal currentValue;
                if (result instanceof Number) {
                    currentValue = new BigDecimal(((Number)result).longValue());
                } else if (result instanceof String) {
                    currentValue = new BigDecimal((String)result);
                } else if (result instanceof Record) {
                    Object val = ((Record)result).get("text()");
                    currentValue = new BigDecimal((String)val);
                } else {
                    // DatabaseException.errorPreallocatingSequenceNumbers() is thrown by the superclass
                    return null;
                }

                // Increment value
                BigDecimal newValue = currentValue.add(new BigDecimal(size));

                update(accessor, writeSession, seqName, newValue);
                return newValue;
            } else {
                update(accessor, writeSession, seqName, sizeInteger);
                return (Number)select(accessor, writeSession, seqName, sizeInteger);
            }
        }