Search in sources :

Example 66 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class DropTableConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for DROP TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    TableDescriptor td;
    UUID tableID;
    ConglomerateDescriptor[] cds;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    if ((sd != null) && sd.getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)) {
        // check if this is a temp table before checking data dictionary
        td = lcc.getTableDescriptorForDeclaredGlobalTempTable(tableName);
        if (// td null here means it is not a temporary table. Look for table in physical SESSION schema
        td == null)
            td = dd.getTableDescriptor(tableName, sd, tc);
        if (// td null means tableName is not a temp table and it is not a physical table in SESSION schema
        td == null) {
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
        }
        if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
            dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
            tc.dropConglomerate(td.getHeapConglomerateId());
            lcc.dropDeclaredGlobalTempTable(tableName);
            return;
        }
    }
    /* Lock the table before we access the data dictionary
		 * to prevent deadlocks.
		 *
		 * Note that for DROP TABLE replayed at Targets during REFRESH,
		 * the conglomerateNumber will be 0. That's ok. During REFRESH,
		 * we don't need to lock the conglomerate.
		 */
    if (conglomerateNumber != 0) {
        lockTableForDDL(tc, conglomerateNumber, true);
    }
    /*
		** 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);
    /* Get the table descriptor. */
    td = dd.getTableDescriptor(tableId);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
    }
    /* Get an exclusive table lock on the table. */
    long heapId = td.getHeapConglomerateId();
    lockTableForDDL(tc, heapId, true);
    /* Drop the triggers */
    for (TriggerDescriptor trd : dd.getTriggerDescriptors(td)) {
        trd.drop(lcc);
    }
    /* Drop all defaults */
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (ColumnDescriptor cd : cdl) {
        // 
        if (cd.isAutoincrement() && dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, null)) {
            dropIdentitySequence(dd, td, activation);
        }
        // any dependencies
        if (cd.getDefaultInfo() != null) {
            DefaultDescriptor defaultDesc = cd.getDefaultDescriptor(dd);
            dm.clearDependencies(lcc, defaultDesc);
        }
    }
    /* Drop the columns */
    dd.dropAllColumnDescriptors(tableId, tc);
    /* Drop all table and column permission descriptors */
    dd.dropAllTableAndColPermDescriptors(tableId, tc);
    /* Drop the constraints */
    dropAllConstraintDescriptors(td, activation);
    /*
		** Drop all the conglomerates.  Drop the heap last, because the
		** store needs it for locking the indexes when they are dropped.
		*/
    cds = td.getConglomerateDescriptors();
    long[] dropped = new long[cds.length - 1];
    int numDropped = 0;
    for (int index = 0; index < cds.length; index++) {
        ConglomerateDescriptor cd = cds[index];
        /* if it's for an index, since similar indexes share one
			 * conglomerate, we only drop the conglomerate once
			 */
        if (cd.getConglomerateNumber() != heapId) {
            long thisConglom = cd.getConglomerateNumber();
            int i;
            for (i = 0; i < numDropped; i++) {
                if (dropped[i] == thisConglom)
                    break;
            }
            if (// not dropped
            i == numDropped) {
                dropped[numDropped++] = thisConglom;
                tc.dropConglomerate(thisConglom);
                dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
            }
        }
    }
    /* Prepare all dependents to invalidate.  (This is there chance
		 * to say that they can't be invalidated.  For example, an open
		 * cursor referencing a table/view that the user is attempting to
		 * drop.) If no one objects, then invalidate any dependent objects.
		 * We check for invalidation before we drop the table descriptor
		 * since the table descriptor may be looked up as part of
		 * decoding tuples in SYSDEPENDS.
		 */
    dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
    // 
    // The table itself can depend on the user defined types of its columns.
    // Drop all of those dependencies now.
    // 
    adjustUDTDependencies(lcc, dd, td, null, true);
    /* Drop the table */
    dd.dropTableDescriptor(td, sd, tc);
    /* Drop the conglomerate descriptors */
    dd.dropAllConglomerateDescriptors(td, tc);
    /* Drop the store element at last, to prevent dangling reference
		 * for open cursor, beetle 4393.
		 */
    tc.dropConglomerate(heapId);
}
Also used : ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) UUID(org.apache.derby.catalog.UUID) TransactionController(org.apache.derby.iapi.store.access.TransactionController) DefaultDescriptor(org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)

Example 67 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class RowChangerImpl method openForUpdate.

/**
 *	  Open this RowChanger to avoid fixing indexes that do not change
 *	  during update operations.
 *
 *	  @param fixOnUpdate fixOnUpdat[ix] == true ==&gt; fix index 'ix' on
 *	  an update operation.
 *	  @param lockMode	The lock mode to use
 *							(row or table, see TransactionController)
 *	  @param wait		If true, then the caller wants to wait for locks. False will be
 *							when we using a nested user xaction - we want to timeout right away
 *							if the parent holds the lock.  (bug 4821)
 *
 *	  @exception StandardException thrown on failure to convert
 */
public void openForUpdate(boolean[] fixOnUpdate, int lockMode, boolean wait) throws StandardException {
    LanguageConnectionContext lcc = null;
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(!isOpen, "RowChanger already open");
    if (activation != null) {
        lcc = activation.getLanguageConnectionContext();
    }
    /* Isolation level - translate from language to store */
    int isolationLevel;
    if (lcc == null) {
        isolationLevel = TransactionControl.READ_COMMITTED_ISOLATION_LEVEL;
    } else {
        isolationLevel = lcc.getCurrentIsolationLevel();
    }
    switch(isolationLevel) {
        // Store will overwrite it to READ COMMITTED for update.
        case TransactionControl.READ_UNCOMMITTED_ISOLATION_LEVEL:
            isolationLevel = TransactionController.ISOLATION_READ_UNCOMMITTED;
            break;
        case TransactionControl.READ_COMMITTED_ISOLATION_LEVEL:
            isolationLevel = TransactionController.ISOLATION_READ_COMMITTED;
            break;
        case TransactionControl.REPEATABLE_READ_ISOLATION_LEVEL:
            isolationLevel = TransactionController.ISOLATION_REPEATABLE_READ;
            break;
        case TransactionControl.SERIALIZABLE_ISOLATION_LEVEL:
            isolationLevel = TransactionController.ISOLATION_SERIALIZABLE;
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Invalid isolation level - " + isolationLevel);
            }
    }
    try {
        /* We can get called by either an activation or 
		 * the DataDictionary.  The DD cannot use the
		 * CompiledInfo while the activation can.
		 */
        if (heapSCOCI != null) {
            baseCC = tc.openCompiledConglomerate(false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, isolationLevel, heapSCOCI, heapDCOCI);
        } else {
            baseCC = tc.openConglomerate(heapConglom, false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, isolationLevel);
        }
    } catch (StandardException se) {
        if (activation != null)
            activation.checkStatementValidity();
        throw se;
    }
    /* Save the ConglomerateController off in the activation
		 * to eliminate the need to open it a 2nd time if we are doing
		 * and index to base row for the search as part of an update or
		 * delete below us.
		 * NOTE: activation can be null.  (We don't have it in
		 * the DataDictionary.)
		 */
    if (activation != null) {
        activation.checkStatementValidity();
        activation.setHeapConglomerateController(baseCC);
    }
    /* Only worry about indexes if there are indexes to worry about */
    if (indexCIDS.length != 0) {
        /* IndexSetChanger re-used across executions. */
        if (isc == null) {
            isc = new IndexSetChanger(irgs, indexCIDS, indexSCOCIs, indexDCOCIs, indexNames, baseCC, tc, lockMode, baseRowReadList, isolationLevel, activation);
            isc.setRowHolder(rowHolder);
        } else {
            /* Propagate the heap's ConglomerateController to
				 * all of the underlying index changers.
				 */
            isc.setBaseCC(baseCC);
        }
        isc.open(fixOnUpdate);
        if (baseRowLocation == null)
            baseRowLocation = baseCC.newRowLocationTemplate();
    }
    isOpen = true;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 68 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class SavepointConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for CREATE TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    // Bug 4507 - savepoint not allowed inside trigger
    StatementContext stmtCtxt = lcc.getStatementContext();
    if (stmtCtxt != null && stmtCtxt.inTrigger())
        throw StandardException.newException(SQLState.NO_SAVEPOINT_IN_TRIGGER);
    if (savepointStatementType == 1) {
        // this is set savepoint
        if (// to enforce DB2 restriction which is savepoint name can't start with SYS
        savepointName.startsWith("SYS"))
            throw StandardException.newException(SQLState.INVALID_SCHEMA_SYS, "SYS");
        lcc.languageSetSavePoint(savepointName, savepointName);
    } else if (savepointStatementType == 2) {
        // this is rollback savepoint
        lcc.internalRollbackToSavepoint(savepointName, true, savepointName);
    } else {
        // this is release savepoint
        lcc.releaseSavePoint(savepointName, savepointName);
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 69 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class SetConstraintsConstantAction method executeConstantAction.

/**
 * This is the guts of the execution time logic for SET CONSTRAINT.
 *
 * @param activation
 *
 * @see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    final LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    final DataDictionary dd = lcc.getDataDictionary();
    final List<String> boundConstraints = new ArrayList<String>();
    if (constraints != null) {
        for (TableName c : constraints) {
            final SchemaDescriptor sd = dd.getSchemaDescriptor(c.getSchemaName(), lcc.getTransactionExecute(), true);
            final ConstraintDescriptor cd = dd.getConstraintDescriptor(c.getTableName(), sd.getUUID());
            if (cd == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "CONSTRAINT", c.getFullSQLName());
            }
            final String bound = IdUtil.normalToDelimited(sd.getSchemaName()) + "." + IdUtil.normalToDelimited(cd.getConstraintName());
            if (boundConstraints.contains(bound)) {
                throw StandardException.newException(SQLState.LANG_DB2_DUPLICATE_NAMES, cd.getConstraintName(), bound);
            } else {
                boundConstraints.add(bound);
            }
            if (deferred && !cd.deferrable()) {
                throw StandardException.newException(SQLState.LANG_SET_CONSTRAINT_NOT_DEFERRABLE, cd.getConstraintName());
            }
            lcc.setConstraintDeferred(activation, cd, deferred);
        }
    } else {
        lcc.setDeferredAll(activation, deferred);
    }
}
Also used : TableName(org.apache.derby.impl.sql.compile.TableName) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ArrayList(java.util.ArrayList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 70 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class RawStore method backup.

/*
	 * Backup the database.
	 * Online backup copies all the database files (log, seg0  ...Etc) to the
	 * specified backup location without blocking any user operation for the 
	 * duration of the backup. Stable copy is made of each page using 
     * page level latches and in some cases with the help of monitors.  
     * Transaction log is also backed up, this is used to bring the database to 
     * the consistent state on restore.
	 * 
     * <P> MT- only one thread  is allowed to perform backup at any given time. 
     *  Synchronized on this. Parallel backups are not supported. 
	 */
public synchronized void backup(Transaction t, File backupDir) throws StandardException {
    if (!privExists(backupDir)) {
        // if backup dir does not exist, go ahead and create it.
        createBackupDirectory(backupDir);
    } else {
        if (!privIsDirectory(backupDir)) {
            throw StandardException.newException(SQLState.RAWSTORE_CANNOT_BACKUP_TO_NONDIRECTORY, (File) backupDir);
        }
        if (privExists(new File(backupDir, PersistentService.PROPERTIES_NAME))) {
            throw StandardException.newException(SQLState.RAWSTORE_CANNOT_BACKUP_INTO_DATABASE_DIRECTORY, (File) backupDir);
        }
    }
    boolean error = true;
    boolean renamed = false;
    boolean renameFailed = false;
    File oldbackup = null;
    File backupcopy = null;
    OutputStreamWriter historyFile = null;
    StorageFile dbHistoryFile = null;
    File backupHistoryFile = null;
    LogInstant backupInstant = logFactory.getFirstUnflushedInstant();
    try {
        // get name of the current db, ie. database directory of current db.
        StorageFile dbase = storageFactory.newStorageFile(null);
        String canonicalDbName = storageFactory.getCanonicalName();
        String dbname = StringUtil.shortDBName(canonicalDbName, storageFactory.getSeparator());
        // append to end of history file
        historyFile = privFileWriter(storageFactory.newStorageFile(BACKUP_HISTORY), true);
        backupcopy = new File(backupDir, dbname);
        logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_STARTED, canonicalDbName, getFilePath(backupcopy)));
        // check if a backup copy of this database already exists,
        if (privExists(backupcopy)) {
            // first make a backup of the backup
            oldbackup = new File(backupDir, dbname + ".OLD");
            if (privExists(oldbackup)) {
                if (privIsDirectory(oldbackup))
                    privRemoveDirectory(oldbackup);
                else
                    privDelete(oldbackup);
            }
            if (!privRenameTo(backupcopy, oldbackup)) {
                renameFailed = true;
                throw StandardException.newException(SQLState.RAWSTORE_ERROR_RENAMING_FILE, backupcopy, oldbackup);
            } else {
                logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_MOVED_BACKUP, getFilePath(backupcopy), getFilePath(oldbackup)));
                renamed = true;
            }
        }
        // create the backup database directory
        createBackupDirectory(backupcopy);
        dbHistoryFile = storageFactory.newStorageFile(BACKUP_HISTORY);
        backupHistoryFile = new File(backupcopy, BACKUP_HISTORY);
        // copy the history file into the backup.
        if (!privCopyFile(dbHistoryFile, backupHistoryFile))
            throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, dbHistoryFile, backupHistoryFile);
        // if they are any jar file stored in the database, copy them into
        // the backup.
        StorageFile jarDir = storageFactory.newStorageFile(FileResource.JAR_DIRECTORY_NAME);
        if (privExists(jarDir)) {
            // find the list of schema directories under the jar dir and
            // then copy only the plain files under those directories. One
            // could just use the recursive copy of directory to copy all
            // the files under the jar dir, but the problem with that is if
            // a user gives jar directory as the backup path by mistake,
            // copy will fail while copying the backup dir onto itself in
            // recursion
            String[] jarDirContents = privList(jarDir);
            File backupJarDir = new File(backupcopy, FileResource.JAR_DIRECTORY_NAME);
            // Create the backup jar directory
            createBackupDirectory(backupJarDir);
            LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
            // DERBY-5357 UUIDs introduced in jar file names in 10.9
            boolean uuidSupported = lcc.getDataDictionary().checkVersion(DataDictionary.DD_VERSION_DERBY_10_9, null);
            if (uuidSupported) {
                // no subdirectories
                for (int i = 0; i < jarDirContents.length; i++) {
                    StorageFile jar = storageFactory.newStorageFile(jarDir, jarDirContents[i]);
                    File backupJar = new File(backupJarDir, jarDirContents[i]);
                    if (privIsDirectory(new File(jar.getPath()))) {
                        // We no longer expect directories inside
                        continue;
                    // 'jar'. Need check to make the weird
                    // test #2 in BackupPathTests.java work:
                    // it does a backup of the db into its
                    // own(!) jar file directory, so trying
                    // to copy that db file into itself two
                    // levels down would fail.
                    }
                    if (!privCopyFile(jar, backupJar)) {
                        throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, jar, backupJar);
                    }
                }
            } else {
                for (int i = 0; i < jarDirContents.length; i++) {
                    StorageFile jarSchemaDir = storageFactory.newStorageFile(jarDir, jarDirContents[i]);
                    File backupJarSchemaDir = new File(backupJarDir, jarDirContents[i]);
                    if (!privCopyDirectory(jarSchemaDir, backupJarSchemaDir, (byte[]) null, null, false)) {
                        throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, jarSchemaDir, backupJarSchemaDir);
                    }
                }
            }
        }
        // save service properties into the backup, Read in property
        // from service.properties file, remove logDevice from it,
        // then write it to the backup.
        StorageFile logdir = logFactory.getLogDirectory();
        try {
            String name = getServiceName(this);
            PersistentService ps = getMonitor().getServiceType(this);
            String fullName = ps.getCanonicalServiceName(name);
            Properties prop = ps.getServiceProperties(fullName, (Properties) null);
            StorageFile defaultLogDir = storageFactory.newStorageFile(LogFactory.LOG_DIRECTORY_NAME);
            if (!logdir.equals(defaultLogDir)) {
                prop.remove(Attribute.LOG_DEVICE);
                if (SanityManager.DEBUG) {
                    SanityManager.ASSERT(prop.getProperty(Attribute.LOG_DEVICE) == null, "cannot get rid of logDevice property");
                }
                logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_EDITED_SERVICEPROPS));
            }
            // save the service properties into the backup.
            ps.saveServiceProperties(backupcopy.getPath(), prop);
        } catch (StandardException se) {
            logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_ERROR_EDIT_SERVICEPROPS) + se);
            // skip the rest and let finally block clean up
            return;
        }
        // Incase of encrypted database and the key is an external
        // encryption key, there is an extra file with name
        // Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE, this file should be
        // copied in to the backup.
        StorageFile verifyKeyFile = storageFactory.newStorageFile(Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
        if (privExists(verifyKeyFile)) {
            File backupVerifyKeyFile = new File(backupcopy, Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
            if (!privCopyFile(verifyKeyFile, backupVerifyKeyFile))
                throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, verifyKeyFile, backupVerifyKeyFile);
        }
        File logBackup = new File(backupcopy, LogFactory.LOG_DIRECTORY_NAME);
        // this is wierd, delete it
        if (privExists(logBackup)) {
            privRemoveDirectory(logBackup);
        }
        // Create the log directory
        createBackupDirectory(logBackup);
        // do a checkpoint to get the persistent store up to date.
        logFactory.checkpoint(this, dataFactory, xactFactory, true);
        // start the transaction log  backup.
        logFactory.startLogBackup(logBackup);
        File segBackup = new File(backupcopy, "seg0");
        // Create the data segment directory
        createBackupDirectory(segBackup);
        // backup all the information in the data segment.
        dataFactory.backupDataFiles(t, segBackup);
        logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_DATA_SEG_BACKUP_COMPLETED, getFilePath(segBackup)));
        // copy the log that got generated after the backup started to
        // backup location and tell the logfactory that backup has come
        // to end.
        logFactory.endLogBackup(logBackup);
        logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_COPIED_LOG, getFilePath(logdir), getFilePath(logBackup)));
        error = false;
    } catch (IOException ioe) {
        throw StandardException.newException(SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe);
    } finally {
        try {
            if (error) {
                // Abort all activity related to backup in the log factory.
                logFactory.abortLogBackup();
                // not an half backed one.
                if (!renameFailed)
                    privRemoveDirectory(backupcopy);
                if (renamed)
                    // recover the old backup
                    privRenameTo(oldbackup, backupcopy);
                logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_ABORTED));
            } else {
                // success, remove the old backup copy
                if (renamed && privExists(oldbackup)) {
                    // get rid of the old backup
                    privRemoveDirectory(oldbackup);
                    logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_REMOVED_BACKUP, getFilePath(oldbackup)));
                }
                logHistory(historyFile, MessageService.getTextMessage(MessageId.STORE_BACKUP_COMPLETED, backupInstant));
                // backup information into the backup.
                if (!privCopyFile(dbHistoryFile, backupHistoryFile))
                    throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE, dbHistoryFile, backupHistoryFile);
            }
            historyFile.close();
        } catch (IOException ioe) {
            try {
                historyFile.close();
            } catch (IOException ioe2) {
            }
            ;
            throw StandardException.newException(SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe);
        }
    }
}
Also used : LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant) IOException(java.io.IOException) UpdateServiceProperties(org.apache.derby.impl.services.monitor.UpdateServiceProperties) Properties(java.util.Properties) StandardException(org.apache.derby.shared.common.error.StandardException) PersistentService(org.apache.derby.iapi.services.monitor.PersistentService) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) StorageFile(org.apache.derby.io.StorageFile) OutputStreamWriter(java.io.OutputStreamWriter) StorageFile(org.apache.derby.io.StorageFile) File(java.io.File)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4