: "Memory";
print(name + " Performance");
try {
jdbcDataSource dataSource = new jdbcDataSource();
dataSource.setDatabase(url);
cConnection = dataSource.getConnection(user, password);
sStatement = cConnection.createStatement();
} catch (Exception e) {
e.printStackTrace();
print("TestSelf init error: " + e.getMessage());
}
try {
// cache, index and performance tests
s = "CREATE CACHED TABLE Addr(ID INT PRIMARY KEY,First CHAR,"
+ "Name CHAR,ZIP INT)";
sStatement.execute(s);
s = "CREATE INDEX iName ON Addr(Name)";
sStatement.execute(s);
s = "SET WRITE_DELAY TRUE";
sStatement.execute(s);
start = System.currentTimeMillis();
for (int i = 0; i < max; i++) {
s = "INSERT INTO Addr VALUES(" + i + ",'Marcel" + i + "',"
+ "'Renggli" + (max - i - (i % 31)) + "',"
+ (3000 + i % 100) + ")";
if (sStatement.executeUpdate(s) != 1) {
throw new Exception("Insert failed");
}
if (i % 100 == 0) {
printStatus("insert ", i, max, start);
}
}
printStatus("insert ", max, max, start);
print("");
s = "SELECT COUNT(*) FROM Addr";
r = sStatement.executeQuery(s);
r.next();
int c = r.getInt(1);
if (c != max) {
throw new Exception("Count should be " + (max) + " but is "
+ c);
}
if (persistent) {
// close & reopen to test backup
cConnection.close();
jdbcDataSource dataSource = new jdbcDataSource();
dataSource.setDatabase(url);
cConnection = dataSource.getConnection(user, password);
sStatement = cConnection.createStatement();
}
start = System.currentTimeMillis();
for (int i = 0; i < max; i++) {
s = "UPDATE Addr SET Name='Robert" + (i + (i % 31))
+ "' WHERE ID=" + i;
if (sStatement.executeUpdate(s) != 1) {
throw new Exception("Update failed");
}
if (i % 100 == 0) {
printStatus("updated ", i, max, start);
// s="SELECT COUNT(*) FROM Addr";
// r=sStatement.executeQuery(s);
// r.next();
// int c=r.getInt(1);
// if(c!=max) {
// throw new Exception("Count should be "+max+" but is "+c);
// }
}
}
printStatus("update ", max, max, start);
print("");
if (persistent) {
s = "SHUTDOWN IMMEDIATELY";
sStatement.execute(s);
// open the database; it must be restored after shutdown
cConnection.close();
jdbcDataSource dataSource = new jdbcDataSource();
dataSource.setDatabase(url);
cConnection = dataSource.getConnection(user, password);
sStatement = cConnection.createStatement();
}
start = System.currentTimeMillis();