Example usage for java.sql Types TIMESTAMP

List of usage examples for java.sql Types TIMESTAMP

Introduction

In this page you can find the example usage for java.sql Types TIMESTAMP.

Prototype

int TIMESTAMP

To view the source code for java.sql Types TIMESTAMP.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP.

Usage

From source file:org.apache.nifi.admin.dao.impl.StandardUserDAO.java

@Override
public void updateGroupVerification(String group, Date lastVerified) throws DataAccessException {
    PreparedStatement statement = null;
    try {//  w w w.  ja va 2  s  . c  o  m
        // create a statement
        statement = connection.prepareStatement(UPDATE_USER_GROUP_VERIFICATION);

        // set the last verified time accordingly
        if (lastVerified == null) {
            statement.setNull(1, Types.TIMESTAMP);
        } else {
            statement.setTimestamp(1, new java.sql.Timestamp(lastVerified.getTime()));
        }

        // set the group
        statement.setString(2, group);

        // perform the update
        statement.executeUpdate();
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } catch (DataAccessException dae) {
        throw dae;
    } finally {
        RepositoryUtils.closeQuietly(statement);
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void insert(final Verblijfsobject verblijfsobject) throws DAOException {
    try {//from w w w.j  av a 2  s.  c  o  m
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("insert into bag_verblijfsobject ("
                                + "bag_verblijfsobject_id," + "aanduiding_record_inactief,"
                                + "aanduiding_record_correctie," + "officieel," + "verblijfsobject_geometrie,"
                                + "oppervlakte_verblijfsobject," + "verblijfsobject_status,"
                                + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid,"
                                + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer,"
                                + "bag_nummeraanduiding_id" + ") values (?,?,?,?,?,?,?,?,?,?,?,?,?)");
                        ps.setLong(1, verblijfsobject.getIdentificatie());
                        ps.setInt(2, verblijfsobject.getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, verblijfsobject.getAanduidingRecordCorrectie());
                        ps.setInt(4, verblijfsobject.getOfficieel().ordinal());
                        ps.setString(5, verblijfsobject.getVerblijfsobjectGeometrie());
                        ps.setInt(6, verblijfsobject.getOppervlakteVerblijfsobject());
                        ps.setInt(7, verblijfsobject.getVerblijfsobjectStatus().ordinal());
                        ps.setTimestamp(8,
                                new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                        if (verblijfsobject.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(9, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(9,
                                    new Timestamp(verblijfsobject.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(10, verblijfsobject.getInOnderzoek().ordinal());
                        ps.setDate(11, new Date(verblijfsobject.getDocumentdatum().getTime()));
                        ps.setString(12, verblijfsobject.getDocumentnummer());
                        ps.setLong(13, verblijfsobject.getHoofdAdres());
                        return ps;
                    }
                });
                insertGebruikersdoelen(verblijfsobject);
                insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject);
                insertGerelateerdePanden(verblijfsobject);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting verblijfsobject: " + verblijfsobject.getIdentificatie(), e);
    }
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java

private int getSQLType(Object object) {
    if (object instanceof PGgeometry) {
        return Types.OTHER;
    } else if (object instanceof Timestamp) {
        return Types.TIMESTAMP;
    } else if (object instanceof String) {
        return Types.VARCHAR;
    } else if (object instanceof Double) {
        return Types.DOUBLE;
    } else if (object instanceof Float) {
        return Types.FLOAT;
    } else if (object instanceof Integer) {
        return Types.INTEGER;
    } else if (object instanceof Time) {
        return Types.TIME;
    }/*from ww  w .ja  v  a  2 s .  c  om*/

    return Types.OTHER;
}

From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java

public java.util.Date parseDate(int type, String value, boolean useVariableDates) {
    if (StringUtils.isNotBlank(value)) {
        try {/*from  w ww . j a va  2 s. c  o m*/
            boolean useTimestamp = (type == Types.TIMESTAMP)
                    || (type == Types.DATE && getDdlBuilder().getDatabaseInfo().isDateOverridesToTimestamp());

            if (useVariableDates && value.startsWith("${curdate")) {
                long time = Long.parseLong(value.substring(10, value.length() - 1));
                if (value.substring(9, 10).equals("-")) {
                    time *= -1L;
                }
                time += System.currentTimeMillis();
                if (useTimestamp) {
                    return new Timestamp(time);
                }
                return new Date(time);
            } else {
                if (useTimestamp) {
                    return parseTimestamp(type, value);
                } else if (type == Types.TIME) {
                    if (value.indexOf(".") == 8) {
                        /*
                         * Firebird (at least) captures fractional seconds
                         * in time fields which need to be parsed by
                         * Timestamp.valueOf
                         */
                        return Timestamp.valueOf("1970-01-01 " + value);
                    } else {
                        return FormatUtils.parseDate(value, FormatUtils.TIME_PATTERNS);
                    }
                } else {
                    return FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS);
                }
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        return null;
    }
}

From source file:org.apache.sqoop.manager.OracleManager.java

@Override
public String datetimeToQueryString(String datetime, int columnType) {
    if (columnType == Types.TIMESTAMP) {
        return "TO_TIMESTAMP('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
    } else if (columnType == Types.DATE) {
        return "TO_DATE('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS')";
    } else {/*from   w  ww.  j ava 2 s. c  om*/
        String msg = "Column type is neither timestamp nor date!";
        LOG.error(msg);
        throw new RuntimeException(msg);
    }
}

From source file:org.apache.hadoop.chukwa.analysis.salsa.visualization.Heatmap.java

/**
 * Interfaces with database to get data and 
 * populate data structures for rendering
 *//*from w  w  w.jav a  2 s .  c o m*/
public HeatmapData getData() {
    // preliminary setup
    OfflineTimeHandler time_offline;
    TimeHandler time_online;
    long start, end, min, max;

    if (offline_use) {
        time_offline = new OfflineTimeHandler(param_map, this.timezone);
        start = time_offline.getStartTime();
        end = time_offline.getEndTime();
    } else {
        time_online = new TimeHandler(this.request, this.timezone);
        start = time_online.getStartTime();
        end = time_online.getEndTime();
    }

    DatabaseWriter dbw = new DatabaseWriter(this.cluster);

    // setup query
    String query;
    if (this.query_state != null && this.query_state.equals("read")) {
        query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["
                + table
                + "] where finish_time between '[start]' and '[end]' and (state_name like 'read_local' or state_name like 'read_remote')";
    } else if (this.query_state != null && this.query_state.equals("write")) {
        query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["
                + table
                + "] where finish_time between '[start]' and '[end]' and (state_name like 'write_local' or state_name like 'write_remote' or state_name like 'write_replicated')";
    } else {
        query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["
                + table + "] where finish_time between '[start]' and '[end]' and state_name like '"
                + query_state + "'";
    }
    Macro mp = new Macro(start, end, query);
    query = mp.toString() + " order by start_time";

    ArrayList<HashMap<String, Object>> events = new ArrayList<HashMap<String, Object>>();

    ResultSet rs = null;

    log.debug("Query: " + query);
    // run query, extract results
    try {
        rs = dbw.query(query);
        ResultSetMetaData rmeta = rs.getMetaData();
        int col = rmeta.getColumnCount();
        while (rs.next()) {
            HashMap<String, Object> event = new HashMap<String, Object>();
            long event_time = 0;
            for (int i = 1; i <= col; i++) {
                if (rmeta.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                    event.put(rmeta.getColumnName(i), rs.getTimestamp(i).getTime());
                } else {
                    event.put(rmeta.getColumnName(i), rs.getString(i));
                }
            }
            events.add(event);
        }
    } catch (SQLException ex) {
        // handle any errors
        log.error("SQLException: " + ex.getMessage());
        log.error("SQLState: " + ex.getSQLState());
        log.error("VendorError: " + ex.getErrorCode());
    } finally {
        dbw.close();
    }
    SimpleDateFormat format = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");

    log.info(events.size() + " results returned.");

    HashSet<String> host_set = new HashSet<String>();
    HashMap<String, Integer> host_indices = new HashMap<String, Integer>();
    HashMap<Integer, String> host_rev_indices = new HashMap<Integer, String>();

    // collect hosts, name unique hosts
    for (int i = 0; i < events.size(); i++) {
        HashMap<String, Object> event = events.get(i);
        String curr_host = (String) event.get("hostname");
        String other_host = (String) event.get("other_host");
        host_set.add(curr_host);
        host_set.add(other_host);
    }
    int num_hosts = host_set.size();

    Iterator<String> host_iter = host_set.iterator();
    for (int i = 0; i < num_hosts && host_iter.hasNext(); i++) {
        String curr_host = host_iter.next();
        host_indices.put(curr_host, new Integer(i));
        host_rev_indices.put(new Integer(i), curr_host);
    }

    System.out.println("Number of hosts: " + num_hosts);
    long stats[][] = new long[num_hosts][num_hosts];
    long count[][] = new long[num_hosts][num_hosts]; // used for averaging

    int start_millis = 0, end_millis = 0;

    // deliberate design choice to duplicate code PER possible operation
    // otherwise we have to do the mode check N times, for N states returned
    //
    // compute aggregate statistics
    log.info("Query statistic type: " + this.query_stat_type);
    if (this.query_stat_type.equals("transaction_count")) {
        for (int i = 0; i < events.size(); i++) {
            HashMap<String, Object> event = events.get(i);
            start = (Long) event.get("start_time");
            end = (Long) event.get("finish_time");
            start_millis = Integer.parseInt(((String) event.get("start_time_millis")));
            end_millis = Integer.parseInt(((String) event.get("finish_time_millis")));
            String cell = (String) event.get("state_name");
            String this_host = (String) event.get("hostname");
            String other_host = (String) event.get("other_host");
            int this_host_idx = host_indices.get(this_host).intValue();
            int other_host_idx = host_indices.get(other_host).intValue();

            // to, from
            stats[other_host_idx][this_host_idx] += 1;
        }
    } else if (this.query_stat_type.equals("avg_duration")) {
        for (int i = 0; i < events.size(); i++) {
            HashMap<String, Object> event = events.get(i);
            start = (Long) event.get("start_time");
            end = (Long) event.get("finish_time");
            start_millis = Integer.parseInt(((String) event.get("start_time_millis")));
            end_millis = Integer.parseInt(((String) event.get("finish_time_millis")));
            String cell = (String) event.get("state_name");
            String this_host = (String) event.get("hostname");
            String other_host = (String) event.get("other_host");
            int this_host_idx = host_indices.get(this_host).intValue();
            int other_host_idx = host_indices.get(other_host).intValue();

            long curr_val = end_millis - start_millis + ((end - start) * 1000);

            // to, from
            stats[other_host_idx][this_host_idx] += curr_val;
            count[other_host_idx][this_host_idx] += 1;
        }
        for (int i = 0; i < num_hosts; i++) {
            for (int j = 0; j < num_hosts; j++) {
                if (count[i][j] > 0)
                    stats[i][j] = stats[i][j] / count[i][j];
            }
        }
    } else if (this.query_stat_type.equals("avg_volume")) {
        for (int i = 0; i < events.size(); i++) {
            HashMap<String, Object> event = events.get(i);
            start = (Long) event.get("start_time");
            end = (Long) event.get("finish_time");
            start_millis = Integer.parseInt(((String) event.get("start_time_millis")));
            end_millis = Integer.parseInt(((String) event.get("finish_time_millis")));
            String cell = (String) event.get("state_name");
            String this_host = (String) event.get("hostname");
            String other_host = (String) event.get("other_host");
            int this_host_idx = host_indices.get(this_host).intValue();
            int other_host_idx = host_indices.get(other_host).intValue();

            long curr_val = Long.parseLong((String) event.get("bytes"));

            // to, from
            stats[other_host_idx][this_host_idx] += curr_val;
            count[other_host_idx][this_host_idx] += 1;
        }
        for (int i = 0; i < num_hosts; i++) {
            for (int j = 0; j < num_hosts; j++) {
                if (count[i][j] > 0)
                    stats[i][j] = stats[i][j] / count[i][j];
            }
        }
    } else if (this.query_stat_type.equals("total_duration")) {
        for (int i = 0; i < events.size(); i++) {
            HashMap<String, Object> event = events.get(i);
            start = (Long) event.get("start_time");
            end = (Long) event.get("finish_time");
            start_millis = Integer.parseInt(((String) event.get("start_time_millis")));
            end_millis = Integer.parseInt(((String) event.get("finish_time_millis")));
            String cell = (String) event.get("state_name");
            String this_host = (String) event.get("hostname");
            String other_host = (String) event.get("other_host");
            int this_host_idx = host_indices.get(this_host).intValue();
            int other_host_idx = host_indices.get(other_host).intValue();

            double curr_val = end_millis - start_millis + ((end - start) * 1000);

            // to, from
            stats[other_host_idx][this_host_idx] += curr_val;
        }
    } else if (this.query_stat_type.equals("total_volume")) {
        for (int i = 0; i < events.size(); i++) {
            HashMap<String, Object> event = events.get(i);
            start = (Long) event.get("start_time");
            end = (Long) event.get("finish_time");
            start_millis = Integer.parseInt(((String) event.get("start_time_millis")));
            end_millis = Integer.parseInt(((String) event.get("finish_time_millis")));
            String cell = (String) event.get("state_name");
            String this_host = (String) event.get("hostname");
            String other_host = (String) event.get("other_host");
            int this_host_idx = host_indices.get(this_host).intValue();
            int other_host_idx = host_indices.get(other_host).intValue();

            long curr_val = Long.parseLong((String) event.get("bytes"));

            // to, from
            stats[other_host_idx][this_host_idx] += curr_val;
        }
    }

    int[] permute = null;
    if (sort_nodes) {
        permute = hClust(stats);
        stats = doPermute(stats, permute);
    }

    Table agg_tab = new Table();
    agg_tab.addColumn("stat", long.class);
    min = Long.MAX_VALUE;
    max = Long.MIN_VALUE;
    agg_tab.addRows(num_hosts * num_hosts);

    // row-wise placement (row1, followed by row2, etc.)
    for (int i = 0; i < num_hosts; i++) {
        for (int j = 0; j < num_hosts; j++) {
            agg_tab.setLong((i * num_hosts) + j, "stat", stats[i][j]);
            if (stats[i][j] > max)
                max = stats[i][j];
            if (stats[i][j] > 0 && stats[i][j] < min)
                min = stats[i][j];
        }
    }
    if (min == Long.MAX_VALUE)
        min = 0;

    log.info(agg_tab);

    // collate data
    HeatmapData hd = new HeatmapData();
    hd.stats = new long[num_hosts][num_hosts];
    hd.stats = stats;
    hd.min = min;
    hd.max = max;
    hd.num_hosts = num_hosts;
    hd.agg_tab = agg_tab;

    this.add_info_extra = new String("\nState: " + this.prettyStateNames.get(this.query_state) + " ("
            + events.size() + " " + this.query_state + "'s [" + this.query_stat_type + "])\n"
            + "Plotted value range: [" + hd.min + "," + hd.max + "] (Zeros in black)");

    hd.hostnames = new String[num_hosts];
    for (int i = 0; i < num_hosts; i++) {
        String curr_host = host_rev_indices.get(new Integer(permute[i]));
        if (sort_nodes) {
            hd.hostnames[i] = new String(curr_host);
        } else {
            hd.hostnames[i] = new String(curr_host);
        }
    }

    return hd;
}

From source file:org.apache.torque.engine.database.model.TypeMap.java

/**
 * Initializes the SQL to Java map so that it
 * can be used by client code.//ww w.  j a  va 2  s. c  om
 */
public static synchronized void initialize() {
    if (!isInitialized) {
        // Create JDBC -> Java object mappings.
        jdbcToJavaObjectMap = new Hashtable();

        jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE);
        jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE);

        // Create JDBC -> native Java type mappings.
        jdbcToJavaNativeMap = new Hashtable();

        jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE);
        jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE);

        jdbcToJavaNativeObjectMap = new Hashtable();
        jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_OBJECT_TYPE);
        jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_OBJECT_TYPE);

        // Create JDBC -> Village asX() mappings.
        jdbcToVillageMethodMap = new Hashtable();

        jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD);
        jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD);

        jdbcToVillageObjectMethodMap = new Hashtable();
        jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_OBJECT_METHOD);
        jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_OBJECT_METHOD);

        // Create JDBC -> ParameterParser getX() mappings.
        jdbcToPPMethodMap = new Hashtable();

        jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD);
        jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD);

        // Create JDBC -> Java object mappings.
        torqueTypeToJdbcTypeMap = new Hashtable();

        Iterator iter = SchemaType.iterator();
        while (iter.hasNext()) {
            SchemaType type = (SchemaType) iter.next();
            torqueTypeToJdbcTypeMap.put(type, type);
        }
        torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR);
        torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER);

        // Create JDBC type code to torque type map.
        jdbcToTorqueTypeMap = new Hashtable();

        jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR);
        jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB);
        jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC);
        jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL);
        jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT);
        jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER);
        jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT);
        jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL);
        jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT);
        jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE);
        jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY);
        jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB);
        jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE);
        jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME);
        jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP);

        isInitialized = true;
    }
}

From source file:org.waarp.common.database.data.AbstractDbData.java

/**
 * Set the values from the Json node to the current object (no database access)
 * //w w  w .  j a va  2s. c om
 * @param node
 * @param ignorePrimaryKey
 *            True will ignore primaryKey from Json
 * @throws WaarpDatabaseSqlException
 */
public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException {
    DbValue[] list = allFields;
    if (ignorePrimaryKey) {
        list = otherFields;
    }
    for (DbValue value : list) {
        if (value.column.equalsIgnoreCase("UPDATEDINFO")) {
            continue;
        }
        JsonNode item = node.get(value.column);
        if (item != null && !item.isMissingNode() && !item.isNull()) {
            isSaved = false;
            switch (value.type) {
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
                value.setValue(item.asText());
                break;
            case Types.BIT:
                value.setValue(item.asBoolean());
                break;
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
                value.setValue(item.asInt());
                break;
            case Types.BIGINT:
                value.setValue(item.asLong());
                break;
            case Types.REAL:
            case Types.DOUBLE:
                value.setValue(item.asDouble());
                break;
            case Types.VARBINARY:
                try {
                    value.setValue(item.binaryValue());
                } catch (IOException e) {
                    throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e);
                }
                break;
            case Types.DATE:
                value.setValue(new Date(item.asLong()));
                break;
            case Types.TIMESTAMP:
                value.setValue(new Timestamp(item.asLong()));
                break;
            case Types.CLOB:
            case Types.BLOB:
            default:
                throw new WaarpDatabaseSqlException("Unsupported type: " + value.type);
            }
        }
    }
    setFromArray();
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize,
        int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction,
        boolean timestampToString) throws SQLException, IOException, StageException {
    Field field;//from  w  ww  .j a v  a2  s  .c  om
    if (userSpecifiedType != DataType.USE_COLUMN_TYPE) {
        // If user specifies the data type, overwrite the column type returned by database.
        field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex));
    } else {
        // All types as of JDBC 2.0 are here:
        // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY
        // Good source of recommended mappings is here:
        // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html
        switch (md.getColumnType(columnIndex)) {
        case Types.BIGINT:
            field = Field.create(Field.Type.LONG, rs.getObject(columnIndex));
            break;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
            field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex));
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex));
            break;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            field = Field.create(Field.Type.STRING, rs.getObject(columnIndex));
            break;
        case Types.CLOB:
        case Types.NCLOB:
            field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize));
            break;
        case Types.BLOB:
            field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize));
            break;
        case Types.DATE:
            field = Field.create(Field.Type.DATE, rs.getDate(columnIndex));
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex));
            field.setAttribute(HeaderAttributeConstants.ATTR_SCALE,
                    String.valueOf(rs.getMetaData().getScale(columnIndex)));
            field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION,
                    String.valueOf(rs.getMetaData().getPrecision(columnIndex)));
            break;
        case Types.DOUBLE:
            field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex));
            break;
        case Types.FLOAT:
        case Types.REAL:
            field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex));
            break;
        case Types.INTEGER:
            field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex));
            break;
        case Types.ROWID:
            field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString());
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex));
            break;
        case Types.TIME:
            field = Field.create(Field.Type.TIME, rs.getObject(columnIndex));
            break;
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnIndex);
            if (timestampToString) {
                field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString());
            } else {
                field = Field.create(Field.Type.DATETIME, timestamp);
                if (timestamp != null) {
                    final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT;
                    if (actualNanos > 0) {
                        field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos));
                    }
                }
            }
            break;
        // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc.
        case Types.TIME_WITH_TIMEZONE:
            OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class);
            field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant()));
            break;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class);
            field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime());
            break;
        //case Types.REF_CURSOR: // JDK8 only
        case Types.SQLXML:
        case Types.STRUCT:
        case Types.ARRAY:
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.NULL:
        case Types.OTHER:
        case Types.REF:
        default:
            if (unknownTypeAction == null) {
                return null;
            }
            switch (unknownTypeAction) {
            case STOP_PIPELINE:
                throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex),
                        md.getColumnLabel(columnIndex));
            case CONVERT_TO_STRING:
                Object value = rs.getObject(columnIndex);
                if (value != null) {
                    field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString());
                } else {
                    field = Field.create(Field.Type.STRING, null);
                }
                break;
            default:
                throw new IllegalStateException("Unknown action: " + unknownTypeAction);
            }
        }
    }

    return field;
}

From source file:org.apereo.portal.security.provider.RDBMPermissionImpl.java

/**
 * Set the params on the PreparedStatement and execute the update.
 * @param perm org.apereo.portal.security.IPermission
 * @param ps java.sql.PreparedStatement - the PreparedStatement for updating a Permission row.
 * @return int - the return code from the PreparedStatement
 * @exception Exception/*from ww w .  j  a v a 2s .  c o  m*/
 */
private int primUpdate(IPermission perm, PreparedStatement ps) throws Exception {
    java.sql.Timestamp ts = null;

    // UPDATE COLUMNS:

    ps.clearParameters();
    // TYPE:
    if (perm.getType() == null) {
        ps.setNull(1, Types.VARCHAR);
    } else {
        ps.setString(1, perm.getType());
    }
    // EFFECTIVE:
    if (perm.getEffective() == null) {
        ps.setNull(2, Types.TIMESTAMP);
    } else {
        ts = new java.sql.Timestamp(perm.getEffective().getTime());
        ps.setTimestamp(2, ts);
    }
    // EXPIRES:
    if (perm.getExpires() == null) {
        ps.setNull(3, Types.TIMESTAMP);
    } else {
        ts = new java.sql.Timestamp(perm.getExpires().getTime());
        ps.setTimestamp(3, ts);
    }
    // WHERE COLUMNS:
    ps.setString(4, perm.getOwner());
    ps.setInt(5, getPrincipalType(perm));
    ps.setString(6, getPrincipalKey(perm));
    ps.setString(7, perm.getActivity());
    ps.setString(8, perm.getTarget());
    if (log.isDebugEnabled())
        log.debug("RDBMPermissionImpl.primUpdate(): " + ps);

    return ps.executeUpdate();
}