init: Create database indexes during schema creation

We now automatically create the database indexes during schema
creation by parsing our own index creation script(s) and doing
their raw SQL commands one at a time on the underlying database.

To simplify setup we now only perform this work inside of init,
and no longer do it implicitly when the WAR is loaded inside of
a servlet container.

Bug: issue 343
Change-Id: I0b37d7e75d75402a3854bb3751c642dec7897940
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-12-16 20:30:00 -08:00
parent 3bccd773c2
commit 2fdaabd50e
13 changed files with 547 additions and 298 deletions

View File

@@ -15,12 +15,13 @@
package com.google.gerrit.testutil;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.config.SystemConfigProvider;
import com.google.gerrit.server.schema.SchemaCreator;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.jdbc.Database;
import com.google.gwtorm.jdbc.SimpleDataSource;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
@@ -55,6 +56,7 @@ public class TestDatabase implements SchemaFactory<ReviewDb> {
private Connection openHandle;
private Database<ReviewDb> database;
private boolean created;
public TestDatabase() throws OrmException {
try {
@@ -84,8 +86,16 @@ public class TestDatabase implements SchemaFactory<ReviewDb> {
}
/** Ensure the database schema has been created and initialized. */
public TestDatabase create() {
new SystemConfigProvider(this).get();
public TestDatabase create() throws OrmException {
if (!created) {
created = true;
final ReviewDb c = open();
try {
new SchemaCreator(new File(".")).create(c);
} finally {
c.close();
}
}
return this;
}