All pastes #2126576 Raw Edit

Mine

public text v1 · immutable
#2126576 ·published 2012-03-10 08:46 UTC
rendered paste body
        Statement stmt = null;
        
        try {
            Class.forName("org.h2.Driver");
            CONNECTION = DriverManager.getConnection("jdbc:h2:resource");

            stmt = CONNECTION.createStatement();

            stmt.execute(
                    "CREATE SEQUENCE IF NOT EXISTS GENERATION_SEQ "
                    + "START WITH -9223372036854775808L"
                    + "INCREMENT BY 1"
                    + "CACHE 1");

            stmt.execute(
                    "CREATE TABLE IF NOT EXISTS GENERATION ("
                    + "ID BIGINT NOT NULL AUTO_INCREMENT,"
                    + "CREATION_TIME BIGINT NOT NULL,"
                    + "BUNDLE_SIZE BIGINT NOT NULL,"
                    + "HASH_CHECKSUM BINARY NOT NULL");

            // bundle size = SELECT SUM(LENGTH(DATA)) + COUNT
            
            stmt.execute(
                    "CREATE TABLE IF NOT EXISTS RESOURCE ("
                    + "ID BIGINT NOT NULL AUTO_INCREMENT,"
                    + "GENERATION_ID BIGINT NOT NULL,"
                    + "DATA BINARY NOT NULL,"
                    + "PRIMARY KEY (GENERATION_ID, ID)"
                    + ")");

            stmt.execute("");
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            
        }