use of org.h2.command.dml.Call in project ignite by apache.
the class GridH2AbstractKeyValueRow method syncValue.
/**
* @param waitTime Time to await for value unswap.
* @return Synchronized value.
*/
protected synchronized Value syncValue(long waitTime) {
Value v = peekValue(VAL_COL);
while (v == null && waitTime > 0) {
// This call must be quite rare, so performance is not a concern.
long start = System.nanoTime();
try {
// Wait for value arrival to allow other threads to make a progress.
wait(waitTime);
} catch (InterruptedException e) {
throw new IgniteInterruptedException(e);
}
long t = System.nanoTime() - start;
if (t > 0)
waitTime -= TimeUnit.NANOSECONDS.toMillis(t);
v = peekValue(VAL_COL);
}
return v;
}
use of org.h2.command.dml.Call in project frostwire by frostwire.
the class FullTextLucene2 method getIndexPath.
/**
* Get the path of the Lucene index for this database.
*
* @param conn the database connection
* @return the path
*/
protected static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
rs.next();
String path = rs.getString(1);
if (path == null) {
throw throwException("Fulltext search for in-memory databases is not supported.");
}
int index = path.lastIndexOf(':');
// position 1 means a windows drive letter is used, ignore that
if (index > 1) {
path = path.substring(index + 1);
}
rs.close();
return path;
}
use of org.h2.command.dml.Call in project ignite by apache.
the class IgniteH2Indexing method querySqlFields.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "StringEquality", "unchecked" })
@Override
public List<FieldsQueryCursor<List<?>>> querySqlFields(String schemaName, SqlFieldsQuery qry, @Nullable SqlClientContext cliCtx, boolean keepBinary, boolean failOnMultipleStmts, GridQueryCancel cancel) {
List<FieldsQueryCursor<List<?>>> res = tryQueryDistributedSqlFieldsNative(schemaName, qry.getSql(), cliCtx);
if (res != null)
return res;
{
// First, let's check if we already have a two-step query for this statement...
H2TwoStepCachedQueryKey cachedQryKey = new H2TwoStepCachedQueryKey(schemaName, qry.getSql(), qry.isCollocated(), qry.isDistributedJoins(), qry.isEnforceJoinOrder(), qry.isLocal());
H2TwoStepCachedQuery cachedQry;
if ((cachedQry = twoStepCache.get(cachedQryKey)) != null) {
checkQueryType(qry, true);
GridCacheTwoStepQuery twoStepQry = cachedQry.query().copy();
List<GridQueryFieldMetadata> meta = cachedQry.meta();
res = Collections.singletonList(doRunDistributedQuery(schemaName, qry, twoStepQry, meta, keepBinary, cancel));
if (!twoStepQry.explain())
twoStepCache.putIfAbsent(cachedQryKey, new H2TwoStepCachedQuery(meta, twoStepQry.copy()));
return res;
}
}
{
// Second, let's check if we already have a parsed statement...
PreparedStatement cachedStmt;
if ((cachedStmt = cachedStatement(connectionForSchema(schemaName), qry.getSql())) != null) {
Prepared prepared = GridSqlQueryParser.prepared(cachedStmt);
// We may use this cached statement only for local queries and non queries.
if (qry.isLocal() || !prepared.isQuery())
return (List<FieldsQueryCursor<List<?>>>) doRunPrepared(schemaName, prepared, qry, null, null, keepBinary, cancel);
}
}
res = new ArrayList<>(1);
int firstArg = 0;
String remainingSql = qry.getSql();
while (remainingSql != null) {
ParsingResult parseRes = parseAndSplit(schemaName, remainingSql != qry.getSql() ? cloneFieldsQuery(qry).setSql(remainingSql) : qry, firstArg);
// Let's avoid second reflection getter call by returning Prepared object too
Prepared prepared = parseRes.prepared();
GridCacheTwoStepQuery twoStepQry = parseRes.twoStepQuery();
List<GridQueryFieldMetadata> meta = parseRes.meta();
SqlFieldsQuery newQry = parseRes.newQuery();
remainingSql = parseRes.remainingSql();
if (remainingSql != null && failOnMultipleStmts)
throw new IgniteSQLException("Multiple statements queries are not supported");
firstArg += prepared.getParameters().size();
res.addAll(doRunPrepared(schemaName, prepared, newQry, twoStepQry, meta, keepBinary, cancel));
if (parseRes.twoStepQuery() != null && parseRes.twoStepQueryKey() != null && !parseRes.twoStepQuery().explain())
twoStepCache.putIfAbsent(parseRes.twoStepQueryKey(), new H2TwoStepCachedQuery(meta, twoStepQry.copy()));
}
return res;
}
use of org.h2.command.dml.Call in project ignite by apache.
the class GridH2Table method removeChildrenAndResources.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void removeChildrenAndResources(Session ses) {
lock(true);
try {
super.removeChildrenAndResources(ses);
// Clear all user indexes registered in schema.
while (idxs.size() > sysIdxsCnt) {
Index idx = idxs.get(sysIdxsCnt);
if (idx.getName() != null && idx.getSchema().findIndex(ses, idx.getName()) == idx) {
// This call implicitly removes both idx and its proxy, if any, from idxs.
database.removeSchemaObject(ses, idx);
// We have to call destroy here if we are who has removed this index from the table.
if (idx instanceof GridH2IndexBase)
((GridH2IndexBase) idx).destroy(rmIndex);
}
}
if (SysProperties.CHECK) {
for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) {
Index idx = (Index) obj;
if (idx.getTable() == this)
DbException.throwInternalError("index not dropped: " + idx.getName());
}
}
database.removeMeta(ses, getId());
invalidate();
} finally {
unlock(true);
}
}
use of org.h2.command.dml.Call in project ignite by apache.
the class H2DynamicTableSelfTest method testIndexNameConflictCheckDiscovery.
/**
* Tests index name conflict check in discovery thread.
* @throws Exception if failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexNameConflictCheckDiscovery() throws Exception {
execute(grid(0), "CREATE TABLE \"Person\" (id int primary key, name varchar)");
execute(grid(0), "CREATE INDEX \"idx\" ON \"Person\" (\"name\")");
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
QueryEntity e = new QueryEntity();
e.setTableName("City");
e.setKeyFields(Collections.singleton("name"));
e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName())));
e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx")));
e.setKeyType("CityKey");
e.setValueType("City");
queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false);
return null;
}
}, SchemaOperationException.class, "Index already exists: idx");
}
Aggregations