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);
}
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();
}
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();
}
}
Aggregations