예제 #1
0
 public String getDeleteRowSql() {
   if (deleteRowSql == null) {
     switch (getDialect()) {
       case SYBASE:
         deleteRowSql =
             "DELETE FROM "
                 + getTableName()
                 + " WHERE "
                 + config.idColumnName()
                 + " = convert("
                 + config.idColumnType()
                 + ","
                 + "?)";
         break;
       case POSTGRES:
         deleteRowSql =
             "DELETE FROM "
                 + getTableName()
                 + " WHERE "
                 + config.idColumnName()
                 + " = cast(? as "
                 + config.idColumnType()
                 + ")";
         break;
       default:
         deleteRowSql =
             "DELETE FROM " + getTableName() + " WHERE " + config.idColumnName() + " = ?";
         break;
     }
   }
   return deleteRowSql;
 }
예제 #2
0
 public String getLoadAllRowsSql() {
   if (loadAllRowsSql == null) {
     loadAllRowsSql =
         "SELECT "
             + config.dataColumnName()
             + ","
             + config.idColumnName()
             + " FROM "
             + getTableName();
   }
   return loadAllRowsSql;
 }
예제 #3
0
 public String getDeleteExpiredRowsSql() {
   if (deleteExpiredRowsSql == null) {
     deleteExpiredRowsSql =
         "DELETE FROM "
             + getTableName()
             + " WHERE "
             + config.timestampColumnName()
             + "< ? AND "
             + config.timestampColumnName()
             + "> 0";
   }
   return deleteExpiredRowsSql;
 }
예제 #4
0
 public String getInsertRowSql() {
   if (insertRowSql == null) {
     insertRowSql =
         "INSERT INTO "
             + getTableName()
             + " ("
             + config.dataColumnName()
             + ", "
             + config.timestampColumnName()
             + ", "
             + config.idColumnName()
             + ") VALUES(?,?,?)";
   }
   return insertRowSql;
 }
예제 #5
0
 public String getLoadAllKeysStringSql() {
   if (loadAllKeysStringSql == null) {
     loadAllKeysStringSql =
         String.format("SELECT %s FROM %s", config.idColumnName(), getTableName());
   }
   return loadAllKeysStringSql;
 }
예제 #6
0
 public void createTable(Connection conn) throws PersistenceException {
   // removed CONSTRAINT clause as this causes problems with some databases, like Informix.
   assertMandatoryElementsPresent();
   String createTableDdl =
       "CREATE TABLE "
           + getTableName()
           + "("
           + config.idColumnName()
           + " "
           + config.idColumnType()
           + " NOT NULL, "
           + config.dataColumnName()
           + " "
           + config.dataColumnType()
           + ", "
           + config.timestampColumnName()
           + " "
           + config.timestampColumnType()
           + ", PRIMARY KEY ("
           + config.idColumnName()
           + "))";
   if (trace) {
     log.tracef("Creating table with following DDL: '%s'.", createTableDdl);
   }
   executeUpdateSql(conn, createTableDdl);
 }
예제 #7
0
 public String getLoadNonExpiredAllRowsSql() {
   if (loadAllNonExpiredRowsSql == null) {
     loadAllNonExpiredRowsSql =
         "SELECT "
             + config.dataColumnName()
             + ","
             + config.idColumnName()
             + ", "
             + config.timestampColumnName()
             + " FROM "
             + getTableName()
             + " WHERE "
             + config.timestampColumnName()
             + " > ? OR "
             + config.timestampColumnName()
             + " < 0";
   }
   return loadAllNonExpiredRowsSql;
 }
예제 #8
0
 public void stop() throws PersistenceException {
   if (config.dropOnExit()) {
     Connection conn = null;
     try {
       conn = connectionFactory.getConnection();
       dropTable(conn);
     } finally {
       connectionFactory.releaseConnection(conn);
     }
   }
 }
예제 #9
0
 public void start(ConnectionFactory connectionFactory) throws PersistenceException {
   this.connectionFactory = connectionFactory;
   if (config.createOnStart()) {
     Connection conn = null;
     try {
       conn = this.connectionFactory.getConnection();
       if (!tableExists(conn, getTableName())) {
         createTable(conn);
       }
     } finally {
       this.connectionFactory.releaseConnection(conn);
     }
   }
 }
예제 #10
0
 public String getSelectIdRowSql() {
   if (selectIdRowSql == null) {
     switch (getDialect()) {
       case SYBASE:
         selectIdRowSql =
             "SELECT "
                 + config.idColumnName()
                 + " FROM "
                 + getTableName()
                 + " WHERE "
                 + config.idColumnName()
                 + " = convert("
                 + config.idColumnType()
                 + ","
                 + "?)";
         break;
       case POSTGRES:
         selectIdRowSql =
             "SELECT "
                 + config.idColumnName()
                 + " FROM "
                 + getTableName()
                 + " WHERE "
                 + config.idColumnName()
                 + " = cast(? as "
                 + config.idColumnType()
                 + ")";
         break;
       default:
         selectIdRowSql =
             "SELECT "
                 + config.idColumnName()
                 + " FROM "
                 + getTableName()
                 + " WHERE "
                 + config.idColumnName()
                 + " = ?";
         break;
     }
   }
   return selectIdRowSql;
 }
예제 #11
0
 /**
  * For DB queries the fetch size will be set on {@link java.sql.ResultSet#setFetchSize(int)}. This
  * is optional parameter, if not specified will be defaulted to {@link #DEFAULT_FETCH_SIZE}.
  */
 public int getFetchSize() {
   return config.fetchSize();
 }
예제 #12
0
 /**
  * When doing repetitive DB inserts this will be batched according to this parameter. This is an
  * optional parameter, and if it is not specified it will be defaulted to {@link
  * #DEFAULT_BATCH_SIZE}. Guaranteed to be a power of two.
  */
 public int getBatchSize() {
   return config.batchSize();
 }
예제 #13
0
 /**
  * For DB queries the fetch size will be set on {@link java.sql.ResultSet#setFetchSize(int)}. This
  * is optional parameter, if not specified will be defaulted to {@link #DEFAULT_FETCH_SIZE}.
  */
 public int getFetchSize() {
   return getDialect() == DatabaseType.MYSQL ? Integer.MIN_VALUE : config.fetchSize();
 }
예제 #14
0
  public String getLoadSomeRowsSql() {
    if (loadSomeRowsSql == null) {
      // this stuff is going to be database specific!!
      // see
      // http://stackoverflow.com/questions/595123/is-there-an-ansi-sql-alternative-to-the-mysql-limit-keyword

      switch (getDialect()) {
        case ORACLE:
          loadSomeRowsSql =
              String.format(
                  "SELECT %s, %s FROM (SELECT %s, %s FROM %s) WHERE ROWNUM <= ?",
                  config.dataColumnName(),
                  config.idColumnName(),
                  config.dataColumnName(),
                  config.idColumnName(),
                  getTableName());
          break;
        case DB2:
        case DB2_390:
        case DERBY:
          loadSomeRowsSql =
              String.format(
                  "SELECT %s, %s FROM %s FETCH FIRST ? ROWS ONLY",
                  config.dataColumnName(), config.idColumnName(), getTableName());
          break;
        case INFORMIX:
        case INTERBASE:
        case FIREBIRD:
          loadSomeRowsSql =
              String.format(
                  "SELECT FIRST ? %s, %s FROM %s",
                  config.dataColumnName(), config.idColumnName(), getTableName());
          break;
        case SQL_SERVER:
          loadSomeRowsSql =
              String.format(
                  "SELECT TOP (?) %s, %s FROM %s",
                  config.dataColumnName(), config.idColumnName(), getTableName());
          break;
        case ACCESS:
        case HSQL:
        case SYBASE:
          loadSomeRowsSql =
              String.format(
                  "SELECT TOP ? %s, %s FROM %s",
                  config.dataColumnName(), config.idColumnName(), getTableName());
          break;
        default:
          // the MySQL-style LIMIT clause (works for PostgreSQL too)
          loadSomeRowsSql =
              String.format(
                  "SELECT %s, %s FROM %s LIMIT ?",
                  config.dataColumnName(), config.idColumnName(), getTableName());
          break;
      }
    }
    return loadSomeRowsSql;
  }
예제 #15
0
 public TableName getTableName() {
   if (tableName == null) {
     tableName = new TableName(getIdentifierQuoteString(), config.tableNamePrefix(), cacheName);
   }
   return tableName;
 }
예제 #16
0
 public String getUpdateRowSql() {
   if (updateRowSql == null) {
     switch (getDialect()) {
       case SYBASE:
         updateRowSql =
             "UPDATE "
                 + getTableName()
                 + " SET "
                 + config.dataColumnName()
                 + " = ? , "
                 + config.timestampColumnName()
                 + "=? WHERE "
                 + config.idColumnName()
                 + " = convert("
                 + config.idColumnType()
                 + ","
                 + "?)";
         break;
       case POSTGRES:
         updateRowSql =
             "UPDATE "
                 + getTableName()
                 + " SET "
                 + config.dataColumnName()
                 + " = ? , "
                 + config.timestampColumnName()
                 + "=? WHERE "
                 + config.idColumnName()
                 + " = cast(? as "
                 + config.idColumnType()
                 + ")";
         break;
       default:
         updateRowSql =
             "UPDATE "
                 + getTableName()
                 + " SET "
                 + config.dataColumnName()
                 + " = ? , "
                 + config.timestampColumnName()
                 + "=? WHERE "
                 + config.idColumnName()
                 + " = ?";
         break;
     }
   }
   return updateRowSql;
 }
예제 #17
0
 public String getSelectExpiredRowsSql() {
   if (selectExpiredRowsSql == null) {
     selectExpiredRowsSql = getLoadAllRowsSql() + " WHERE " + config.timestampColumnName() + "< ?";
   }
   return selectExpiredRowsSql;
 }