use of org.h2.table.Table in project aries by apache.
the class AbstractTransactionTest method initTestTable.
protected void initTestTable(String jdbcUrl) throws SQLException {
Driver d = new Driver();
try (Connection c = d.connect(jdbcUrl, null)) {
Statement s = c.createStatement();
try {
s.execute("DROP TABLE TEST_TABLE");
} catch (SQLException sqle) {
}
s.execute("CREATE TABLE TEST_TABLE ( message varchar(255) )");
c.commit();
}
}
use of org.h2.table.Table in project ignite by apache.
the class DmlAstUtils method selectForUpdate.
/**
* Generate SQL SELECT based on UPDATE's WHERE, LIMIT, etc.
*
* @param update Update statement.
* @param keysParamIdx Index of new param for the array of keys.
* @return SELECT statement.
*/
public static GridSqlSelect selectForUpdate(GridSqlUpdate update, @Nullable Integer keysParamIdx) {
GridSqlSelect mapQry = new GridSqlSelect();
mapQry.from(update.target());
Set<GridSqlTable> tbls = new HashSet<>();
collectAllGridTablesInTarget(update.target(), tbls);
assert tbls.size() == 1 : "Failed to determine target table for UPDATE";
GridSqlTable tbl = tbls.iterator().next();
GridH2Table gridTbl = tbl.dataTable();
assert gridTbl != null : "Failed to determine target grid table for UPDATE";
Column h2KeyCol = gridTbl.getColumn(GridH2KeyValueRowOnheap.KEY_COL);
Column h2ValCol = gridTbl.getColumn(GridH2KeyValueRowOnheap.VAL_COL);
GridSqlColumn keyCol = new GridSqlColumn(h2KeyCol, tbl, h2KeyCol.getName());
keyCol.resultType(GridSqlType.fromColumn(h2KeyCol));
GridSqlColumn valCol = new GridSqlColumn(h2ValCol, tbl, h2ValCol.getName());
valCol.resultType(GridSqlType.fromColumn(h2ValCol));
mapQry.addColumn(keyCol, true);
mapQry.addColumn(valCol, true);
for (GridSqlColumn c : update.cols()) {
String newColName = Parser.quoteIdentifier("_upd_" + c.columnName());
// We have to use aliases to cover cases when the user
// wants to update _val field directly (if it's a literal)
GridSqlAlias alias = new GridSqlAlias(newColName, elementOrDefault(update.set().get(c.columnName()), c), true);
alias.resultType(c.resultType());
mapQry.addColumn(alias, true);
}
GridSqlElement where = update.where();
if (keysParamIdx != null)
where = injectKeysFilterParam(where, keyCol, keysParamIdx);
mapQry.where(where);
mapQry.limit(update.limit());
return mapQry;
}
use of org.h2.table.Table in project ignite by apache.
the class H2Utils method createSpatialIndex.
/**
* Create spatial index.
*
* @param tbl Table.
* @param idxName Index name.
* @param cols Columns.
*/
public static GridH2IndexBase createSpatialIndex(GridH2Table tbl, String idxName, IndexColumn[] cols) {
try {
Class<?> cls = Class.forName(SPATIAL_IDX_CLS);
Constructor<?> ctor = cls.getConstructor(GridH2Table.class, String.class, Integer.TYPE, IndexColumn[].class);
if (!ctor.isAccessible())
ctor.setAccessible(true);
final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
return (GridH2IndexBase) ctor.newInstance(tbl, idxName, segments, cols);
} catch (Exception e) {
throw new IgniteException("Failed to instantiate: " + SPATIAL_IDX_CLS, e);
}
}
use of org.h2.table.Table in project ignite by apache.
the class GridH2Table method update.
/**
* Updates table for given key. If value is null then row with given key will be removed from table,
* otherwise value and expiration time will be updated or new row will be added.
*
* @param row Row to be updated.
* @param prevRow Previous row.
* @param prevRowAvailable Whether previous row is available.
* @throws IgniteCheckedException If failed.
*/
public void update(CacheDataRow row, @Nullable CacheDataRow prevRow, boolean prevRowAvailable) throws IgniteCheckedException {
assert desc != null;
GridH2KeyValueRowOnheap row0 = (GridH2KeyValueRowOnheap) desc.createRow(row);
GridH2KeyValueRowOnheap prevRow0 = prevRow != null ? (GridH2KeyValueRowOnheap) desc.createRow(prevRow) : null;
row0.prepareValuesCache();
if (prevRow0 != null)
prevRow0.prepareValuesCache();
try {
lock(false);
try {
ensureNotDestroyed();
boolean replaced;
if (prevRowAvailable)
replaced = pk().putx(row0);
else {
prevRow0 = (GridH2KeyValueRowOnheap) pk().put(row0);
replaced = prevRow0 != null;
}
if (!replaced)
size.increment();
for (int i = pkIndexPos + 1, len = idxs.size(); i < len; i++) {
Index idx = idxs.get(i);
if (idx instanceof GridH2IndexBase)
addToIndex((GridH2IndexBase) idx, row0, prevRow0);
}
if (!tmpIdxs.isEmpty()) {
for (GridH2IndexBase idx : tmpIdxs.values()) addToIndex(idx, row0, prevRow0);
}
} finally {
unlock(false);
}
} finally {
row0.clearValuesCache();
if (prevRow0 != null)
prevRow0.clearValuesCache();
}
}
use of org.h2.table.Table in project ignite by apache.
the class H2DynamicTableSelfTest method testSqlFlagCompatibilityCheck.
/**
* Test that attempting to start a node that has a cache with the name already present in the grid and whose
* SQL flag does not match that of cache with the same name that is already started, yields an error.
* @throws Exception if failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testSqlFlagCompatibilityCheck() throws Exception {
execute("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar, \"name\" varchar, \"surname\" varchar, " + "\"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH \"template=cache\"");
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
String cacheName = cacheName("Person");
Ignition.start(clientConfiguration(5).setCacheConfiguration(new CacheConfiguration(cacheName)));
return null;
}
}, IgniteException.class, "Cache configuration mismatch (local cache was created via Ignite API, while " + "remote cache was created via CREATE TABLE): SQL_PUBLIC_Person");
}
Aggregations