use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class SYSCOLUMNSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a ColumnDescriptor out of a SYSCOLUMNS row
*
* @param row a SYSCOLUMNS row
* @param parentTupleDescriptor The UniqueTupleDescriptor for the object that is tied
* to this column
* @param dd dataDictionary
*
* @return a column descriptor equivalent to a SYSCOLUMNS row
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
if (SanityManager.DEBUG) {
int expectedCols = dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_14, null) ? SYSCOLUMNS_COLUMN_COUNT : (SYSCOLUMNS_COLUMN_COUNT - 1);
SanityManager.ASSERT(row.nColumns() == expectedCols, "Wrong number of columns for a SYSCOLUMNS row");
}
int columnNumber;
String columnName;
String defaultID;
DefaultInfoImpl defaultInfo = null;
ColumnDescriptor colDesc;
DataValueDescriptor defaultValue = null;
UUID defaultUUID = null;
UUID uuid = null;
UUIDFactory uuidFactory = getUUIDFactory();
long autoincStart, autoincInc, autoincValue;
boolean autoincCycle = false;
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
/*
** We're going to be getting the UUID for this sucka
** so make sure it is a UniqueTupleDescriptor.
*/
if (parentTupleDescriptor != null) {
if (SanityManager.DEBUG) {
if (!(parentTupleDescriptor instanceof UniqueTupleDescriptor)) {
SanityManager.THROWASSERT(parentTupleDescriptor.getClass().getName() + " not instanceof UniqueTupleDescriptor");
}
}
uuid = ((UniqueTupleDescriptor) parentTupleDescriptor).getUUID();
} else {
/* 1st column is REFERENCEID (char(36)) */
uuid = uuidFactory.recreateUUID(row.getColumn(SYSCOLUMNS_REFERENCEID).getString());
}
/* NOTE: We get columns 5 and 6 next in order to work around
* a 1.3.0 HotSpot bug. (#4361550)
*/
// 5th column is COLUMNDEFAULT (serialiazable)
Object object = row.getColumn(SYSCOLUMNS_COLUMNDEFAULT).getObject();
if (object instanceof DataValueDescriptor) {
defaultValue = (DataValueDescriptor) object;
} else if (object instanceof DefaultInfoImpl) {
defaultInfo = (DefaultInfoImpl) object;
defaultValue = defaultInfo.getDefaultValue();
}
/* 6th column is DEFAULTID (char(36)) */
defaultID = row.getColumn(SYSCOLUMNS_COLUMNDEFAULTID).getString();
if (defaultID != null) {
defaultUUID = uuidFactory.recreateUUID(defaultID);
}
/* 2nd column is COLUMNNAME (varchar(128)) */
columnName = row.getColumn(SYSCOLUMNS_COLUMNNAME).getString();
/* 3rd column is COLUMNNUMBER (int) */
columnNumber = row.getColumn(SYSCOLUMNS_COLUMNNUMBER).getInt();
/* 4th column is COLUMNDATATYPE */
/*
** What is stored in the column is a TypeDescriptorImpl, which
** points to a BaseTypeIdImpl. These are simple types that are
** intended to be movable to the client, so they don't have
** the entire implementation. We need to wrap them in DataTypeServices
** and TypeId objects that contain the full implementations for
** language processing.
*/
TypeDescriptor catalogType = (TypeDescriptor) row.getColumn(SYSCOLUMNS_COLUMNDATATYPE).getObject();
DataTypeDescriptor dataTypeServices = DataTypeDescriptor.getType(catalogType);
/* 7th column is AUTOINCREMENTVALUE (long) */
autoincValue = row.getColumn(SYSCOLUMNS_AUTOINCREMENTVALUE).getLong();
/* 8th column is AUTOINCREMENTSTART (long) */
autoincStart = row.getColumn(SYSCOLUMNS_AUTOINCREMENTSTART).getLong();
/* 9th column is AUTOINCREMENTINC (long) */
autoincInc = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINC).getLong();
if (row.nColumns() >= 10) {
DataValueDescriptor col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE);
autoincCycle = col.getBoolean();
}
DataValueDescriptor col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTSTART);
autoincStart = col.getLong();
col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINC);
autoincInc = col.getLong();
// Hard upgraded tables <=10.13 come with a false autoincCyle before they are first
// explicitly set with cycle or no cycle command.
colDesc = new ColumnDescriptor(columnName, columnNumber, dataTypeServices, defaultValue, defaultInfo, uuid, defaultUUID, autoincStart, autoincInc, autoincValue, autoincCycle);
return colDesc;
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class IndexStatisticsDaemonImpl method writeUpdatedStats.
/**
* Writes updated statistics for the specified index to the data dictionary.
*
* @param lcc connection context to use to perform the work
* @param td the base table
* @param index the index of the base table
* @param numRows number of rows in the base table
* @param cardinality the number of unique values in the index (per number
* of leading columns)
* @param asBackgroundTask whether the update is done automatically as
* part of a background task or if explicitly invoked by the user
* @throws StandardException if updating the data dictionary fails
*/
private void writeUpdatedStats(LanguageConnectionContext lcc, TableDescriptor td, UUID index, long numRows, long[] cardinality, boolean asBackgroundTask) throws StandardException {
TransactionController tc = lcc.getTransactionExecute();
trace(1, "writing new stats (xid=" + tc.getTransactionIdString() + ")");
UUID table = td.getUUID();
DataDictionary dd = lcc.getDataDictionary();
UUIDFactory uf = dd.getUUIDFactory();
// Update the heap row count estimate.
setHeapRowEstimate(tc, td.getHeapConglomerateId(), numRows);
// Drop existing index statistics for this index.
if (!lcc.dataDictionaryInWriteMode()) {
dd.startWriting(lcc);
}
dd.dropStatisticsDescriptors(table, index, tc);
// invalidation control flag
boolean conglomerateGone = false;
// Don't write statistics if the table is empty.
if (numRows == 0) {
trace(2, "empty table, no stats written");
} else {
// Construct and add the statistics entries.
for (int i = 0; i < cardinality.length; i++) {
StatisticsDescriptor statDesc = new StatisticsDescriptor(dd, uf.createUUID(), index, table, "I", new StatisticsImpl(numRows, cardinality[i]), i + 1);
dd.addDescriptor(statDesc, null, DataDictionary.SYSSTATISTICS_CATALOG_NUM, true, tc);
}
// Log some information.
ConglomerateDescriptor cd = dd.getConglomerateDescriptor(index);
log(asBackgroundTask, td, "wrote stats for index " + (cd == null ? "n/a" : cd.getDescriptorName()) + " (" + index + "): rows=" + numRows + ", card=" + cardToStr(cardinality));
// for non-existent indexes in SYSSTATISTICS.
if (asBackgroundTask && cd == null) {
log(asBackgroundTask, td, "rolled back index stats because index has been dropped");
lcc.internalRollback();
}
conglomerateGone = (cd == null);
}
if (!conglomerateGone) {
// Invalidate statments accessing the given table.
invalidateStatements(lcc, td, asBackgroundTask);
}
// Only commit tx as we go if running as background task.
if (asBackgroundTask) {
lcc.internalCommit(true);
}
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class HeapConglomerateFactory method boot.
public void boot(boolean create, Properties startParams) throws StandardException {
// Find the UUID factory.
UUIDFactory uuidFactory = getMonitor().getUUIDFactory();
// Make a UUID that identifies this conglomerate's format.
formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
}
Aggregations