use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class CreateConstraintConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for CREATE CONSTRAINT.
* <P>
* A constraint is represented as:
* <UL>
* <LI> ConstraintDescriptor.
* </UL>
* If a backing index is required then the index will
* be created through an CreateIndexConstantAction setup
* by the compiler.
* <BR>
* Dependencies are created as:
* <UL>
* <LI> ConstraintDescriptor depends on all the providers collected
* at compile time and passed into the constructor.
* <LI> For a FOREIGN KEY constraint ConstraintDescriptor depends
* on the ConstraintDescriptor for the referenced constraints
* and the privileges required to create the constraint.
* </UL>
*
* @see ConstraintDescriptor
* @see CreateIndexConstantAction
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
ConglomerateDescriptor conglomDesc = null;
ConglomerateDescriptor[] conglomDescs = null;
ConstraintDescriptor conDesc = null;
TableDescriptor td = null;
UUID indexId = null;
String uniqueName;
String backingIndexName;
/* RESOLVE - blow off not null constraints for now (and probably for ever) */
if (constraintType == DataDictionary.NOTNULL_CONSTRAINT) {
return;
}
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
cf = lcc.getLanguageConnectionFactory().getClassFactory();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
/* Table gets locked in AlterTableConstantAction */
/*
** If the schema descriptor is null, then
** we must have just read ourselves in.
** So we will get the corresponding schema
** descriptor from the data dictionary.
*/
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
/* Try to get the TableDescriptor from
* the Activation. We will go to the
* DD if not there. (It should always be
* there except when in a target.)
*/
td = activation.getDDLTableDescriptor();
if (td == null) {
/* tableId will be non-null if adding a
* constraint to an existing table.
*/
if (tableId != null) {
td = dd.getTableDescriptor(tableId);
} else {
td = dd.getTableDescriptor(tableName, sd, tc);
}
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
activation.setDDLTableDescriptor(td);
}
/* Generate the UUID for the backing index. This will become the
* constraint's name, if no name was specified.
*/
UUIDFactory uuidFactory = dd.getUUIDFactory();
UUID constrId = uuidFactory.createUUID();
/* Create the index, if there's one for this constraint */
if (indexAction != null) {
if (indexAction.getIndexName() == null) {
/* Set the index name */
backingIndexName = uuidFactory.createUUID().toString();
indexAction.setIndexName(backingIndexName);
} else {
backingIndexName = indexAction.getIndexName();
}
indexAction.setConstraintID(constrId);
/* Create the index */
indexAction.executeConstantAction(activation);
/* Get the conglomerate descriptor for the backing index */
conglomDescs = td.getConglomerateDescriptors();
for (int index = 0; index < conglomDescs.length; index++) {
conglomDesc = conglomDescs[index];
/* Check for conglomerate being an index first, since
* name is null for heap.
*/
if (conglomDesc.isIndex() && backingIndexName.equals(conglomDesc.getConglomerateName())) {
break;
}
}
if (SanityManager.DEBUG) {
SanityManager.ASSERT(conglomDesc != null, "conglomDesc is expected to be non-null after search for backing index");
SanityManager.ASSERT(conglomDesc.isIndex(), "conglomDesc is expected to be indexable after search for backing index");
SanityManager.ASSERT(conglomDesc.getConglomerateName().equals(backingIndexName), "conglomDesc name expected to be the same as backing index name after search for backing index");
}
indexId = conglomDesc.getUUID();
}
boolean[] defaults = new boolean[] { ConstraintDefinitionNode.DEFERRABLE_DEFAULT, ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT, ConstraintDefinitionNode.ENFORCED_DEFAULT };
for (int i = 0; i < characteristics.length; i++) {
if (characteristics[i] != defaults[i]) {
dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, "DEFERRED CONSTRAINTS");
if (constraintType == DataDictionary.NOTNULL_CONSTRAINT || !characteristics[2]) /* not enforced */
{
// Remove when feature DERBY-532 is completed
if (!PropertyUtil.getSystemProperty("derby.constraintsTesting", "false").equals("true")) {
throw StandardException.newException(SQLState.NOT_IMPLEMENTED, "non-default constraint characteristics");
}
}
}
}
/* Now, lets create the constraint descriptor */
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
switch(constraintType) {
case DataDictionary.PRIMARYKEY_CONSTRAINT:
conDesc = ddg.newPrimaryKeyConstraintDescriptor(td, constraintName, // deferable,
characteristics[0], // initiallyDeferred,
characteristics[1], // int[],
genColumnPositions(td, false), constrId, indexId, sd, characteristics[2], // referenceCount
0);
dd.addConstraintDescriptor(conDesc, tc);
break;
case DataDictionary.UNIQUE_CONSTRAINT:
conDesc = ddg.newUniqueConstraintDescriptor(td, constraintName, // deferable,
characteristics[0], // initiallyDeferred,
characteristics[1], // int[],
genColumnPositions(td, false), constrId, indexId, sd, characteristics[2], // referenceCount
0);
dd.addConstraintDescriptor(conDesc, tc);
break;
case DataDictionary.CHECK_CONSTRAINT:
conDesc = ddg.newCheckConstraintDescriptor(td, constraintName, // deferable,
characteristics[0], // initiallyDeferred,
characteristics[1], constrId, constraintText, // int[],
new ReferencedColumnsDescriptorImpl(genColumnPositions(td, false)), sd, characteristics[2]);
dd.addConstraintDescriptor(conDesc, tc);
storeConstraintDependenciesOnPrivileges(activation, conDesc, null, providerInfo);
break;
case DataDictionary.FOREIGNKEY_CONSTRAINT:
ReferencedKeyConstraintDescriptor referencedConstraint = DDUtils.locateReferencedConstraint(dd, td, constraintName, columnNames, otherConstraintInfo);
DDUtils.validateReferentialActions(dd, td, constraintName, otherConstraintInfo, columnNames);
conDesc = ddg.newForeignKeyConstraintDescriptor(td, constraintName, // deferable,
characteristics[0], // initiallyDeferred,
characteristics[1], // int[],
genColumnPositions(td, false), constrId, indexId, sd, referencedConstraint, characteristics[2], otherConstraintInfo.getReferentialActionDeleteRule(), otherConstraintInfo.getReferentialActionUpdateRule());
// try to create the constraint first, because it
// is expensive to do the bulk check, find obvious
// errors first
dd.addConstraintDescriptor(conDesc, tc);
/* No need to do check if we're creating a
* table.
*/
if ((!forCreateTable) && dd.activeConstraint(conDesc)) {
validateFKConstraint(activation, tc, dd, (ForeignKeyConstraintDescriptor) conDesc, referencedConstraint, ((CreateIndexConstantAction) indexAction).getIndexTemplateRow());
}
/* Create stored dependency on the referenced constraint */
dm.addDependency(conDesc, referencedConstraint, lcc.getContextManager());
// store constraint's dependency on REFERENCES privileges in the dependeny system
storeConstraintDependenciesOnPrivileges(activation, conDesc, referencedConstraint.getTableId(), providerInfo);
break;
case DataDictionary.MODIFY_CONSTRAINT:
throw StandardException.newException(SQLState.NOT_IMPLEMENTED, "ALTER CONSTRAINT");
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("contraintType (" + constraintType + ") has unexpected value");
}
break;
}
/* Create stored dependencies for each provider */
if (providerInfo != null) {
for (int ix = 0; ix < providerInfo.length; ix++) {
Provider provider = null;
/* We should always be able to find the Provider */
provider = (Provider) providerInfo[ix].getDependableFinder().getDependable(dd, providerInfo[ix].getObjectId());
dm.addDependency(conDesc, provider, lcc.getContextManager());
}
}
/* Finally, invalidate off of the table descriptor(s)
* to ensure that any dependent statements get
* re-compiled.
*/
if (!forCreateTable) {
dm.invalidateFor(td, DependencyManager.CREATE_CONSTRAINT, lcc);
}
if (constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT) {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(conDesc != null, "conDesc expected to be non-null");
if (!(conDesc instanceof ForeignKeyConstraintDescriptor)) {
SanityManager.THROWASSERT("conDesc expected to be instance of ForeignKeyConstraintDescriptor, not " + conDesc.getClass().getName());
}
}
dm.invalidateFor(((ForeignKeyConstraintDescriptor) conDesc).getReferencedConstraint().getTableDescriptor(), DependencyManager.CREATE_CONSTRAINT, lcc);
}
this.constraintId = constrId;
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class B2IFactory 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);
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class ExternalSortFactory 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 sort's format.
formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
// See if there's a new maximum sort buffer size.
defaultSortBufferMax = PropertyUtil.getSystemInt("derby.storage.sortBufferMax", 0, Integer.MAX_VALUE, 0);
// do not override it.
if (defaultSortBufferMax == 0) {
userSpecified = false;
defaultSortBufferMax = DEFAULT_SORTBUFFERMAX;
} else {
userSpecified = true;
if (defaultSortBufferMax < MINIMUM_SORTBUFFERMAX)
defaultSortBufferMax = MINIMUM_SORTBUFFERMAX;
}
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class BaseActivation method initFromContext.
public final void initFromContext(Context context) throws StandardException {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(context != null, "NULL context passed to BaseActivation.initFromContext");
}
this.cm = context.getContextManager();
lcc = (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID);
if (SanityManager.DEBUG) {
if (lcc == null)
SanityManager.THROWASSERT("lcc is null in activation type " + getClass());
}
// mark in use
inUse = true;
// add this activation to the pool for the connection.
lcc.addActivation(this);
isValid = true;
/* Get the UUID for this activation */
UUIDFactory uuidFactory = getMonitor().getUUIDFactory();
UUIDValue = uuidFactory.createUUID();
UUIDString = UUIDValue.toString();
}
use of org.apache.derby.iapi.services.uuid.UUIDFactory in project derby by apache.
the class BaseDataFileFactory method boot.
public void boot(boolean create, Properties startParams) throws StandardException {
jbmsVersion = getMonitor().getEngineVersion();
jvmVersion = buildJvmVersion();
osInfo = buildOSinfo();
jarCPath = jarClassPath(getClass());
dataDirectory = startParams.getProperty(PersistentService.ROOT);
UUIDFactory uf = getMonitor().getUUIDFactory();
identifier = uf.createUUID();
PersistentService ps = getMonitor().getServiceType(this);
try {
storageFactory = ps.getStorageFactoryInstance(true, dataDirectory, startParams.getProperty(Property.STORAGE_TEMP_DIRECTORY, PropertyUtil.getSystemProperty(Property.STORAGE_TEMP_DIRECTORY)), identifier.toANSIidentifier());
} catch (IOException ioe) {
if (create) {
throw StandardException.newException(SQLState.SERVICE_DIRECTORY_CREATE_ERROR, ioe, dataDirectory);
} else {
throw StandardException.newException(SQLState.DATABASE_NOT_FOUND, ioe, dataDirectory);
}
}
// you can't encrypt a database if the Lucene plugin is loaded
if (luceneLoaded()) {
String encryptionProp = startParams.getProperty(Attribute.DATA_ENCRYPTION);
if ((encryptionProp != null) && "TRUE".equals(encryptionProp.toUpperCase())) {
throw StandardException.newException(SQLState.LUCENE_ENCRYPTED_DB);
}
}
if (storageFactory instanceof WritableStorageFactory)
writableStorageFactory = (WritableStorageFactory) storageFactory;
actionCode = BOOT_ACTION;
try {
AccessController.doPrivileged(this);
} catch (PrivilegedActionException pae) {
// BOOT_ACTION does not throw any exceptions.
}
String value = startParams.getProperty(Property.FORCE_DATABASE_LOCK, PropertyUtil.getSystemProperty(Property.FORCE_DATABASE_LOCK));
throwDBlckException = Boolean.valueOf((value != null ? value.trim() : value)).booleanValue();
if (// read only db, not interested in filelock
!isReadOnly())
getJBMSLockOnDB(identifier, uf, dataDirectory);
// If the database is being restored/created from backup
// the restore the data directory(seg*) from backup
String restoreFrom = null;
restoreFrom = startParams.getProperty(Attribute.CREATE_FROM);
if (restoreFrom == null)
restoreFrom = startParams.getProperty(Attribute.RESTORE_FROM);
if (restoreFrom == null)
restoreFrom = startParams.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM);
if (restoreFrom != null) {
try {
// restoreFrom and createFrom operations also need to know if database
// is encrypted
String dataEncryption = startParams.getProperty(Attribute.DATA_ENCRYPTION);
databaseEncrypted = Boolean.valueOf(dataEncryption).booleanValue();
restoreDataDirectory(restoreFrom);
} catch (StandardException se) {
releaseJBMSLockOnDB();
throw se;
}
}
logMsg(LINE);
String messageID = (isReadOnly()) ? MessageId.STORE_BOOT_MSG_READ_ONLY : MessageId.STORE_BOOT_MSG;
boolean logBootTrace = Boolean.valueOf(startParams.getProperty(Property.LOG_BOOT_TRACE, PropertyUtil.getSystemProperty(Property.LOG_BOOT_TRACE))).booleanValue();
logMsg(new Date() + MessageService.getTextMessage(messageID, jbmsVersion, identifier, dataDirectory, // cast to Object so we get object hash code
(Object) this.getClass().getClassLoader(), jarCPath));
// Log the JVM version info
logMsg(jvmVersion);
// Log the OS info
logMsg(osInfo);
// Log derby.system.home It will have null value if user didn't set it
logMsg(Property.SYSTEM_HOME_PROPERTY + "=" + PropertyUtil.getSystemProperty(Property.SYSTEM_HOME_PROPERTY));
// Log properties related to redirection of derby.log
String target = PropertyUtil.getSystemProperty(Property.ERRORLOG_STYLE_PROPERTY);
if (target != null)
logMsg(Property.ERRORLOG_STYLE_PROPERTY + "=" + target);
target = PropertyUtil.getSystemProperty(Property.ERRORLOG_FILE_PROPERTY);
if (target != null)
logMsg(Property.ERRORLOG_FILE_PROPERTY + "=" + target);
target = PropertyUtil.getSystemProperty(Property.ERRORLOG_METHOD_PROPERTY);
if (target != null)
logMsg(Property.ERRORLOG_METHOD_PROPERTY + "=" + target);
target = PropertyUtil.getSystemProperty(Property.ERRORLOG_FIELD_PROPERTY);
if (target != null)
logMsg(Property.ERRORLOG_FIELD_PROPERTY + "=" + target);
if (logBootTrace)
Monitor.logThrowable(new Throwable("boot trace"));
uf = null;
CacheFactory cf = (CacheFactory) startSystemModule(org.apache.derby.shared.common.reference.Module.CacheFactory);
// Initialize the page cache
int pageCacheSize = getIntParameter(RawStoreFactory.PAGE_CACHE_SIZE_PARAMETER, null, RawStoreFactory.PAGE_CACHE_SIZE_DEFAULT, RawStoreFactory.PAGE_CACHE_SIZE_MINIMUM, RawStoreFactory.PAGE_CACHE_SIZE_MAXIMUM);
pageCache = cf.newCacheManager(this, "PageCache", pageCacheSize / 2, pageCacheSize);
// Initialize the container cache
int fileCacheSize = getIntParameter(RawStoreFactory.CONTAINER_CACHE_SIZE_PARAMETER, null, RawStoreFactory.CONTAINER_CACHE_SIZE_DEFAULT, RawStoreFactory.CONTAINER_CACHE_SIZE_MINIMUM, RawStoreFactory.CONTAINER_CACHE_SIZE_MAXIMUM);
containerCache = cf.newCacheManager(this, "ContainerCache", fileCacheSize / 2, fileCacheSize);
// Register MBeans that allow users to monitor the page cache
// and the container cache.
pageCache.registerMBean(dataDirectory);
containerCache.registerMBean(dataDirectory);
if (create) {
String noLog = startParams.getProperty(Property.CREATE_WITH_NO_LOG);
inCreateNoLog = (noLog != null && Boolean.valueOf(noLog).booleanValue());
}
droppedTableStubInfo = new Hashtable<LogInstant, Object[]>();
// writes during checkpoint
if (Property.DURABILITY_TESTMODE_NO_SYNC.equalsIgnoreCase(PropertyUtil.getSystemProperty(Property.DURABILITY_PROPERTY))) {
// - disable syncing of data during checkpoint.
dataNotSyncedAtCheckpoint = true;
// log message stating that derby.system.durability
// is set to a mode, where syncs wont be forced and the
// possible consequences of setting this mode
Monitor.logMessage(MessageService.getTextMessage(MessageId.STORE_DURABILITY_TESTMODE_NO_SYNC, Property.DURABILITY_PROPERTY, Property.DURABILITY_TESTMODE_NO_SYNC));
} else if (Performance.MEASURE) {
// development build only feature, must by hand set the
// Performance.MEASURE variable and rebuild. Useful during
// development to compare/contrast effect of syncing, release
// users can use the above relaxed durability option to disable
// all syncing.
// debug only flag - disable syncing of data during checkpoint.
dataNotSyncedAtCheckpoint = PropertyUtil.getSystemBoolean(Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT);
if (dataNotSyncedAtCheckpoint)
Monitor.logMessage("Warning: " + Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT + "set to true.");
}
fileHandler = new RFResource(this);
}
Aggregations