use of org.h2.test.db.Db in project h2database by h2database.
the class TestMultiThread method testConcurrentView.
private void testConcurrentView() throws Exception {
if (config.mvcc || config.mvStore) {
return;
}
String db = getTestName();
deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true);
final Random r = new Random();
try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement();
StringBuilder buff = new StringBuilder();
buff.append("create table test(id int");
final int len = 3;
for (int i = 0; i < len; i++) {
buff.append(", x" + i + " int");
}
buff.append(")");
stat.execute(buff.toString());
stat.execute("create view test_view as select * from test");
stat.execute("insert into test(id) select x from system_range(1, 2)");
Task t = new Task() {
@Override
public void call() throws Exception {
Connection c2 = getConnection(url);
while (!stop) {
c2.prepareStatement("select * from test_view where x" + r.nextInt(len) + "=1");
}
c2.close();
}
};
t.execute();
SynchronizedVerifier.setDetect(SmallLRUCache.class, true);
for (int i = 0; i < 1000; i++) {
conn.prepareStatement("select * from test_view where x" + r.nextInt(len) + "=1");
}
t.get();
SynchronizedVerifier.setDetect(SmallLRUCache.class, false);
}
}
use of org.h2.test.db.Db in project narayana by jbosstm.
the class RecoveryTest method directRecoverableConnection.
@Test
@BMRule(name = "throw rmfail xaexception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new javax.transaction.xa.XAException(javax.transaction.xa.XAException.XAER_RMFAIL)", targetLocation = "AT ENTRY")
public void directRecoverableConnection() throws Exception {
// jdbc:arjuna: <path to properties file>, path starting at System.getProperty("user.dir")
String url = TransactionalDriver.arjunaDriver + "ds-direct.properties";
Properties dbProperties = new Properties();
dbProperties.put(TransactionalDriver.dynamicClass, PropertyFileDynamicClass.class.getName());
dbProperties.put(TransactionalDriver.userName, "");
dbProperties.put(TransactionalDriver.password, "");
Properties p = System.getProperties();
p.put("jdbc.drivers", Driver.class.getName());
System.setProperties(p);
transactionalDriver = new TransactionalDriver();
DriverManager.registerDriver(transactionalDriver);
step0_setupTables(url, dbProperties);
// rmfail means the db connection was left to be recovered
step1_leaveXidsInDbTable(url, dbProperties);
step2_checkDbIsNotCommitted(url, dbProperties);
// 3. Perform recovery - checking only top down XARecoveryModule functionality
{
XARecoveryModule xarm = new XARecoveryModule();
RecoveryManager manager = RecoveryManager.manager();
manager.removeAllModules(true);
manager.addModule(xarm);
AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
aarm.periodicWorkFirstPass();
Transformer.disableTriggers(true);
aarm.periodicWorkSecondPass();
Transformer.enableTriggers(true);
}
step4_finalDbCommitCheck(url, dbProperties);
}
use of org.h2.test.db.Db in project syncope by apache.
the class H2StartStopListener method contextInitialized.
@Override
public void contextInitialized(final ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
try {
Server h2TestDb = new Server();
h2TestDb.runTool("-tcp", "-tcpDaemon", "-web", "-webDaemon", "-webPort", ctx.getBean("testdb.webport", String.class));
context.setAttribute(H2_TESTDB, h2TestDb);
} catch (SQLException e) {
LOG.error("Could not start H2 test db", e);
}
DataSource datasource = ctx.getBean(DataSource.class);
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(ctx.getResource("classpath:/testdb.sql"));
populator.setSqlScriptEncoding("UTF-8");
DataSourceInitializer init = new DataSourceInitializer();
init.setDataSource(datasource);
init.setEnabled(true);
init.setDatabasePopulator(populator);
init.afterPropertiesSet();
LOG.info("Database successfully initialized");
}
use of org.h2.test.db.Db in project h2database by h2database.
the class ScriptBase method initStore.
private void initStore() {
Database db = session.getDatabase();
byte[] key = null;
if (cipher != null && password != null) {
char[] pass = password.optimize(session).getValue(session).getString().toCharArray();
key = SHA256.getKeyPasswordHash("script", pass);
}
String file = getFileName();
store = FileStore.open(db, file, "rw", cipher, key);
store.setCheckedWriting(false);
store.init();
}
use of org.h2.test.db.Db in project h2database by h2database.
the class Query method initOrder.
/**
* Initialize the order by list. This call may extend the expressions list.
*
* @param session the session
* @param expressions the select list expressions
* @param expressionSQL the select list SQL snippets
* @param orderList the order by list
* @param visible the number of visible columns in the select list
* @param mustBeInResult all order by expressions must be in the select list
* @param filters the table filters
*/
static void initOrder(Session session, ArrayList<Expression> expressions, ArrayList<String> expressionSQL, ArrayList<SelectOrderBy> orderList, int visible, boolean mustBeInResult, ArrayList<TableFilter> filters) {
Database db = session.getDatabase();
for (SelectOrderBy o : orderList) {
Expression e = o.expression;
if (e == null) {
continue;
}
// special case: SELECT 1 AS A FROM DUAL ORDER BY A
// (oracle supports it, but only in order by, not in group by and
// not in having):
// SELECT 1 AS A FROM DUAL ORDER BY -A
boolean isAlias = false;
int idx = expressions.size();
if (e instanceof ExpressionColumn) {
// order by expression
ExpressionColumn exprCol = (ExpressionColumn) e;
String tableAlias = exprCol.getOriginalTableAliasName();
String col = exprCol.getOriginalColumnName();
for (int j = 0; j < visible; j++) {
boolean found = false;
Expression ec = expressions.get(j);
if (ec instanceof ExpressionColumn) {
// select expression
ExpressionColumn c = (ExpressionColumn) ec;
found = db.equalsIdentifiers(col, c.getColumnName());
if (found && tableAlias != null) {
String ca = c.getOriginalTableAliasName();
if (ca == null) {
found = false;
if (filters != null) {
// select id from test order by test.id
for (TableFilter f : filters) {
if (db.equalsIdentifiers(f.getTableAlias(), tableAlias)) {
found = true;
break;
}
}
}
} else {
found = db.equalsIdentifiers(ca, tableAlias);
}
}
} else if (!(ec instanceof Alias)) {
continue;
} else if (tableAlias == null && db.equalsIdentifiers(col, ec.getAlias())) {
found = true;
} else {
Expression ec2 = ec.getNonAliasExpression();
if (ec2 instanceof ExpressionColumn) {
ExpressionColumn c2 = (ExpressionColumn) ec2;
String ta = exprCol.getSQL();
String tb = c2.getSQL();
String s2 = c2.getColumnName();
found = db.equalsIdentifiers(col, s2);
if (!db.equalsIdentifiers(ta, tb)) {
found = false;
}
}
}
if (found) {
idx = j;
isAlias = true;
break;
}
}
} else {
String s = e.getSQL();
if (expressionSQL != null) {
for (int j = 0, size = expressionSQL.size(); j < size; j++) {
String s2 = expressionSQL.get(j);
if (db.equalsIdentifiers(s2, s)) {
idx = j;
isAlias = true;
break;
}
}
}
}
if (!isAlias) {
if (mustBeInResult) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
}
expressions.add(e);
String sql = e.getSQL();
expressionSQL.add(sql);
}
o.columnIndexExpr = ValueExpression.get(ValueInt.get(idx + 1));
o.expression = expressions.get(idx).getNonAliasExpression();
}
}
Aggregations