Search in sources :

Example 1 with Stmt

use of ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt in project ili2db by claeis.

the class FgdbSequenceBasedIdGen method initDbDefs.

@Override
public void initDbDefs(ch.ehi.sqlgen.generator.Generator gen) {
    String sqlName = SQL_ILI2DB_SEQ_NAME;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String stmt = "CREATE SEQUENCE " + sqlName + ";";
    if (gen instanceof GeneratorJdbc) {
        ((GeneratorJdbc) gen).addCreateLine(((GeneratorJdbc) gen).new Stmt(stmt));
        ((GeneratorJdbc) gen).addDropLine(((GeneratorJdbc) gen).new Stmt("DROP SEQUENCE " + sqlName + ";"));
    }
    try {
        if (sequenceExists(new DbTableName(schema, sqlName))) {
            return;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement updstmt = null;
    try {
        updstmt = conn.prepareStatement(stmt);
        updstmt.execute();
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to create sequence " + sqlName, ex);
    } finally {
        if (updstmt != null) {
            try {
                updstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
}
Also used : GeneratorJdbc(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc) IOException(java.io.IOException) DbTableName(ch.ehi.sqlgen.repository.DbTableName) Stmt(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt)

Example 2 with Stmt

use of ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt in project ili2db by claeis.

the class GpkgSequenceBasedIdGen method initDbDefs.

@Override
public void initDbDefs(ch.ehi.sqlgen.generator.Generator gen) {
    String sqlName = SQL_ILI2DB_SEQ_NAME;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String stmt = "CREATE SEQUENCE " + sqlName + ";";
    if (gen instanceof GeneratorJdbc) {
        ((GeneratorJdbc) gen).addCreateLine(((GeneratorJdbc) gen).new Stmt(stmt));
        ((GeneratorJdbc) gen).addDropLine(((GeneratorJdbc) gen).new Stmt("DROP SEQUENCE " + sqlName + ";"));
    }
    try {
        if (sequenceExists(new DbTableName(schema, sqlName))) {
            return;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement updstmt = null;
    try {
        updstmt = conn.prepareStatement(stmt);
        updstmt.execute();
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to create sequence " + sqlName, ex);
    } finally {
        if (updstmt != null) {
            try {
                updstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
}
Also used : GeneratorJdbc(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc) IOException(java.io.IOException) DbTableName(ch.ehi.sqlgen.repository.DbTableName) Stmt(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt)

Aggregations

GeneratorJdbc (ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc)2 Stmt (ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt)2 DbTableName (ch.ehi.sqlgen.repository.DbTableName)2 IOException (java.io.IOException)2