deleteDb("testLinkedTableInReadOnlyDb");
org.h2.Driver.load();
Connection memConn = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
Statement memStat = memConn.createStatement();
memStat.execute("CREATE TABLE TEST(ID VARCHAR)");
String url1 = getURL("testLinkedTableInReadOnlyDb", true);
Connection conn = DriverManager.getConnection(url1, "sa1", "abc abc");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
conn.close();
String[] files = IOUtils.listFiles(getBaseDir());
for (String file : files) {
String name = IOUtils.getFileName(file);
if ((name.startsWith("testLinkedTableInReadOnlyDb")) && (!name.endsWith(".trace.db"))) {
FileSystem.getInstance(file).setReadOnly(file);
boolean isReadOnly = FileSystem.getInstance(file).isReadOnly(file);
if (!isReadOnly) {
fail("File " + file + " is not read only. Can't test it.");
}
}
}
// Now it's read only
conn = DriverManager.getConnection(url1, "sa1", "abc abc");
stat = conn.createStatement();
stat.execute("CREATE LOCAL TEMPORARY LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')");
// This is valid because it's a linked table
stat.execute("INSERT INTO T VALUES('abc')");
conn.close();
memConn.close();
deleteDb("testLinkedTableInReadOnlyDb");