Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

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

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabase.java

/**
 * Get the date for the last file list job.
 *
 * @param replica The replica to get the date for.
 * @return The date of the last missing files update for the replica. A null is returned if no last missing files
 * update has been performed./*from  w w  w. java2 s .  co m*/
 * @throws ArgumentNotValid If the replica is null.
 * @throws IllegalArgumentException If the Date of the Timestamp cannot be instantiated.
 */
@Override
public Date getDateOfLastMissingFilesUpdate(Replica replica) throws ArgumentNotValid, IllegalArgumentException {
    ArgumentNotValid.checkNotNull(replica, "Replica replica");
    Connection con = ArchiveDBConnection.get();
    String result = null;
    try {
        // sql for retrieving this replicafileinfo_guid.
        String sql = "SELECT filelist_updated FROM replica WHERE replica_id = ?";
        result = DBUtils.selectStringValue(con, sql, replica.getId());
    } finally {
        ArchiveDBConnection.release(con);
    }
    // return null if the field has no be set for this replica.
    if (result == null) {
        log.debug(
                "The 'filelist_updated' field has not been set, as no missing files update has been performed yet.");
        return null;
    } else {
        // Parse the timestamp into a date.
        return new Date(Timestamp.valueOf(result).getTime());
    }
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testProjectedDateTimestampUnequal() throws Exception {
    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
            + " (k1 INTEGER PRIMARY KEY, dates DATE, timestamps TIMESTAMP)";
    conn.createStatement().execute(ddl);
    // Differ by date
    String dml = "UPSERT INTO " + tableName + " VALUES (1," + "TO_DATE('2004-02-04 00:10:10'),"
            + "TO_TIMESTAMP('2006-04-12 00:10:10'))";
    conn.createStatement().execute(dml);
    // Differ by time
    dml = "UPSERT INTO " + tableName + " VALUES (2," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 15:10:20'))";
    conn.createStatement().execute(dml);
    // Differ by nanoseconds
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
    stmt.setInt(1, 3);// w w w  . ja  va  2s . co m
    stmt.setDate(2, new Date(1000));
    Timestamp ts = new Timestamp(1000);
    ts.setNanos(100);
    stmt.setTimestamp(3, ts);
    stmt.execute();
    // Equality
    dml = "UPSERT INTO " + tableName + " VALUES (4," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 00:10:10'))";
    conn.createStatement().execute(dml);
    conn.commit();

    ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(true, rs.getBoolean(1));
    assertFalse(rs.next());
}

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

@Override
public void insertLigplaatsen(final List<Ligplaats> ligplaatsen) throws DAOException {
    try {//from  w  ww. j  av  a  2 s. com
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.batchUpdate("insert into bag_ligplaats (" + "bag_ligplaats_id,"
                        + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel,"
                        + "ligplaats_status," + "ligplaats_geometrie," + "begindatum_tijdvak_geldigheid,"
                        + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum,"
                        + "bron_documentnummer," + "bag_nummeraanduiding_id"
                        + ") values (?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
                            @Override
                            public void setValues(PreparedStatement ps, int i) throws SQLException {
                                ps.setLong(1, ligplaatsen.get(i).getIdentificatie());
                                ps.setInt(2, ligplaatsen.get(i).getAanduidingRecordInactief().ordinal());
                                ps.setLong(3, ligplaatsen.get(i).getAanduidingRecordCorrectie());
                                ps.setInt(4, ligplaatsen.get(i).getOfficieel().ordinal());
                                ps.setInt(5, ligplaatsen.get(i).getLigplaatsStatus().ordinal());
                                ps.setString(6, ligplaatsen.get(i).getLigplaatsGeometrie());
                                ps.setTimestamp(7, new Timestamp(
                                        ligplaatsen.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                                if (ligplaatsen.get(i).getEinddatumTijdvakGeldigheid() == null)
                                    ps.setNull(8, Types.TIMESTAMP);
                                else
                                    ps.setTimestamp(8, new Timestamp(
                                            ligplaatsen.get(i).getEinddatumTijdvakGeldigheid().getTime()));
                                ps.setInt(9, ligplaatsen.get(i).getInOnderzoek().ordinal());
                                ps.setDate(10, new Date(ligplaatsen.get(i).getDocumentdatum().getTime()));
                                ps.setString(11, ligplaatsen.get(i).getDocumentnummer());
                                ps.setLong(12, ligplaatsen.get(i).getHoofdAdres());
                            }

                            @Override
                            public int getBatchSize() {
                                return ligplaatsen.size();
                            }
                        });
                insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaatsen);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting ligplaatsen", e);
    }
}

From source file:org.apache.carbondata.sdk.file.CarbonReaderTest.java

@Test
public void testReadUserSchema() throws IOException, InterruptedException {
    String timestampFormat = carbonProperties.getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
            CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT);
    String badRecordAction = carbonProperties.getProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION,
            CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION_DEFAULT);
    String badRecordLoc = carbonProperties.getProperty(CarbonCommonConstants.CARBON_BADRECORDS_LOC,
            CarbonCommonConstants.CARBON_BADRECORDS_LOC_DEFAULT_VAL);
    String rootPath = new File(this.getClass().getResource("/").getPath() + "../../").getCanonicalPath();
    String storeLocation = rootPath + "/target/";
    carbonProperties.addProperty(CarbonCommonConstants.CARBON_BADRECORDS_LOC, storeLocation)
            .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, "yyyy-MM-dd hh:mm:ss")
            .addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, "REDIRECT");
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    Field[] fields = new Field[9];
    fields[0] = new Field("stringField", DataTypes.STRING);
    fields[1] = new Field("shortField", DataTypes.SHORT);
    fields[2] = new Field("intField", DataTypes.INT);
    fields[3] = new Field("longField", DataTypes.LONG);
    fields[4] = new Field("doubleField", DataTypes.DOUBLE);
    fields[5] = new Field("boolField", DataTypes.BOOLEAN);
    fields[6] = new Field("dateField", DataTypes.DATE);
    fields[7] = new Field("timeField", DataTypes.TIMESTAMP);
    fields[8] = new Field("decimalField", DataTypes.createDecimalType(8, 2));

    try {/*  www .jav a2s . c o  m*/
        CarbonWriterBuilder builder = CarbonWriter.builder().outputPath(path).writtenBy("SDK_1.0.0");

        CarbonWriter writer = builder.withCsvInput(new Schema(fields)).build();

        for (int i = 0; i < 100; i++) {
            String[] row2 = new String[] { "robot" + (i % 10), String.valueOf(i), String.valueOf(i),
                    String.valueOf(Long.MAX_VALUE - i), String.valueOf((double) i / 2), String.valueOf(true),
                    "2019-03-02", "2019-02-12 03:03:34", "12.345" };
            writer.write(row2);
        }
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    File[] dataFiles1 = new File(path).listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith("carbondata");
        }
    });
    String versionDetails = CarbonSchemaReader.getVersionDetails(dataFiles1[0].getAbsolutePath());
    assertTrue(versionDetails.contains("SDK_1.0.0 in version: "));

    File[] dataFiles2 = new File(path).listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith("carbonindex");
        }
    });

    Schema schema = CarbonSchemaReader.readSchema(dataFiles2[0].getAbsolutePath()).asOriginOrder();
    // Transform the schema
    String[] strings = new String[schema.getFields().length];
    for (int i = 0; i < schema.getFields().length; i++) {
        strings[i] = (schema.getFields())[i].getFieldName();
    }

    File folder = new File(path);
    Assert.assertTrue(folder.exists());

    CarbonReader reader = CarbonReader.builder(path, "_temp").projection(strings).build();

    int i = 0;
    while (reader.hasNext()) {
        Object[] row = (Object[]) reader.readNextRow();
        int id = (int) row[2];
        Assert.assertEquals("robot" + (id % 10), row[0]);
        Assert.assertEquals(Short.parseShort(String.valueOf(id)), row[1]);
        Assert.assertEquals(Long.MAX_VALUE - id, row[3]);
        Assert.assertEquals((double) id / 2, row[4]);
        Assert.assertEquals(true, (boolean) row[5]);
        long day = 24L * 3600 * 1000;
        Assert.assertEquals("2019-03-02", new Date((day * ((int) row[6]))).toString());
        Assert.assertEquals("2019-02-12 03:03:34.0", new Timestamp((long) row[7] / 1000).toString());
        i++;
    }
    Assert.assertEquals(i, 100);

    reader.close();
    FileUtils.deleteDirectory(new File(path));
    carbonProperties.addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, timestampFormat);
    carbonProperties.addProperty(CarbonCommonConstants.CARBON_BAD_RECORDS_ACTION, badRecordAction);
    carbonProperties.addProperty(CarbonCommonConstants.CARBON_BADRECORDS_LOC, badRecordLoc);
}

From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabase.java

/**
 * Method for retrieving the date for the last update for corrupted files.
 * <p>//from  w w  w.  j  av a2 s.c  o  m
 * This method does not contact the replicas, it only retrieves the data from the last time the checksum was
 * retrieved.
 *
 * @param replica The replica to find the date for the latest update for corruption of files.
 * @return The date for the last checksum update. A null is returned if no wrong files update has been performed for
 * this replica.
 * @throws ArgumentNotValid If the replica is null.
 * @throws IllegalArgumentException If the Date of the Timestamp cannot be instantiated.
 */
@Override
public Date getDateOfLastWrongFilesUpdate(Replica replica) throws ArgumentNotValid, IllegalArgumentException {
    ArgumentNotValid.checkNotNull(replica, "Replica replica");
    Connection con = ArchiveDBConnection.get();
    String result = null;
    try {
        // The SQL statement for retrieving the date for last update of
        // checksum for the replica.
        final String sql = "SELECT checksum_updated FROM replica WHERE replica_id = ?";
        result = DBUtils.selectStringValue(con, sql, replica.getId());
    } finally {
        ArchiveDBConnection.release(con);
    }
    // return null if the field has no be set for this replica.
    if (result == null) {
        log.debug(
                "The 'checksum_updated' field has not been set, as no wrong files update has been performed yet.");
        return null;
    } else {
        // Parse the timestamp into a date.
        return new Date(Timestamp.valueOf(result).getTime());
    }
}

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

@Override
public void insertStandplaatsen(final List<Standplaats> standplaatsen) throws DAOException {
    try {//w  w  w.ja  v a  2s .com
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.batchUpdate("insert into bag_standplaats (" + "bag_standplaats_id,"
                        + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel,"
                        + "standplaats_status," + "standplaats_geometrie," + "begindatum_tijdvak_geldigheid,"
                        + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum,"
                        + "bron_documentnummer," + "bag_nummeraanduiding_id"
                        + ") values (?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
                            @Override
                            public void setValues(PreparedStatement ps, int i) throws SQLException {
                                ps.setLong(1, standplaatsen.get(i).getIdentificatie());
                                ps.setInt(2, standplaatsen.get(i).getAanduidingRecordInactief().ordinal());
                                ps.setLong(3, standplaatsen.get(i).getAanduidingRecordCorrectie());
                                ps.setInt(4, standplaatsen.get(i).getOfficieel().ordinal());
                                ps.setInt(5, standplaatsen.get(i).getStandplaatsStatus().ordinal());
                                ps.setString(6, standplaatsen.get(i).getStandplaatsGeometrie());
                                ps.setTimestamp(7, new Timestamp(
                                        standplaatsen.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                                if (standplaatsen.get(i).getEinddatumTijdvakGeldigheid() == null)
                                    ps.setNull(8, Types.TIMESTAMP);
                                else
                                    ps.setTimestamp(8, new Timestamp(
                                            standplaatsen.get(i).getEinddatumTijdvakGeldigheid().getTime()));
                                ps.setInt(9, standplaatsen.get(i).getInOnderzoek().ordinal());
                                ps.setDate(10, new Date(standplaatsen.get(i).getDocumentdatum().getTime()));
                                ps.setString(11, standplaatsen.get(i).getDocumentnummer());
                                ps.setLong(12, standplaatsen.get(i).getHoofdAdres());
                            }

                            @Override
                            public int getBatchSize() {
                                return standplaatsen.size();
                            }
                        });
                insertNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaatsen);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting standplaatsen", e);
    }
}

From source file:eionet.meta.service.RDFVocabularyImportServiceTest.java

/**
 * In this test, single concept RDF is imported. concept is a non existing concept to be imported with data elements (both rdf
 * and dd namespaces)/* w ww. j av a2s .  c o m*/
 *
 * @throws Exception
 */
@Test
@Rollback
public void testIfNewConceptAddedWithDDNamespace() throws Exception {
    // get vocabulary folder
    VocabularyFolder vocabularyFolder = vocabularyService.getVocabularyFolder(TEST_VALID_VOCABULARY_ID);

    // get initial values of concepts with attributes
    List<VocabularyConcept> concepts = getVocabularyConceptsWithAttributes(vocabularyFolder);

    // get reader for RDF file
    Reader reader = getReaderFromResource("rdf_import/rdf_import_test_11.rdf");

    // import RDF into database
    vocabularyImportService.importRdfIntoVocabulary(reader, vocabularyFolder, false, false);
    Assert.assertFalse("Transaction rolled back (unexpected)",
            transactionManager.getTransaction(null).isRollbackOnly());

    // manually create values of new concept for comparison
    VocabularyConcept vc11 = new VocabularyConcept();
    // vc11.setId(11); //this field will be updated after re-querying
    vc11.setIdentifier("rdf_test_concept_5");
    vc11.setLabel("rdf_test_concept_label_5");
    vc11.setDefinition("rdf_test_concept_def_5");
    vc11.setStatus(StandardGenericStatus.VALID);
    vc11.setStatusModified(new Date(System.currentTimeMillis()));
    vc11.setAcceptedDate(new Date(System.currentTimeMillis()));

    // create element attributes (there is only one concept)
    List<List<DataElement>> elementAttributes = new ArrayList<List<DataElement>>();
    DataElement elem = null;
    String identifier = null;
    int dataElemId = -1;
    List<DataElement> elements = null;

    // AnotherCode
    identifier = "AnotherCode";
    dataElemId = 2;
    elements = new ArrayList<DataElement>();
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("HCO2_rdf_test_concept_5");
    elements.add(elem);
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("2_HCO2_rdf_test_concept_5");
    elements.add(elem);
    elementAttributes.add(elements);

    // geo:lat
    identifier = "geo:lat";
    dataElemId = 5;
    elements = new ArrayList<DataElement>();
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("geo_lat_concept_5");
    elements.add(elem);
    elementAttributes.add(elements);

    // skos:prefLabel
    identifier = "skos:prefLabel";
    dataElemId = 8;
    elements = new ArrayList<DataElement>();
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("bg_rdf_test_concept_5");
    elem.setAttributeLanguage("bg");
    elements.add(elem);
    elementAttributes.add(elements);

    // skos:definition
    identifier = "skos:definition";
    dataElemId = 9;
    elements = new ArrayList<DataElement>();
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("de_rdf_test_concept_5");
    elem.setAttributeLanguage("de");
    elements.add(elem);
    elem = new DataElement();
    elem.setId(dataElemId);
    elem.setIdentifier(identifier);
    elem.setAttributeValue("en_rdf_test_concept_5");
    elem.setAttributeLanguage("en");
    elements.add(elem);
    elementAttributes.add(elements);

    vc11.setElementAttributes(elementAttributes);
    concepts.add(vc11);

    // get updated values of concepts with attributes
    List<VocabularyConcept> updatedConcepts = getVocabularyConceptsWithAttributes(vocabularyFolder);
    Assert.assertEquals("Updated Concepts does not include 4 vocabulary concepts", updatedConcepts.size(), 4);

    // last object should be the inserted one, so use it is id to set (all other fields are updated manually)
    vc11.setId(updatedConcepts.get(3).getId());

    // compare manually updated objects with queried ones (after import operation)
    ReflectionAssert.assertReflectionEquals(concepts, updatedConcepts, ReflectionComparatorMode.LENIENT_DATES,
            ReflectionComparatorMode.LENIENT_ORDER);
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testProjectedDateUnsignedTimestampCompare() throws Exception {
    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
            + " (k1 INTEGER PRIMARY KEY, dates DATE, timestamps UNSIGNED_TIMESTAMP)";
    conn.createStatement().execute(ddl);
    // Differ by date
    String dml = "UPSERT INTO " + tableName + " VALUES (1," + "TO_DATE('2004-02-04 00:10:10'),"
            + "TO_TIMESTAMP('2006-04-12 00:10:10'))";
    conn.createStatement().execute(dml);
    // Differ by time
    dml = "UPSERT INTO " + tableName + " VALUES (2," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 15:10:20'))";
    conn.createStatement().execute(dml);
    // Differ by nanoseconds
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
    stmt.setInt(1, 3);//  w w w. j a  v a  2  s .c  om
    stmt.setDate(2, new Date(1000));
    Timestamp ts = new Timestamp(1000);
    ts.setNanos(100);
    stmt.setTimestamp(3, ts);
    stmt.execute();
    // Equality
    dml = "UPSERT INTO " + tableName + " VALUES (4," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 00:10:10'))";
    conn.createStatement().execute(dml);
    conn.commit();

    ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(true, rs.getBoolean(1));
    assertFalse(rs.next());
}

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

@Override
public void update(final Woonplaats woonplaats) throws DAOException {
    try {//from  w  ww  .ja  v a 2  s . c  o  m
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("update bag_woonplaats set"
                        + " aanduiding_record_inactief = ?," + " woonplaats_naam = ?,"
                        + " woonplaats_geometrie = ?," + " officieel = ?,"
                        + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                        + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " woonplaats_status = ?"
                        + " where bag_woonplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?");
                ps.setInt(1, woonplaats.getAanduidingRecordInactief().ordinal());
                ps.setString(2, woonplaats.getWoonplaatsNaam());
                ps.setString(3, woonplaats.getWoonplaatsGeometrie());
                ps.setInt(4, woonplaats.getOfficieel().ordinal());
                if (woonplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(5, Types.TIMESTAMP);
                else
                    ps.setTimestamp(5, new Timestamp(woonplaats.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(6, woonplaats.getInOnderzoek().ordinal());
                ps.setDate(7, new Date(woonplaats.getDocumentdatum().getTime()));
                ps.setString(8, woonplaats.getDocumentnummer());
                ps.setInt(9, woonplaats.getWoonplaatsStatus().ordinal());
                ps.setLong(10, woonplaats.getIdentificatie());
                ps.setLong(11, woonplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(12, new Timestamp(woonplaats.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating woonplaats: " + woonplaats.getIdentificatie(), e);
    }
}

From source file:org.apache.phoenix.query.BaseTest.java

protected static void initATableValues(String tenantId, byte[][] splits, Date date, Long ts, String url)
        throws Exception {
    if (ts == null) {
        ensureTableCreated(url, ATABLE_NAME, splits);
    } else {/*from   w  ww  .jav  a 2  s  .c om*/
        ensureTableCreated(url, ATABLE_NAME, splits, ts - 5);
    }

    Properties props = new Properties();
    if (ts != null) {
        props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts - 3));
    }
    Connection conn = DriverManager.getConnection(url, props);
    try {
        // Insert all rows at ts
        PreparedStatement stmt = conn.prepareStatement("upsert into " + "ATABLE(" + "    ORGANIZATION_ID, "
                + "    ENTITY_ID, " + "    A_STRING, " + "    B_STRING, " + "    A_INTEGER, " + "    A_DATE, "
                + "    X_DECIMAL, " + "    X_LONG, " + "    X_INTEGER," + "    Y_INTEGER," + "    A_BYTE,"
                + "    A_SHORT," + "    A_FLOAT," + "    A_DOUBLE," + "    A_UNSIGNED_FLOAT,"
                + "    A_UNSIGNED_DOUBLE)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        stmt.setString(1, tenantId);
        stmt.setString(2, ROW1);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 1);
        stmt.setDate(6, date);
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 1);
        stmt.setShort(12, (short) 128);
        stmt.setFloat(13, 0.01f);
        stmt.setDouble(14, 0.0001);
        stmt.setFloat(15, 0.01f);
        stmt.setDouble(16, 0.0001);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW2);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 2);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 2);
        stmt.setShort(12, (short) 129);
        stmt.setFloat(13, 0.02f);
        stmt.setDouble(14, 0.0002);
        stmt.setFloat(15, 0.02f);
        stmt.setDouble(16, 0.0002);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW3);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 3);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 3);
        stmt.setShort(12, (short) 130);
        stmt.setFloat(13, 0.03f);
        stmt.setDouble(14, 0.0003);
        stmt.setFloat(15, 0.03f);
        stmt.setDouble(16, 0.0003);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW4);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 4);
        stmt.setDate(6, date == null ? null : date);
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 4);
        stmt.setShort(12, (short) 131);
        stmt.setFloat(13, 0.04f);
        stmt.setDouble(14, 0.0004);
        stmt.setFloat(15, 0.04f);
        stmt.setDouble(16, 0.0004);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW5);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 5);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 5);
        stmt.setShort(12, (short) 132);
        stmt.setFloat(13, 0.05f);
        stmt.setDouble(14, 0.0005);
        stmt.setFloat(15, 0.05f);
        stmt.setDouble(16, 0.0005);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW6);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 6);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 6);
        stmt.setShort(12, (short) 133);
        stmt.setFloat(13, 0.06f);
        stmt.setDouble(14, 0.0006);
        stmt.setFloat(15, 0.06f);
        stmt.setDouble(16, 0.0006);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW7);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 7);
        stmt.setDate(6, date == null ? null : date);
        stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
        stmt.setLong(8, 5L);
        stmt.setInt(9, 5);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 7);
        stmt.setShort(12, (short) 134);
        stmt.setFloat(13, 0.07f);
        stmt.setDouble(14, 0.0007);
        stmt.setFloat(15, 0.07f);
        stmt.setDouble(16, 0.0007);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW8);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 8);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, BigDecimal.valueOf(3.9));
        long l = Integer.MIN_VALUE - 1L;
        assert (l < Integer.MIN_VALUE);
        stmt.setLong(8, l);
        stmt.setInt(9, 4);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 8);
        stmt.setShort(12, (short) 135);
        stmt.setFloat(13, 0.08f);
        stmt.setDouble(14, 0.0008);
        stmt.setFloat(15, 0.08f);
        stmt.setDouble(16, 0.0008);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW9);
        stmt.setString(3, C_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 9);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, BigDecimal.valueOf(3.3));
        l = Integer.MAX_VALUE + 1L;
        assert (l > Integer.MAX_VALUE);
        stmt.setLong(8, l);
        stmt.setInt(9, 3);
        stmt.setInt(10, 300);
        stmt.setByte(11, (byte) 9);
        stmt.setShort(12, (short) 0);
        stmt.setFloat(13, 0.09f);
        stmt.setDouble(14, 0.0009);
        stmt.setFloat(15, 0.09f);
        stmt.setDouble(16, 0.0009);
        stmt.execute();

        conn.commit();
    } finally {
        conn.close();
    }
}