oraclemodule.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,223 行 · 第 1/5 页

JAVA
2,223
字号
    }  }  /**   * Allocates new collection object   */  @ReturnNullAsFalse  public static OracleOciCollection oci_new_collection(Env env,                                                       @NotNull Oracle conn,                                                       @NotNull String tdo,                                                       @Optional String schema)  {    try {      String typeName = tdo;      if ((schema != null) && (schema.length() > 0)) {        typeName = schema + "." + tdo;      }      // XXX: Is this case ever possible?      // StructDescriptor structDesc = StructDescriptor.createDescriptor(typeName, jdbcConn);      // JDBC underlying connection      Connection jdbcConn = conn.getJavaConnection();      // Oracle underlying statement      // PreparedStatement oracleStmt = stmt.getPreparedStatement();      // Use reflection      // ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(typeName, jdbcConn);      Class clArrayDescriptor = Class.forName("oracle.sql.ArrayDescriptor");      Method method = clArrayDescriptor.getDeclaredMethod("createDescriptor",                                                          new Class[] {String.class,                                                                       Connection.class});      Object arrayDesc = method.invoke(clArrayDescriptor,                                       new Object[] {typeName, jdbcConn});      if (arrayDesc != null) {        return new OracleOciCollection(jdbcConn, arrayDesc);      }    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);    }    return null;  }  /**   * Establishes a new connection to the Oracle server   */  public static Value oci_new_connect(Env env,                                      @NotNull String username,                                      @NotNull String password,                                      @Optional String db,                                      @Optional String charset,                                      @Optional("0") int sessionMode)  {    if ((sessionMode == OCI_DEFAULT)	|| (sessionMode == OCI_SYSOPER)	|| (sessionMode == OCI_SYSDBA)) {      log.warning(L.l("oci_new_connect with session mode '{0}'", sessionMode));    }    return connectInternal(env, false, username, password, db,			   charset, sessionMode);  }  /**   * Allocates and returns a new cursor (statement handle)   */  @ReturnNullAsFalse  public static OracleStatement oci_new_cursor(Env env,                                               @NotNull Oracle conn)  {    try {      OracleStatement stmt = new OracleStatement((Oracle) conn.validateConnection());      return stmt;    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return null;    }  }  /**   * Initializes a new empty LOB or FILE descriptor   *   * @param type one of the following types:   *   * OCI_D_FILE - a FILE descriptor   *   * OCI_D_LOB - a LOB descriptor   *   * OCI_D_ROWID - a ROWID descriptor   */  @ReturnNullAsFalse  public static OracleOciLob oci_new_descriptor(Env env,                                                @NotNull Oracle conn,                                                @Optional("-1") int type)  {    try {      if ((type == OCI_D_FILE) ||          (type == OCI_D_LOB) ||          (type == OCI_D_ROWID)) {        OracleOciLob oracleLob = new OracleOciLob(conn, type);        return oracleLob;      }    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);    }    return null;  }  /**   *  Returns the number of result columns in a statement   */  public static Value oci_num_fields(Env env,                                     @NotNull OracleStatement stmt)  {    try {      if (stmt == null)        return BooleanValue.FALSE;      JdbcResultResource resource	= new JdbcResultResource(env, null, stmt.getResultSet(), null);      return LongValue.create(resource.getFieldCount());    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return BooleanValue.FALSE;    }  }  /**   * Returns number of rows affected during statement execution   *   * Note:  This function does not return number of rows selected!   * For SELECT statements this function will return the number of rows,   * that were fetched to the buffer with oci_fetchxxxx() functions.   */  @ReturnNullAsFalse  public static LongValue oci_num_rows(Env env,                                       @NotNull OracleStatement stmt)  {    try {      if (stmt == null)        return null;      // JdbcResultResource resource = new JdbcResultResource(null, stmt.getResultSet(), null);      // return LongValue.create(resource.getNumRows());      return LongValue.create(stmt.getFetchedRows());    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return null;    }  }  /**   * Prepares Oracle statement for execution   */  @ReturnNullAsFalse  public static OracleStatement oci_parse(Env env,                                          @NotNull Oracle conn,                                          String query)  {    try {      // XXX: Rework this.      // Enclose the query with "begin ...; end;" so any regular statement      // or stored procedure call can be executed with a CallableStatement.      query = query.trim();      String lowerCaseQuery = query.toLowerCase();      if (lowerCaseQuery.startsWith("insert") ||          lowerCaseQuery.startsWith("update") ||          lowerCaseQuery.startsWith("delete")) {        if (!lowerCaseQuery.startsWith("begin ")) {          query = "begin " + query;        }        if (!lowerCaseQuery.endsWith(";")) {          query += ";";        }        if (!lowerCaseQuery.endsWith(" end;")) {          query += " end;";        }      }      // Make the PHP query a JDBC like query replacing (:mydata -> ?) with question marks.      // Store binding names for future reference (see oci_execute)      String regex = ":[a-zA-Z0-9_]+";      String jdbcQuery = query.replaceAll(regex, "?");      OracleStatement pstmt = conn.prepare(env, env.createString(jdbcQuery));      Pattern pattern = Pattern.compile(regex);      Matcher matcher = pattern.matcher(query);      int i = 0;      while (matcher.find()) {        String group = matcher.group();        pstmt.putBindingVariable(group, new Integer(++i));      }      return pstmt;    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return null;    }  }  /**   * Changes password of Oracle's user   */  public static boolean oci_password_change(Env env,                                            @NotNull Oracle conn,                                            @NotNull String username,                                            @NotNull String oldPassword,                                            @NotNull String newPassword)  {    try {      // XXX: When is oldPassword used?      if (conn == null)        return false;      OracleStatement oracleStmt;      oracleStmt = oci_parse(env, conn, "ALTER USER "+username+" IDENTIFIED BY "+newPassword);      oci_execute(env, oracleStmt, 0);      return true;    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return false;    }  }  /**   * Connect to an Oracle database using a persistent connection   */  public static Value oci_pconnect(Env env,                                   @NotNull String username,                                   @NotNull String password,                                   @Optional String db,                                   @Optional String charset,                                   @Optional("0") int sessionMode)  {    if (!((charset == null) || charset.length() == 0)) {      throw new UnimplementedException("oci_pconnect with charset");    }    if ((sessionMode == OCI_DEFAULT) ||        (sessionMode == OCI_SYSOPER) ||        (sessionMode == OCI_SYSDBA)) {      throw new UnimplementedException("oci_pconnect with session mode");    }    return connectInternal(env, true, username, password, db, charset, sessionMode);  }  /**   * Returns field's value from the fetched row   */  public static Value oci_result(Env env,                                 @NotNull OracleStatement stmt,                                 @NotNull Value field)  {    try {      if (stmt == null)        return BooleanValue.FALSE;      Value result = stmt.getResultBuffer();      return ((ArrayValueImpl)result).get(field);    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return BooleanValue.FALSE;    }  }  /**   * Rolls back outstanding transaction   */  public static Value oci_rollback(Env env,                                   @NotNull Oracle conn)  {    try {      return BooleanValue.create(conn.rollback());    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return BooleanValue.FALSE;    }  }  /**   * Returns server version   */  @ReturnNullAsFalse  public static String oci_server_version(Env env,                                          @NotNull Oracle conn)  {    try {      if (conn == null)        conn = getConnection(env);      return conn.getServerInfo();    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return null;    }  }  /**   * Sets number of rows to be prefetched   */  public static boolean oci_set_prefetch(Env env,                                         @NotNull OracleStatement stmt,                                         @Optional("1") int rows)  {    try {      if (stmt == null)        return false;      PreparedStatement pstmt = stmt.getPreparedStatement();      pstmt.setFetchSize(rows);      return true;    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return false;    }  }  /**   * Returns the type of an OCI statement   */  public static String oci_statement_type(Env env,                                          @NotNull OracleStatement stmt)  {    return stmt.getStatementType();  }  /**   * Alias of oci_bind_by_name()   */  public static boolean ocibindbyname(Env env,                                      @NotNull OracleStatement stmt,                                      @NotNull String variable,                                      @NotNull Value value,                                      @Optional("0") int maxLength,                                      @Optional("0") int type)  {    return oci_bind_by_name(env, stmt, variable, value, maxLength, type);  }  /**   * Alias of oci_cancel()   */  public static boolean ocicancel(Env env,                                  @NotNull OracleStatement stmt)  {    return oci_cancel(env, stmt);  }  /**   * Alias of OCI-Lob->close   */  public static Value ocicloselob(Env env,                                  @NotNull Oracle conn)  {    throw new UnimplementedException("ocicloselob");  }  /**   * Alias of OCI-Collection->append   */  public static Value ocicollappend(Env env,                                    @NotNull Oracle conn)  {    throw new UnimplementedException("ocicollappend");  }  /**   * Alias of OCI-Collection->assign   */  public static Value ocicollassign(Env env,                                    @NotNull Oracle conn)  {    throw new UnimplementedException("ocicollassign");  }  /**   * Alias of OCI-Collection->assignElem   */  public static Value ocicollassignelem(Env env,                                        @NotNull Oracle conn)  {    throw new UnimplementedException("ocicollassignelem");  }  /**   * Alias of OCI-Collection->getElem   */  public static Value ocicollgetelem(Env env,                                     @NotNull Oracle conn)  {    throw new UnimplementedException("ocicollgetelem");  }  /**   * Alias of OCI-Collection->max   */  public static Value ocicollmax(Env env,                                 @NotNull Oracle conn)  {    throw new UnimplementedException("ocicollmax");  }  /**   * Alias of OCI-Collection->size   */  public static Value ocicollsize(Env env,                                  @NotNull Oracle conn)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?