Search in sources :

Example 1 with AutoincrementCounter

use of org.apache.derby.impl.sql.execute.AutoincrementCounter in project derby by apache.

the class GenericLanguageConnectionContext method autoincrementCreateCounter.

/**
 * @see LanguageConnectionContext#autoincrementCreateCounter
 */
public void autoincrementCreateCounter(String s, String t, String c, Long initialValue, long increment, int position) {
    String key = AutoincrementCounter.makeIdentity(s, t, c);
    if (autoincrementCacheHashtable == null) {
        autoincrementCacheHashtable = new HashMap<String, AutoincrementCounter>();
    }
    AutoincrementCounter aic = autoincrementCacheHashtable.get(key);
    if (aic != null) {
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("Autoincrement Counter already exists:" + key);
        }
        return;
    }
    aic = new AutoincrementCounter(initialValue, increment, 0, s, t, c, position);
    autoincrementCacheHashtable.put(key, aic);
}
Also used : AutoincrementCounter(org.apache.derby.impl.sql.execute.AutoincrementCounter)

Example 2 with AutoincrementCounter

use of org.apache.derby.impl.sql.execute.AutoincrementCounter in project derby by apache.

the class GenericLanguageConnectionContext method autoincrementFlushCache.

/**
 * Flush the cache of autoincrement values being kept by the lcc.
 * This will result in the autoincrement values being written to the
 * SYSCOLUMNS table as well as the mapping used by lastAutoincrementValue
 *
 * @exception StandardException thrown on error.
 * @see LanguageConnectionContext#lastAutoincrementValue
 * @see GenericLanguageConnectionContext#lastAutoincrementValue
 */
public void autoincrementFlushCache(UUID tableUUID) throws StandardException {
    if (autoincrementCacheHashtable == null)
        return;
    if (autoincrementHT == null)
        autoincrementHT = new HashMap<String, Long>();
    DataDictionary dd = getDataDictionary();
    for (Iterator<String> it = autoincrementCacheHashtable.keySet().iterator(); it.hasNext(); ) {
        String key = it.next();
        AutoincrementCounter aic = autoincrementCacheHashtable.get(key);
        Long value = aic.getCurrentValue();
        aic.flushToDisk(getTransactionExecute(), dd, tableUUID);
        if (value != null) {
            autoincrementHT.put(key, value);
        }
    }
    autoincrementCacheHashtable.clear();
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) AutoincrementCounter(org.apache.derby.impl.sql.execute.AutoincrementCounter)

Example 3 with AutoincrementCounter

use of org.apache.derby.impl.sql.execute.AutoincrementCounter in project derby by apache.

the class GenericLanguageConnectionContext method nextAutoincrementValue.

/**
 * returns the <b>next</b> value to be inserted into an autoincrement col.
 * This is used internally by the system to generate autoincrement values
 * which are going to be inserted into a autoincrement column. This is
 * used when as autoincrement column is added to a table by an alter
 * table statemenet and during bulk insert.
 *
 * @param schemaName
 * @param tableName
 * @param columnName identify the column uniquely in the system.
 */
public long nextAutoincrementValue(String schemaName, String tableName, String columnName) throws StandardException {
    String key = AutoincrementCounter.makeIdentity(schemaName, tableName, columnName);
    AutoincrementCounter aic = autoincrementCacheHashtable.get(key);
    if (aic == null) {
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("counter doesn't exist:" + key);
        }
        return 0;
    } else {
        return aic.update();
    }
}
Also used : AutoincrementCounter(org.apache.derby.impl.sql.execute.AutoincrementCounter)

Aggregations

AutoincrementCounter (org.apache.derby.impl.sql.execute.AutoincrementCounter)3 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 WeakHashMap (java.util.WeakHashMap)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1