Search in sources :

Example 6 with DropTable

use of org.h2.command.ddl.DropTable in project h2database by h2database.

the class Parser method parseDrop.

private Prepared parseDrop() {
    if (readIf("TABLE")) {
        boolean ifExists = readIfExists(false);
        String tableName = readIdentifierWithSchema();
        DropTable command = new DropTable(session, getSchema());
        command.setTableName(tableName);
        while (readIf(",")) {
            tableName = readIdentifierWithSchema();
            DropTable next = new DropTable(session, getSchema());
            next.setTableName(tableName);
            command.addNextDropTable(next);
        }
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        if (readIf("CASCADE")) {
            command.setDropAction(ConstraintActionType.CASCADE);
            readIf("CONSTRAINTS");
        } else if (readIf("RESTRICT")) {
            command.setDropAction(ConstraintActionType.RESTRICT);
        } else if (readIf("IGNORE")) {
            command.setDropAction(ConstraintActionType.SET_DEFAULT);
        }
        return command;
    } else if (readIf("INDEX")) {
        boolean ifExists = readIfExists(false);
        String indexName = readIdentifierWithSchema();
        DropIndex command = new DropIndex(session, getSchema());
        command.setIndexName(indexName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        // Support for MySQL: DROP INDEX index_name ON tbl_name
        if (readIf("ON")) {
            readIdentifierWithSchema();
        }
        return command;
    } else if (readIf("USER")) {
        boolean ifExists = readIfExists(false);
        DropUser command = new DropUser(session);
        command.setUserName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        readIf("CASCADE");
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("SEQUENCE")) {
        boolean ifExists = readIfExists(false);
        String sequenceName = readIdentifierWithSchema();
        DropSequence command = new DropSequence(session, getSchema());
        command.setSequenceName(sequenceName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("CONSTANT")) {
        boolean ifExists = readIfExists(false);
        String constantName = readIdentifierWithSchema();
        DropConstant command = new DropConstant(session, getSchema());
        command.setConstantName(constantName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("TRIGGER")) {
        boolean ifExists = readIfExists(false);
        String triggerName = readIdentifierWithSchema();
        DropTrigger command = new DropTrigger(session, getSchema());
        command.setTriggerName(triggerName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("VIEW")) {
        boolean ifExists = readIfExists(false);
        String viewName = readIdentifierWithSchema();
        DropView command = new DropView(session, getSchema());
        command.setViewName(viewName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        ConstraintActionType dropAction = parseCascadeOrRestrict();
        if (dropAction != null) {
            command.setDropAction(dropAction);
        }
        return command;
    } else if (readIf("ROLE")) {
        boolean ifExists = readIfExists(false);
        DropRole command = new DropRole(session);
        command.setRoleName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("ALIAS")) {
        boolean ifExists = readIfExists(false);
        String aliasName = readIdentifierWithSchema();
        DropFunctionAlias command = new DropFunctionAlias(session, getSchema());
        command.setAliasName(aliasName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("SCHEMA")) {
        boolean ifExists = readIfExists(false);
        DropSchema command = new DropSchema(session);
        command.setSchemaName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        if (readIf("CASCADE")) {
            command.setDropAction(ConstraintActionType.CASCADE);
        } else if (readIf("RESTRICT")) {
            command.setDropAction(ConstraintActionType.RESTRICT);
        }
        return command;
    } else if (readIf("ALL")) {
        read("OBJECTS");
        DropDatabase command = new DropDatabase(session);
        command.setDropAllObjects(true);
        if (readIf("DELETE")) {
            read("FILES");
            command.setDeleteFiles(true);
        }
        return command;
    } else if (readIf("DOMAIN")) {
        return parseDropUserDataType();
    } else if (readIf("TYPE")) {
        return parseDropUserDataType();
    } else if (readIf("DATATYPE")) {
        return parseDropUserDataType();
    } else if (readIf("AGGREGATE")) {
        return parseDropAggregate();
    } else if (readIf("SYNONYM")) {
        boolean ifExists = readIfExists(false);
        String synonymName = readIdentifierWithSchema();
        DropSynonym command = new DropSynonym(session, getSchema());
        command.setSynonymName(synonymName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    }
    throw getSyntaxError();
}
Also used : DropConstant(org.h2.command.ddl.DropConstant) DropTrigger(org.h2.command.ddl.DropTrigger) DropView(org.h2.command.ddl.DropView) DropUser(org.h2.command.ddl.DropUser) DropSynonym(org.h2.command.ddl.DropSynonym) DropSequence(org.h2.command.ddl.DropSequence) ValueString(org.h2.value.ValueString) DropTable(org.h2.command.ddl.DropTable) DropSchema(org.h2.command.ddl.DropSchema) DropRole(org.h2.command.ddl.DropRole) DropFunctionAlias(org.h2.command.ddl.DropFunctionAlias) DropDatabase(org.h2.command.ddl.DropDatabase) ConstraintActionType(org.h2.constraint.ConstraintActionType) DropIndex(org.h2.command.ddl.DropIndex)

Example 7 with DropTable

use of org.h2.command.ddl.DropTable in project h2database by h2database.

the class ResultTempTable method dropTable.

private void dropTable() {
    if (table == null) {
        return;
    }
    if (containsLob) {
        // otherwise the BLOB and CLOB entries are removed
        return;
    }
    try {
        Database database = session.getDatabase();
        // notably via the close() paths.
        synchronized (session) {
            synchronized (database) {
                table.truncate(session);
            }
        }
        // time. (the table is truncated, so this is just one record)
        if (!database.isSysTableLocked()) {
            Session sysSession = database.getSystemSession();
            table.removeChildrenAndResources(sysSession);
            if (index != null) {
                // need to explicitly do this,
                // as it's not registered in the system session
                session.removeLocalTempTableIndex(index);
            }
            // TODO this synchronization cascade is very ugly
            synchronized (session) {
                synchronized (sysSession) {
                    synchronized (database) {
                        sysSession.commit(false);
                    }
                }
            }
        }
    } finally {
        table = null;
    }
}
Also used : Database(org.h2.engine.Database) Session(org.h2.engine.Session)

Example 8 with DropTable

use of org.h2.command.ddl.DropTable in project ignite by apache.

the class SchemaManager method onCacheDestroyed.

/**
 * Handle cache destroy.
 *
 * @param cacheName Cache name.
 * @param rmvIdx Whether to remove indexes.
 */
public void onCacheDestroyed(String cacheName, boolean rmvIdx) {
    String schemaName = schemaName(cacheName);
    H2Schema schema = schemas.get(schemaName);
    // Remove this mapping only after callback to DML proc - it needs that mapping internally
    cacheName2schema.remove(cacheName);
    // Drop tables.
    Collection<H2TableDescriptor> rmvTbls = new HashSet<>();
    for (H2TableDescriptor tbl : schema.tables()) {
        if (F.eq(tbl.cacheName(), cacheName)) {
            try {
                tbl.table().setRemoveIndexOnDestroy(rmvIdx);
                dropTable(tbl, rmvIdx);
            } catch (Exception e) {
                U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
            }
            schema.drop(tbl);
            rmvTbls.add(tbl);
            GridH2Table h2Tbl = tbl.table();
            dataTables.remove(h2Tbl.identifier(), h2Tbl);
        }
    }
    synchronized (schemaMux) {
        if (schema.decrementUsageCount()) {
            schemas.remove(schemaName);
            try {
                dropSchema(schemaName);
            } catch (Exception e) {
                U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
            }
        }
    }
    for (H2TableDescriptor tbl : rmvTbls) {
        for (Index idx : tbl.table().getIndexes()) idx.close(null);
    }
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Index(org.h2.index.Index) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Aggregations

SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)3 Index (org.h2.index.Index)3 Statement (java.sql.Statement)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 GridCacheTwoStepQuery (org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)2 GridBoundedConcurrentLinkedHashMap (org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)2 MalformedURLException (java.net.MalformedURLException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 IgniteException (org.apache.ignite.IgniteException)1 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)1