コード例 #1
0
  /**
   * Method to create a PreparedStatement for use with the query.
   *
   * @param conn the Connection
   * @param queryStmt The statement text for the query
   * @param query The query
   * @return the PreparedStatement
   * @throws SQLException Thrown if an error occurs creating the statement
   */
  public static PreparedStatement getPreparedStatementForQuery(
      ManagedConnection conn, String queryStmt, Query query) throws SQLException {
    // Apply any non-standard result set definition if required (either from the PMF, or via query
    // extensions)
    String rsTypeString = RDBMSQueryUtils.getResultSetTypeForQuery(query);
    if (rsTypeString != null
        && (!rsTypeString.equals("scroll-sensitive")
            && !rsTypeString.equals("forward-only")
            && !rsTypeString.equals("scroll-insensitive"))) {
      throw new NucleusUserException(LOCALISER.msg("052510"));
    }
    if (rsTypeString != null) {
      DatastoreAdapter dba = ((RDBMSStoreManager) query.getStoreManager()).getDatastoreAdapter();

      // Add checks on what the DatastoreAdapter supports
      if (rsTypeString.equals("scroll-sensitive")
          && !dba.supportsOption(DatastoreAdapter.RESULTSET_TYPE_SCROLL_SENSITIVE)) {
        NucleusLogger.DATASTORE_RETRIEVE.info(
            "Query requested to run with result-set type of "
                + rsTypeString
                + " yet not supported by adapter. Using forward-only");
        rsTypeString = "forward-only";
      } else if (rsTypeString.equals("scroll-insensitive")
          && !dba.supportsOption(DatastoreAdapter.RESULTSET_TYPE_SCROLL_INSENSITIVE)) {
        NucleusLogger.DATASTORE_RETRIEVE.info(
            "Query requested to run with result-set type of "
                + rsTypeString
                + " yet not supported by adapter. Using forward-only");
        rsTypeString = "forward-only";
      } else if (rsTypeString.equals("forward-only")
          && !dba.supportsOption(DatastoreAdapter.RESULTSET_TYPE_FORWARD_ONLY)) {
        NucleusLogger.DATASTORE_RETRIEVE.info(
            "Query requested to run with result-set type of "
                + rsTypeString
                + " yet not supported by adapter. Using scroll-sensitive");
        rsTypeString = "scroll-sensitive";
      }
    }

    String rsConcurrencyString = RDBMSQueryUtils.getResultSetConcurrencyForQuery(query);
    if (rsConcurrencyString != null
        && (!rsConcurrencyString.equals("read-only")
            && !rsConcurrencyString.equals("updateable"))) {
      throw new NucleusUserException(LOCALISER.msg("052511"));
    }

    SQLController sqlControl = ((RDBMSStoreManager) query.getStoreManager()).getSQLController();
    PreparedStatement ps =
        sqlControl.getStatementForQuery(conn, queryStmt, rsTypeString, rsConcurrencyString);

    return ps;
  }
コード例 #2
0
  /** Method to initialise the sequence table used for storing the sequence values. */
  protected void initialiseSequenceTable() {
    // Set catalog/schema name (using properties, and if not specified using the values for the
    // table)
    String catalogName = properties.getProperty("sequence-catalog-name");
    if (catalogName == null) {
      catalogName = properties.getProperty("catalog-name");
    }
    String schemaName = properties.getProperty("sequence-schema-name");
    if (schemaName == null) {
      schemaName = properties.getProperty("schema-name");
    }
    String tableName =
        (properties.getProperty("sequence-table-name") == null
            ? DEFAULT_TABLE_NAME
            : properties.getProperty("sequence-table-name"));

    RDBMSStoreManager storeMgr = (RDBMSStoreManager) this.storeMgr;
    DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
    DatastoreIdentifier identifier = storeMgr.getIdentifierFactory().newTableIdentifier(tableName);
    if (dba.supportsOption(DatastoreAdapter.CATALOGS_IN_TABLE_DEFINITIONS) && catalogName != null) {
      identifier.setCatalogName(catalogName);
    }
    if (dba.supportsOption(DatastoreAdapter.SCHEMAS_IN_TABLE_DEFINITIONS) && schemaName != null) {
      identifier.setSchemaName(schemaName);
    }

    DatastoreClass table = storeMgr.getDatastoreClass(identifier);
    if (table != null) {
      sequenceTable = (SequenceTable) table;
    } else {
      String sequenceNameColumnName = DEFAULT_SEQUENCE_COLUMN_NAME;
      String nextValColumnName = DEFAULT_NEXTVALUE_COLUMN_NAME;
      if (properties.getProperty("sequence-name-column-name") != null) {
        sequenceNameColumnName = properties.getProperty("sequence-name-column-name");
      }
      if (properties.getProperty("sequence-nextval-column-name") != null) {
        nextValColumnName = properties.getProperty("sequence-nextval-column-name");
      }
      sequenceTable =
          new SequenceTable(identifier, storeMgr, sequenceNameColumnName, nextValColumnName);
      sequenceTable.initialize(storeMgr.getNucleusContext().getClassLoaderResolver(null));
    }
  }