use of org.h2.command.ddl.DropTable in project ignite by apache.
the class IgniteH2Indexing method unregisterCache.
/**
* {@inheritDoc}
*/
@Override
public void unregisterCache(GridCacheContext cctx, boolean rmvIdx) {
rowCache.onCacheUnregistered(cctx);
String cacheName = cctx.name();
String schemaName = schema(cacheName);
H2Schema schema = schemas.get(schemaName);
if (schema != null) {
mapQryExec.onCacheStop(cacheName);
dmlProc.onCacheStop(cacheName);
// 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.cache().name(), cacheName)) {
try {
tbl.table().setRemoveIndexOnDestroy(rmvIdx);
dropTable(tbl);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
}
schema.drop(tbl);
rmvTbls.add(tbl);
}
}
if (!isDefaultSchema(schemaName)) {
synchronized (schemaMux) {
if (schema.decrementUsageCount() == 0) {
schemas.remove(schemaName);
try {
dropSchema(schemaName);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
}
}
}
}
stmtCache.clear();
for (H2TableDescriptor tbl : rmvTbls) {
for (Index idx : tbl.table().getIndexes()) idx.close(null);
}
int cacheId = CU.cacheId(cacheName);
for (Iterator<Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery>> it = twoStepCache.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery> e = it.next();
GridCacheTwoStepQuery qry = e.getValue().query();
if (!F.isEmpty(qry.cacheIds()) && qry.cacheIds().contains(cacheId))
it.remove();
}
}
}
use of org.h2.command.ddl.DropTable in project nifi by apache.
the class DBCPServiceTest method createInsertSelectDrop.
protected void createInsertSelectDrop(Connection con) throws SQLException {
final Statement st = con.createStatement();
try {
st.executeUpdate(dropTable);
} catch (final Exception e) {
// table may not exist, this is not serious problem.
}
st.executeUpdate(createTable);
st.executeUpdate("insert into restaurants values (1, 'Irifunes', 'San Mateo')");
st.executeUpdate("insert into restaurants values (2, 'Estradas', 'Daly City')");
st.executeUpdate("insert into restaurants values (3, 'Prime Rib House', 'San Francisco')");
int nrOfRows = 0;
final ResultSet resultSet = st.executeQuery("select * from restaurants");
while (resultSet.next()) nrOfRows++;
assertEquals(3, nrOfRows);
st.close();
}
use of org.h2.command.ddl.DropTable in project ignite by apache.
the class GridSqlQueryParser method parseDropTable.
/**
* Parse {@code DROP TABLE} statement.
*
* @param dropTbl {@code DROP TABLE} statement.
* @see <a href="http://h2database.com/html/grammar.html#drop_table">H2 {@code DROP TABLE} spec.</a>
*/
private GridSqlDropTable parseDropTable(DropTable dropTbl) {
GridSqlDropTable res = new GridSqlDropTable();
Schema schema = SCHEMA_COMMAND_SCHEMA.get(dropTbl);
res.schemaName(schema.getName());
res.ifExists(DROP_TABLE_IF_EXISTS.get(dropTbl));
res.tableName(DROP_TABLE_NAME.get(dropTbl));
return res;
}
use of org.h2.command.ddl.DropTable in project ignite by apache.
the class IgniteH2Indexing method unregisterCache.
/** {@inheritDoc} */
@Override
public void unregisterCache(String cacheName) {
String schemaName = schema(cacheName);
boolean dflt = isDefaultSchema(schemaName);
H2Schema schema = dflt ? schemas.get(schemaName) : schemas.remove(schemaName);
if (schema != null) {
mapQryExec.onCacheStop(cacheName);
dmlProc.onCacheStop(cacheName);
// 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.cache().name(), cacheName)) {
try {
dropTable(tbl);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
}
schema.drop(tbl);
rmvTbls.add(tbl);
}
}
if (!dflt) {
try {
dropSchema(schemaName);
} catch (IgniteCheckedException 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);
}
int cacheId = CU.cacheId(cacheName);
for (Iterator<Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery>> it = twoStepCache.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery> e = it.next();
GridCacheTwoStepQuery qry = e.getValue().query();
if (!F.isEmpty(qry.cacheIds()) && qry.cacheIds().contains(cacheId))
it.remove();
}
}
}
use of org.h2.command.ddl.DropTable in project ignite by apache.
the class IgniteH2Indexing method dropTable.
/**
* Drops table form h2 database and clear all related indexes (h2 text, lucene).
*
* @param tbl Table to unregister.
* @throws IgniteCheckedException If failed to unregister.
*/
private void dropTable(H2TableDescriptor tbl) throws IgniteCheckedException {
assert tbl != null;
if (log.isDebugEnabled())
log.debug("Removing query index table: " + tbl.fullTableName());
Connection c = connectionForThread(tbl.schemaName());
Statement stmt = null;
try {
stmt = c.createStatement();
String sql = "DROP TABLE IF EXISTS " + tbl.fullTableName();
if (log.isDebugEnabled())
log.debug("Dropping database index table with SQL: " + sql);
stmt.executeUpdate(sql);
} catch (SQLException e) {
onSqlException();
throw new IgniteSQLException("Failed to drop database index table [type=" + tbl.type().name() + ", table=" + tbl.fullTableName() + "]", IgniteQueryErrorCode.TABLE_DROP_FAILED, e);
} finally {
U.close(stmt, log);
}
}
Aggregations