use of org.h2.engine.Session in project siena by mandubian.
the class FullText method parseKey.
/**
* Parse a primary key condition into the primary key columns.
*
* @param conn the database connection
* @param key the primary key condition as a string
* @return an array containing the column name list and the data list
*/
protected static Object[][] parseKey(Connection conn, String key) {
ArrayList<String> columns = New.arrayList();
ArrayList<String> data = New.arrayList();
JdbcConnection c = (JdbcConnection) conn;
Session session = (Session) c.getSession();
Parser p = new Parser(session);
Expression expr = p.parseExpression(key);
addColumnData(columns, data, expr);
Object[] col = new Object[columns.size()];
columns.toArray(col);
Object[] dat = new Object[columns.size()];
data.toArray(dat);
Object[][] columnData = { col, dat };
return columnData;
}
use of org.h2.engine.Session in project ignite by apache.
the class GridH2Table method commitUserIndex.
/**
* Promote temporary index to make it usable in queries.
*
* @param ses H2 session.
* @param idxName Index name.
* @return Temporary index with given name.
*/
private Index commitUserIndex(Session ses, String idxName) {
lock(true);
try {
ensureNotDestroyed();
Index idx = tmpIdxs.remove(idxName);
assert idx != null;
Index cloneIdx = createDuplicateIndexIfNeeded(idx);
ArrayList<Index> newIdxs = new ArrayList<>(idxs.size() + ((cloneIdx == null) ? 1 : 2));
newIdxs.addAll(idxs);
newIdxs.add(idx);
if (cloneIdx != null)
newIdxs.add(cloneIdx);
idxs = newIdxs;
database.addSchemaObject(ses, idx);
if (cloneIdx != null)
database.addSchemaObject(ses, cloneIdx);
setModified();
return idx;
} finally {
unlock(true);
}
}
use of org.h2.engine.Session in project ignite by apache.
the class GridH2Table method removeIndex.
/**
* Remove the given index from the list.
*
* @param h2Idx the index to remove
*/
public void removeIndex(Session session, Index h2Idx) {
lock(true);
try {
ArrayList<Index> idxs = new ArrayList<>(this.idxs);
Index targetIdx = (h2Idx instanceof GridH2ProxyIndex) ? ((GridH2ProxyIndex) h2Idx).underlyingIndex() : h2Idx;
for (int i = pkIndexPos; i < idxs.size(); ) {
Index idx = idxs.get(i);
if (idx == targetIdx || (idx instanceof GridH2ProxyIndex && ((GridH2ProxyIndex) idx).underlyingIndex() == targetIdx)) {
idxs.remove(i);
if (idx instanceof GridH2ProxyIndex && idx.getSchema().findIndex(session, idx.getName()) != null)
database.removeSchemaObject(session, idx);
continue;
}
i++;
}
this.idxs = idxs;
} finally {
unlock(true);
}
}
use of org.h2.engine.Session in project ignite by apache.
the class GridMergeIndex method getRowCount.
/** {@inheritDoc} */
@Override
public long getRowCount(Session ses) {
Cursor c = find(ses, null, null);
long cnt = 0;
while (c.next()) cnt++;
return cnt;
}
use of org.h2.engine.Session in project ignite by apache.
the class IgniteH2Indexing method rebuildIndexesFromHash.
/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
if (tbl == null)
return;
assert tbl.table() != null;
assert tbl.table().rebuildFromHashInProgress();
H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
Cursor cursor = hashIdx.find((Session) null, null, null);
while (cursor.next()) {
CacheDataRow dataRow = (CacheDataRow) cursor.get();
boolean done = false;
while (!done) {
GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
try {
synchronized (entry) {
// TODO : How to correctly get current value and link here?
GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
row.link(dataRow.link());
List<Index> indexes = tbl.table().getAllIndexes();
for (int i = 2; i < indexes.size(); i++) {
Index idx = indexes.get(i);
if (idx instanceof H2TreeIndex)
((H2TreeIndex) idx).put(row);
}
done = true;
}
} catch (GridCacheEntryRemovedException e) {
// No-op
}
}
}
tbl.table().markRebuildFromHashInProgress(false);
}
Aggregations