Package henplus.view.util

Examples of henplus.view.util.ProgressWriter


        dumpOut.print("  (data ");
        ResultSet rset = null;
        Statement stmt = null;
        try {
            long rows = 0;
            final ProgressWriter progressWriter = new ProgressWriter(expectedRows, HenPlus.msg());
            rset = dumpSource.getResultSet();
            stmt = dumpSource.getStatement();
            boolean isFirst = true;
            while (_running && rset.next()) {
                ++rows;
                progressWriter.update(rows);
                if (!isFirst) {
                    dumpOut.print("\n\t");
                }
                isFirst = false;
                dumpOut.print("(");

                for (int i = 0; i < metaProps.length; ++i) {
                    final int col = i + 1;
                    final int thisType = metaProps[i].getType();
                    switch (thisType) {
                        case HP_INTEGER:
                        case HP_NUMERIC:
                        case HP_DOUBLE: {
                            final String val = rset.getString(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                dumpOut.print(val);
                            }
                            break;
                        }

                        case HP_TIMESTAMP: {
                            final Timestamp val = rset.getTimestamp(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }

                        case HP_TIME: {
                            final Time val = rset.getTime(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }

                        case HP_DATE: {
                            final java.sql.Date val = rset.getDate(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }

                        case HP_BLOB: // we try our best by reading BLOB/CLOB
                        case HP_CLOB: // as String (known not to work on Oracle)
                        case HP_STRING: {
                            final String val = rset.getString(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val);
                            }
                            break;
                        }
                        case HP_BOOLEAN:
                            final boolean val = rset.getBoolean(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                dumpOut.print(val);
                            }
                            break;

                        default:
                            throw new IllegalArgumentException("type " + TYPES[thisType] + " not supported yet");
                    }
                    if (metaProps.length > col) {
                        dumpOut.print(",");
                    } else {
                        dumpOut.print(")");
                    }
                }
            }
            progressWriter.finish();
            dumpOut.println(")");
            dumpOut.println("  (rows " + rows + "))\n");

            HenPlus.msg().print("(" + rows + " rows)\n");
            final long execTime = System.currentTimeMillis() - startTime;
View Full Code Here


                                + "\nat                  : " + dumpTime + "\ndump format version : " + dumpVersion);
                if (whereClause != null) {
                    HenPlus.msg().println("projection          : " + whereClause);
                }

                final ProgressWriter progressWriter = new ProgressWriter(estimatedRows, HenPlus.msg());
                importedRows = 0;
                problemRows = 0;
                _running = true;
                while (_running) {
                    skipWhite(reader);
                    inCh = (char) reader.read();
                    if (inCh == ')') {
                        break;
                    }
                    if (inCh != '(') {
                        raiseException(reader, "'(' or ')' expected");
                    }
                    // we are now at the beginning of the row.
                    ++importedRows;
                    progressWriter.update(importedRows);
                    for (int i = 0; i < metaProperty.length; ++i) {
                        final int col = i + 1;
                        final int type = metaProperty[i].type;
                        switch (type) {
                            case HP_NUMERIC:
                            case HP_DOUBLE:
                            case HP_INTEGER: {
                                final Number number = readNumber(reader);
                                if (stmt != null) {
                                    if (number == null) {
                                        if (type == HP_NUMERIC) {
                                            stmt.setNull(col, Types.NUMERIC);
                                        } else if (type == HP_INTEGER) {
                                            stmt.setNull(col, Types.INTEGER);
                                        } else if (type == HP_DOUBLE) {
                                            stmt.setNull(col, Types.DOUBLE);
                                        }
                                    } else {
                                        if (number instanceof Integer) {
                                            stmt.setInt(col, number.intValue());
                                        } else if (number instanceof Long) {
                                            stmt.setLong(col, number.longValue());
                                        } else if (number instanceof Double) {
                                            stmt.setDouble(col, number.doubleValue());
                                        } else if (number instanceof BigDecimal) {
                                            stmt.setBigDecimal(col, (BigDecimal) number);
                                        }
                                    }
                                }
                                break;
                            }

                            case HP_TIMESTAMP: {
                                final String val = readString(reader);
                                metaProperty[i].updateMaxLength(val);
                                if (stmt != null) {
                                    if (val == null) {
                                        stmt.setTimestamp(col, null);
                                    } else {
                                        stmt.setTimestamp(col, Timestamp.valueOf(val));
                                    }
                                }
                                break;
                            }

                            case HP_TIME: {
                                final String val = readString(reader);
                                metaProperty[i].updateMaxLength(val);
                                if (stmt != null) {
                                    if (val == null) {
                                        stmt.setTime(col, null);
                                    } else {
                                        stmt.setTime(col, Time.valueOf(val));
                                    }
                                }
                                break;
                            }

                            case HP_DATE: {
                                final String val = readString(reader);
                                metaProperty[i].updateMaxLength(val);
                                if (stmt != null) {
                                    if (val == null) {
                                        stmt.setDate(col, null);
                                    } else {
                                        stmt.setDate(col, java.sql.Date.valueOf(val));
                                    }
                                }
                                break;
                            }

                            case HP_BLOB: // we try our best by reading BLOB/CLOB
                            case HP_CLOB: // as String (known not to work on Oracle
                            case HP_STRING: {
                                final String val = readString(reader);
                                metaProperty[i].updateMaxLength(val);
                                if (stmt != null) {
                                    stmt.setString(col, val);
                                }
                                break;
                            }
                            case HP_BOOLEAN:
                                final String val = readToken(reader);
                                metaProperty[i].updateMaxLength(1);
                                if (stmt != null) {
                                    stmt.setBoolean(col, Boolean.valueOf(val));
                                }
                                break;

                            default:
                                throw new IllegalArgumentException("type " + TYPES[metaProperty[i].type] + " not supported yet");
                        }
                        expect(reader, i + 1 < metaProperty.length ? ',' : ')');
                    }
                    try {
                        if (stmt != null) {
                            stmt.execute();
                        }
                    } catch (final SQLException e) {
                        String msg = e.getMessage();
                        // oracle adds CR for some reason.
                        if (msg != null) {
                            msg = msg.trim();
                        }
                        reportProblem(msg);
                        ++problemRows;
                    }

                    // commit every once in a while.
                    if (hot && commitPoint >= 0 && importedRows % commitPoint == 0) {
                        conn.commit();
                    }
                }
                progressWriter.finish();
            } else {
                HenPlus.msg().println("ignoring unknown token " + token);
                dumpTime = readString(reader);
                expect(reader, ')');
            }
View Full Code Here

TOP

Related Classes of henplus.view.util.ProgressWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.