List of usage examples for java.sql Date Date
public Date(long date)
From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabase.java
/** * Method for inserting a line of Admin.Data into the database. It is assumed that it is a '0.4' admin.data line. * * @param line The line to insert into the database. * @return Whether the line was valid./*w ww . ja va 2 s.c o m*/ * @throws ArgumentNotValid If the line is null. If it is empty, then it is logged. */ public boolean insertAdminEntry(String line) throws ArgumentNotValid { ArgumentNotValid.checkNotNull(line, "String line"); Connection con = ArchiveDBConnection.get(); log.trace("Insert admin entry begun"); final int lengthFirstPart = 4; final int lengthOtherParts = 3; try { // split into parts. First contains String[] split = line.split(" , "); // Retrieve the basic entry data. String[] entryData = split[0].split(" "); // Check if enough elements if (entryData.length < lengthFirstPart) { log.warn("Bad line in Admin.data: {}", line); return false; } String filename = entryData[0]; String checksum = entryData[1]; long fileId = ReplicaCacheHelpers.retrieveIdForFile(filename, con); // If the fileId is -1, then the file is not within the file table. // Thus insert it and retrieve the id. if (fileId == -1) { fileId = ReplicaCacheHelpers.insertFileIntoDB(filename, con); } log.trace("Step 1 completed (file created in database)."); // go through the replica specifics. for (int i = 1; i < split.length; i++) { String[] repInfo = split[i].split(" "); // check if correct size if (repInfo.length < lengthOtherParts) { log.warn("Bad replica information '{}' in line '{}'", split[i], line); continue; } // retrieve the data for this replica String replicaId = Channels.retrieveReplicaFromIdentifierChannel(repInfo[0]).getId(); ReplicaStoreState replicaUploadStatus = ReplicaStoreState.valueOf(repInfo[1]); Date replicaDate = new Date(Long.parseLong(repInfo[2])); // retrieve the guid of the replicafileinfo. long guid = ReplicaCacheHelpers.retrieveReplicaFileInfoGuid(fileId, replicaId, con); // Update the replicaFileInfo with the information. ReplicaCacheHelpers.updateReplicaFileInfo(guid, checksum, replicaDate, replicaUploadStatus, con); } } catch (IllegalState e) { log.warn("Received IllegalState exception while parsing.", e); return false; } finally { ArchiveDBConnection.release(con); } log.trace("Insert admin entry finished"); return true; }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Verblijfsobject verblijfsobject) throws DAOException { try {/*w w w . ja v 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("update bag_verblijfsobject set" + " aanduiding_record_inactief = ?," + " officieel = ?," + " verblijfsobject_geometrie = ?," + " oppervlakte_verblijfsobject = ?," + " verblijfsobject_status = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " bag_nummeraanduiding_id = ?" + " where bag_verblijfsobject_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, verblijfsobject.getAanduidingRecordInactief().ordinal()); ps.setInt(2, verblijfsobject.getOfficieel().ordinal()); ps.setString(3, verblijfsobject.getVerblijfsobjectGeometrie()); ps.setInt(4, verblijfsobject.getOppervlakteVerblijfsobject()); ps.setInt(5, verblijfsobject.getVerblijfsobjectStatus().ordinal()); if (verblijfsobject.getEinddatumTijdvakGeldigheid() == null) ps.setNull(6, Types.TIMESTAMP); else ps.setTimestamp(6, new Timestamp(verblijfsobject.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(7, verblijfsobject.getInOnderzoek().ordinal()); ps.setDate(8, new Date(verblijfsobject.getDocumentdatum().getTime())); ps.setString(9, verblijfsobject.getDocumentnummer()); ps.setLong(10, verblijfsobject.getHoofdAdres()); ps.setLong(11, verblijfsobject.getIdentificatie()); ps.setLong(12, verblijfsobject.getAanduidingRecordCorrectie()); ps.setTimestamp(13, new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); deleteGebruikersdoelen(verblijfsobject); insertGebruikersdoelen(verblijfsobject); deleteNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject); insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject); deleteGerelateerdePanden(verblijfsobject); insertGerelateerdePanden(verblijfsobject); } }); } catch (DataAccessException e) { throw new DAOException("Error updating verblijfsobject: " + verblijfsobject.getIdentificatie(), e); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Ligplaats ligplaats) throws DAOException { try {// www. j ava 2s . c om 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( "update bag_ligplaats set" + " aanduiding_record_inactief = ?," + " officieel = ?," + " ligplaats_status = ?," + " ligplaats_geometrie = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " bag_nummeraanduiding_id = ?" + " where bag_ligplaats_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, ligplaats.getAanduidingRecordInactief().ordinal()); ps.setInt(2, ligplaats.getOfficieel().ordinal()); ps.setInt(3, ligplaats.getLigplaatsStatus().ordinal()); ps.setString(4, ligplaats.getLigplaatsGeometrie()); if (ligplaats.getEinddatumTijdvakGeldigheid() == null) ps.setNull(5, Types.TIMESTAMP); else ps.setTimestamp(5, new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(6, ligplaats.getInOnderzoek().ordinal()); ps.setDate(7, new Date(ligplaats.getDocumentdatum().getTime())); ps.setString(8, ligplaats.getDocumentnummer()); ps.setLong(9, ligplaats.getHoofdAdres()); ps.setLong(10, ligplaats.getIdentificatie()); ps.setLong(11, ligplaats.getAanduidingRecordCorrectie()); ps.setTimestamp(12, new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); deleteNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats); insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats); } }); } catch (DataAccessException e) { throw new DAOException("Error updating ligplaats: " + ligplaats.getIdentificatie(), e); } }
From source file:org.apache.phoenix.query.BaseTest.java
protected static void initJoinTableValues(String url, byte[][] splits, Long ts) throws Exception { if (ts == null) { ensureTableCreated(url, JOIN_CUSTOMER_TABLE_FULL_NAME, splits); ensureTableCreated(url, JOIN_ITEM_TABLE_FULL_NAME, splits); ensureTableCreated(url, JOIN_SUPPLIER_TABLE_FULL_NAME, splits); ensureTableCreated(url, JOIN_ORDER_TABLE_FULL_NAME, splits); } else {/* w ww . j ava 2 s. c om*/ ensureTableCreated(url, JOIN_CUSTOMER_TABLE_FULL_NAME, splits, ts - 2); ensureTableCreated(url, JOIN_ITEM_TABLE_FULL_NAME, splits, ts - 2); ensureTableCreated(url, JOIN_SUPPLIER_TABLE_FULL_NAME, splits, ts - 2); ensureTableCreated(url, JOIN_ORDER_TABLE_FULL_NAME, splits, ts - 2); } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); if (ts != null) { props.setProperty(CURRENT_SCN_ATTRIB, ts.toString()); } Connection conn = DriverManager.getConnection(url, props); try { conn.createStatement().execute("CREATE SEQUENCE my.seq"); // Insert into customer table PreparedStatement stmt = conn.prepareStatement("upsert into " + JOIN_CUSTOMER_TABLE_FULL_NAME + " (\"customer_id\", " + " NAME, " + " PHONE, " + " ADDRESS, " + " LOC_ID, " + " DATE) " + "values (?, ?, ?, ?, ?, ?)"); stmt.setString(1, "0000000001"); stmt.setString(2, "C1"); stmt.setString(3, "999-999-1111"); stmt.setString(4, "101 XXX Street"); stmt.setString(5, "10001"); stmt.setDate(6, new Date(format.parse("2013-11-01 10:20:36").getTime())); stmt.execute(); stmt.setString(1, "0000000002"); stmt.setString(2, "C2"); stmt.setString(3, "999-999-2222"); stmt.setString(4, "202 XXX Street"); stmt.setString(5, null); stmt.setDate(6, new Date(format.parse("2013-11-25 16:45:07").getTime())); stmt.execute(); stmt.setString(1, "0000000003"); stmt.setString(2, "C3"); stmt.setString(3, "999-999-3333"); stmt.setString(4, "303 XXX Street"); stmt.setString(5, null); stmt.setDate(6, new Date(format.parse("2013-11-25 10:06:29").getTime())); stmt.execute(); stmt.setString(1, "0000000004"); stmt.setString(2, "C4"); stmt.setString(3, "999-999-4444"); stmt.setString(4, "404 XXX Street"); stmt.setString(5, "10004"); stmt.setDate(6, new Date(format.parse("2013-11-22 14:22:56").getTime())); stmt.execute(); stmt.setString(1, "0000000005"); stmt.setString(2, "C5"); stmt.setString(3, "999-999-5555"); stmt.setString(4, "505 XXX Street"); stmt.setString(5, "10005"); stmt.setDate(6, new Date(format.parse("2013-11-27 09:37:50").getTime())); stmt.execute(); stmt.setString(1, "0000000006"); stmt.setString(2, "C6"); stmt.setString(3, "999-999-6666"); stmt.setString(4, "606 XXX Street"); stmt.setString(5, "10001"); stmt.setDate(6, new Date(format.parse("2013-11-01 10:20:36").getTime())); stmt.execute(); // Insert into item table stmt = conn.prepareStatement("upsert into " + JOIN_ITEM_TABLE_FULL_NAME + " (\"item_id\", " + " NAME, " + " PRICE, " + " DISCOUNT1, " + " DISCOUNT2, " + " \"supplier_id\", " + " DESCRIPTION) " + "values (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, "0000000001"); stmt.setString(2, "T1"); stmt.setInt(3, 100); stmt.setInt(4, 5); stmt.setInt(5, 10); stmt.setString(6, "0000000001"); stmt.setString(7, "Item T1"); stmt.execute(); stmt.setString(1, "0000000002"); stmt.setString(2, "T2"); stmt.setInt(3, 200); stmt.setInt(4, 5); stmt.setInt(5, 8); stmt.setString(6, "0000000001"); stmt.setString(7, "Item T2"); stmt.execute(); stmt.setString(1, "0000000003"); stmt.setString(2, "T3"); stmt.setInt(3, 300); stmt.setInt(4, 8); stmt.setInt(5, 12); stmt.setString(6, "0000000002"); stmt.setString(7, "Item T3"); stmt.execute(); stmt.setString(1, "0000000004"); stmt.setString(2, "T4"); stmt.setInt(3, 400); stmt.setInt(4, 6); stmt.setInt(5, 10); stmt.setString(6, "0000000002"); stmt.setString(7, "Item T4"); stmt.execute(); stmt.setString(1, "0000000005"); stmt.setString(2, "T5"); stmt.setInt(3, 500); stmt.setInt(4, 8); stmt.setInt(5, 15); stmt.setString(6, "0000000005"); stmt.setString(7, "Item T5"); stmt.execute(); stmt.setString(1, "0000000006"); stmt.setString(2, "T6"); stmt.setInt(3, 600); stmt.setInt(4, 8); stmt.setInt(5, 15); stmt.setString(6, "0000000006"); stmt.setString(7, "Item T6"); stmt.execute(); stmt.setString(1, "invalid001"); stmt.setString(2, "INVALID-1"); stmt.setInt(3, 0); stmt.setInt(4, 0); stmt.setInt(5, 0); stmt.setString(6, "0000000000"); stmt.setString(7, "Invalid item for join test"); stmt.execute(); // Insert into supplier table stmt = conn.prepareStatement("upsert into " + JOIN_SUPPLIER_TABLE_FULL_NAME + " (\"supplier_id\", " + " NAME, " + " PHONE, " + " ADDRESS, " + " LOC_ID) " + "values (?, ?, ?, ?, ?)"); stmt.setString(1, "0000000001"); stmt.setString(2, "S1"); stmt.setString(3, "888-888-1111"); stmt.setString(4, "101 YYY Street"); stmt.setString(5, "10001"); stmt.execute(); stmt.setString(1, "0000000002"); stmt.setString(2, "S2"); stmt.setString(3, "888-888-2222"); stmt.setString(4, "202 YYY Street"); stmt.setString(5, "10002"); stmt.execute(); stmt.setString(1, "0000000003"); stmt.setString(2, "S3"); stmt.setString(3, "888-888-3333"); stmt.setString(4, "303 YYY Street"); stmt.setString(5, null); stmt.execute(); stmt.setString(1, "0000000004"); stmt.setString(2, "S4"); stmt.setString(3, "888-888-4444"); stmt.setString(4, "404 YYY Street"); stmt.setString(5, null); stmt.execute(); stmt.setString(1, "0000000005"); stmt.setString(2, "S5"); stmt.setString(3, "888-888-5555"); stmt.setString(4, "505 YYY Street"); stmt.setString(5, "10005"); stmt.execute(); stmt.setString(1, "0000000006"); stmt.setString(2, "S6"); stmt.setString(3, "888-888-6666"); stmt.setString(4, "606 YYY Street"); stmt.setString(5, "10006"); stmt.execute(); // Insert into order table stmt = conn.prepareStatement("upsert into " + JOIN_ORDER_TABLE_FULL_NAME + " (\"order_id\", " + " \"customer_id\", " + " \"item_id\", " + " PRICE, " + " QUANTITY," + " DATE) " + "values (?, ?, ?, ?, ?, ?)"); stmt.setString(1, "000000000000001"); stmt.setString(2, "0000000004"); stmt.setString(3, "0000000001"); stmt.setInt(4, 100); stmt.setInt(5, 1000); stmt.setTimestamp(6, new Timestamp(format.parse("2013-11-22 14:22:56").getTime())); stmt.execute(); stmt.setString(1, "000000000000002"); stmt.setString(2, "0000000003"); stmt.setString(3, "0000000006"); stmt.setInt(4, 552); stmt.setInt(5, 2000); stmt.setTimestamp(6, new Timestamp(format.parse("2013-11-25 10:06:29").getTime())); stmt.execute(); stmt.setString(1, "000000000000003"); stmt.setString(2, "0000000002"); stmt.setString(3, "0000000002"); stmt.setInt(4, 190); stmt.setInt(5, 3000); stmt.setTimestamp(6, new Timestamp(format.parse("2013-11-25 16:45:07").getTime())); stmt.execute(); stmt.setString(1, "000000000000004"); stmt.setString(2, "0000000004"); stmt.setString(3, "0000000006"); stmt.setInt(4, 510); stmt.setInt(5, 4000); stmt.setTimestamp(6, new Timestamp(format.parse("2013-11-26 13:26:04").getTime())); stmt.execute(); stmt.setString(1, "000000000000005"); stmt.setString(2, "0000000005"); stmt.setString(3, "0000000003"); stmt.setInt(4, 264); stmt.setInt(5, 5000); stmt.setTimestamp(6, new Timestamp(format.parse("2013-11-27 09:37:50").getTime())); stmt.execute(); conn.commit(); } finally { conn.close(); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Standplaats standplaats) throws DAOException { try {/*from ww w. j a v a2 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("update bag_standplaats set" + " aanduiding_record_inactief = ?," + " officieel = ?," + " standplaats_status = ?," + " standplaats_geometrie = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " bag_nummeraanduiding_id = ?" + " where bag_standplaats_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, standplaats.getAanduidingRecordInactief().ordinal()); ps.setInt(2, standplaats.getOfficieel().ordinal()); ps.setInt(3, standplaats.getStandplaatsStatus().ordinal()); ps.setString(4, standplaats.getStandplaatsGeometrie()); if (standplaats.getEinddatumTijdvakGeldigheid() == null) ps.setNull(5, Types.TIMESTAMP); else ps.setTimestamp(5, new Timestamp(standplaats.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(6, standplaats.getInOnderzoek().ordinal()); ps.setDate(7, new Date(standplaats.getDocumentdatum().getTime())); ps.setString(8, standplaats.getDocumentnummer()); ps.setLong(9, standplaats.getHoofdAdres()); ps.setLong(10, standplaats.getIdentificatie()); ps.setLong(11, standplaats.getAanduidingRecordCorrectie()); ps.setTimestamp(12, new Timestamp(standplaats.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); deleteNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats); insertNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats); } }); } catch (DataAccessException e) { throw new DAOException("Error updating standplaats: " + standplaats.getIdentificatie(), e); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Woonplaats origineel, final Woonplaats wijziging) throws DAOException { try {//from www. ja va 2 s .co m jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_woonplaats set" + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?," + " 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, wijziging.getAanduidingRecordInactief().ordinal()); ps.setLong(2, wijziging.getAanduidingRecordCorrectie()); ps.setString(3, wijziging.getWoonplaatsNaam()); ps.setString(4, wijziging.getWoonplaatsGeometrie()); ps.setInt(5, wijziging.getOfficieel().ordinal()); if (wijziging.getEinddatumTijdvakGeldigheid() == null) ps.setNull(6, Types.TIMESTAMP); else ps.setTimestamp(6, new Timestamp(wijziging.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(7, wijziging.getInOnderzoek().ordinal()); ps.setDate(8, new Date(wijziging.getDocumentdatum().getTime())); ps.setString(9, wijziging.getDocumentnummer()); ps.setInt(10, wijziging.getWoonplaatsStatus().ordinal()); ps.setLong(11, origineel.getIdentificatie()); ps.setLong(12, origineel.getAanduidingRecordCorrectie()); ps.setTimestamp(13, new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating woonplaats: " + origineel.getIdentificatie(), e); } }
From source file:com.ichi2.anki.SyncClient.java
/** * Anki Desktop -> libanki/anki/sync.py, SyncTools - needFullSync * /*from w ww.j a v a 2 s. co m*/ * @param sums * @return */ @SuppressWarnings("unchecked") public boolean needFullSync(JSONArray sums) { Log.i(AnkiDroidApp.TAG, "needFullSync - lastSync = " + mDeck.getLastSync()); if (mDeck.getLastSync() <= 0) { Log.i(AnkiDroidApp.TAG, "deck.lastSync <= 0"); return true; } int len = sums.length(); for (int i = 0; i < len; i++) { try { JSONObject summary = sums.getJSONObject(i); Iterator keys = summary.keys(); while (keys.hasNext()) { String key = (String) keys.next(); JSONArray l = (JSONArray) summary.get(key); Log.i(AnkiDroidApp.TAG, "Key " + key + ", length = " + l.length()); if (l.length() > 500) { Log.i(AnkiDroidApp.TAG, "Length of key > 500"); return true; } } } catch (JSONException e) { Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } } AnkiDb ankiDB = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()); if (ankiDB.queryScalar("SELECT count() FROM reviewHistory WHERE time > " + mDeck.getLastSync()) > 500) { Log.i(AnkiDroidApp.TAG, "reviewHistory since lastSync > 500"); return true; } Date lastDay = new Date(java.lang.Math.max(0, (long) (mDeck.getLastSync() - 60 * 60 * 24) * 1000)); Log.i(AnkiDroidApp.TAG, "lastDay = " + lastDay.toString() + ", lastDayInMillis = " + lastDay.getTime()); Log.i(AnkiDroidApp.TAG, "Count stats = " + ankiDB.queryScalar("SELECT count() FROM stats WHERE day >= \"" + lastDay.toString() + "\"")); if (ankiDB.queryScalar("SELECT count() FROM stats WHERE day >= \"" + lastDay.toString() + "\"") > 100) { Log.i(AnkiDroidApp.TAG, "stats since lastDay > 100"); return true; } return false; }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testDateSubtractionCompareNumber() throws Exception { String tablename = generateUniqueName(); String tenantId = getOrganizationId(); String query = "SELECT feature FROM " + tablename + " WHERE organization_id = ? and ? - \"DATE\" > 3"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try {//w w w.j av a2s.c om Date startDate = new Date(System.currentTimeMillis()); Date endDate = new Date(startDate.getTime() + 6 * QueryConstants.MILLIS_IN_DAY); initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); statement.setDate(2, endDate); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals("A", rs.getString(1)); assertTrue(rs.next()); assertEquals("B", rs.getString(1)); assertFalse(rs.next()); } finally { conn.close(); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final OpenbareRuimte origineel, final OpenbareRuimte mutation) throws DAOException { try {/*from w ww.ja va 2 s. c o m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_openbare_ruimte set" + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?," + " openbare_ruimte_naam = ?," + " officieel = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " openbare_ruimte_type = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " openbareruimte_status = ?," + " bag_woonplaats_id = ?," + " verkorte_openbare_ruimte_naam = ?" + " where bag_openbare_ruimte_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal()); ps.setLong(2, mutation.getAanduidingRecordCorrectie()); ps.setString(3, mutation.getOpenbareRuimteNaam()); ps.setInt(4, mutation.getOfficieel().ordinal()); if (mutation.getEinddatumTijdvakGeldigheid() == null) ps.setNull(5, Types.TIMESTAMP); else ps.setTimestamp(5, new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(6, mutation.getInOnderzoek().ordinal()); ps.setInt(7, mutation.getOpenbareRuimteType().ordinal()); ps.setDate(8, new Date(mutation.getDocumentdatum().getTime())); ps.setString(9, mutation.getDocumentnummer()); ps.setInt(10, mutation.getOpenbareruimteStatus().ordinal()); ps.setLong(11, mutation.getGerelateerdeWoonplaats()); ps.setString(12, mutation.getVerkorteOpenbareRuimteNaam()); ps.setLong(13, origineel.getIdentificatie()); ps.setLong(14, origineel.getAanduidingRecordCorrectie()); ps.setTimestamp(15, new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating openbare ruimte: " + origineel.getIdentificatie(), e); } }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testDateSubtractionLongToDecimalCompareNumber() throws Exception { String tablename = generateUniqueName(); String tenantId = getOrganizationId(); String query = "SELECT feature FROM " + tablename + " WHERE organization_id = ? and ? - \"DATE\" - 1.5 > 3"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try {//w w w .j a v a 2 s . c o m Date startDate = new Date(System.currentTimeMillis()); Date endDate = new Date(startDate.getTime() + 9 * QueryConstants.MILLIS_IN_DAY); initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); statement.setDate(2, endDate); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals("A", rs.getString(1)); assertTrue(rs.next()); assertEquals("B", rs.getString(1)); assertTrue(rs.next()); assertEquals("C", rs.getString(1)); assertFalse(rs.next()); } finally { conn.close(); } }