⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transferdb.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    PrimaryKeysConstraint += ") ";                }            }        } catch (SQLException e) {            throw new DataAccessPointException(e.getMessage());        }        boolean   indices     = false;        ResultSet Indices     = null;        String    IndiceName  = new String("");        String    CreateIndex = new String("");        String    DropIndex   = new String("");        try {            Indices = meta.getIndexInfo(TTable.Stmts.sDatabaseToConvert,                                        TTable.Stmts.sSchema,                                        TTable.Stmts.sSourceTable, false,                                        false);        } catch (SQLException e) {            Indices = null;        }        try {            if (Indices != null) {                while (Indices.next()) {                    String tmpIndexName = null;                    try {                        tmpIndexName = Indices.getString(6);                    } catch (SQLException e) {                        tmpIndexName = null;                    }                    if (tmpIndexName == null) {                        continue;                    }                    if (!tmpIndexName.equals(IndiceName)) {                        if (!IndiceName.equals("")) {                            CreateIndex =                                CreateIndex.substring(                                    0, CreateIndex.length() - 1) + ");";                            DropIndex += ";";                        }                        IndiceName = tmpIndexName;                        DropIndex  += "DROP INDEX ";                        if ((TTable.Stmts.bIdxForced)                                && (!IndiceName.startsWith("Idx_"))) {                            DropIndex += Dest.helper.formatIdentifier("Idx_"                                    + IndiceName);                        } else {                            DropIndex +=                                Dest.helper.formatIdentifier(IndiceName);                        }                        CreateIndex += "CREATE ";                        if (!Indices.getBoolean(4)) {                            CreateIndex += "UNIQUE ";                        }                        CreateIndex += "INDEX ";                        if ((TTable.Stmts.bIdxForced)                                && (!IndiceName.startsWith("Idx_"))) {                            CreateIndex += Dest.helper.formatIdentifier("Idx_"                                    + IndiceName);                        } else {                            CreateIndex +=                                Dest.helper.formatIdentifier(IndiceName);                        }                        CreateIndex +=                            " ON "                            + Dest.helper.formatName(TTable.Stmts.sDestTable)                            + "(";                    }                    CreateIndex +=                        Dest.helper.formatIdentifier(Indices.getString(9))                        + ",";                    indices = true;                }                Indices.close();                if (indices) {                    CreateIndex =                        CreateIndex.substring(0, CreateIndex.length() - 1)                        + ");";                    DropIndex += ";";                }            }        } catch (SQLException e) {            throw new DataAccessPointException(e.getMessage());        }        Vector v = new Vector();        tracer.trace("Reading source columns for table "                     + TTable.Stmts.sSourceTable);        ResultSet         col            = null;        int               colnum         = 1;        Statement         stmt           = null;        ResultSet         select_rs      = null;        ResultSetMetaData select_rsmdata = null;        try {            stmt           = conn.createStatement();            select_rs      = stmt.executeQuery(TTable.Stmts.sSourceSelect);            select_rsmdata = select_rs.getMetaData();            col = meta.getColumns(TTable.Stmts.sDatabaseToConvert,                                  TTable.Stmts.sSchema,                                  TTable.Stmts.sSourceTable, null);        } catch (SQLException eSchema) {            // fredt - second try with null schema            if (TTable.Stmts.sSchema.equals("")) {                try {                    col = meta.getColumns(TTable.Stmts.sDatabaseToConvert,                                          null, TTable.Stmts.sSourceTable,                                          null);                } catch (SQLException eSchema1) {}            }        }        try {            while (col.next()) {                String name = Dest.helper.formatIdentifier(col.getString(4));                int    type        = col.getShort(5);                String source      = col.getString(6);                int    column_size = col.getInt(7);                String DefaultVal  = col.getString(13);                boolean rsmdata_NoNulls =                    (select_rsmdata.isNullable(colnum)                     == java.sql.DatabaseMetaData.columnNoNulls);                boolean rsmdata_isAutoIncrement = false;                try {                    rsmdata_isAutoIncrement =                        select_rsmdata.isAutoIncrement(colnum);                } catch (SQLException e) {                    rsmdata_isAutoIncrement = false;                }                int rsmdata_precision = select_rsmdata.getPrecision(colnum);                int rsmdata_scale     = select_rsmdata.getScale(colnum);                type = helper.convertFromType(type);                type = Dest.helper.convertToType(type);                Integer inttype  = new Integer(type);                String  datatype = (String) TTable.hTypes.get(inttype);                if (datatype == null) {                    datatype = source;                    tracer.trace("No mapping for type: " + name + " type: "                                 + type + " source: " + source);                }                if (type == Types.NUMERIC) {                    datatype += "(" + Integer.toString(rsmdata_precision);                    if (rsmdata_scale > 0) {                        datatype += "," + Integer.toString(rsmdata_scale);                    }                    datatype += ")";                } else if (type == Types.CHAR) {                    datatype += "(" + Integer.toString(column_size) + ")";                } else if (rsmdata_isAutoIncrement) {                    datatype = "SERIAL";                }                if (DefaultVal != null) {                    if (type == Types.CHAR || type == Types.VARCHAR                            || type == Types.LONGVARCHAR                            || type == Types.BINARY || type == Types.DATE                            || type == Types.TIME                            || type == Types.TIMESTAMP) {                        DefaultVal = "\'" + DefaultVal + "\'";                    }                    datatype += " DEFAULT " + DefaultVal;                }                if (rsmdata_NoNulls) {                    datatype += " NOT NULL ";                }                v.addElement(inttype);                datatype = helper.fixupColumnDefRead(TTable, select_rsmdata,                                                     datatype, col, colnum);                datatype = Dest.helper.fixupColumnDefWrite(TTable,                        select_rsmdata, datatype, col, colnum);                create += name + " " + datatype + ",";                insert += "?,";                colnum++;            }            select_rs.close();            stmt.close();            col.close();        } catch (SQLException e) {            throw new DataAccessPointException(e.getMessage());        }        if (primarykeys) {            create += PrimaryKeysConstraint + ",";        }        TTable.Stmts.sDestCreate = create.substring(0, create.length() - 1)                                   + ")";        TTable.Stmts.sDestInsert = insert.substring(0, insert.length() - 1)                                   + ")";        if (importedkeys) {            TTable.Stmts.bAlter     = true;            TTable.Stmts.sDestAlter = alterCreate;        } else {            TTable.Stmts.bAlter = false;        }        if (indices) {            TTable.Stmts.bCreateIndex     = true;            TTable.Stmts.bDropIndex       = true;            TTable.Stmts.sDestCreateIndex = CreateIndex;            TTable.Stmts.sDestDropIndex   = DropIndex;        } else {            TTable.Stmts.bCreateIndex = false;            TTable.Stmts.bDropIndex   = false;        }        //iColumnType = new int[v.size()];        //for (int j = 0; j < v.size(); j++) {        //    iColumnType[j] = ((Integer) v.elementAt(j)).intValue();        //}    }    void close() throws DataAccessPointException {        if (srcStatement != null) {            try {                srcStatement.close();            } catch (SQLException e) {}            srcStatement = null;        }        if (conn != null) {            try {                conn.close();            } catch (SQLException e) {}            conn = null;        }    }    /**     * Method declaration     *     *     * @param type     * @param r     * @param p     *     * @throws SQLException     */    private void transferRow(TransferResultSet r, PreparedStatement p,                             int len,                             int[] types)                             throws DataAccessPointException, SQLException {        for (int i = 1; i <= len; i++) {            int    t = types[i];            Object o = r.getObject(i);            if (o == null) {                if (p != null) {                    p.setNull(i, t);                }            } else {                o = helper.convertColumnValue(o, i, t);                p.setObject(i, o);            }        }        if (p != null) {            p.execute();        }    }    /**     * @return Returns the meta.     */    public DatabaseMetaData getMeta() {        return meta;    }    /**     * @return Returns the conn.     */    public Connection getConn() {        return conn;    }}

⌨️ 快捷键说明

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