List of usage examples for java.sql PreparedStatement setNull
void setNull(int parameterIndex, int sqlType) throws SQLException;
NULL
. From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Woonplaats origineel, final Woonplaats wijziging) throws DAOException { try {//w ww. ja va 2s . 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:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void insertVerblijfsobjecten(final List<Verblijfsobject> verblijfsobjecten) throws DAOException { try {/* w ww . j a v a 2s . co m*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jdbcTemplate.batchUpdate("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 (?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, verblijfsobjecten.get(i).getIdentificatie()); ps.setInt(2, verblijfsobjecten.get(i).getAanduidingRecordInactief().ordinal()); ps.setLong(3, verblijfsobjecten.get(i).getAanduidingRecordCorrectie()); ps.setInt(4, verblijfsobjecten.get(i).getOfficieel().ordinal()); ps.setString(5, verblijfsobjecten.get(i).getVerblijfsobjectGeometrie()); ps.setInt(6, verblijfsobjecten.get(i).getOppervlakteVerblijfsobject()); ps.setInt(7, verblijfsobjecten.get(i).getVerblijfsobjectStatus().ordinal()); ps.setTimestamp(8, new Timestamp( verblijfsobjecten.get(i).getBegindatumTijdvakGeldigheid().getTime())); if (verblijfsobjecten.get(i).getEinddatumTijdvakGeldigheid() == null) ps.setNull(9, Types.TIMESTAMP); else ps.setTimestamp(9, new Timestamp(verblijfsobjecten.get(i) .getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(10, verblijfsobjecten.get(i).getInOnderzoek().ordinal()); ps.setDate(11, new Date(verblijfsobjecten.get(i).getDocumentdatum().getTime())); ps.setString(12, verblijfsobjecten.get(i).getDocumentnummer()); ps.setLong(13, verblijfsobjecten.get(i).getHoofdAdres()); } @Override public int getBatchSize() { return verblijfsobjecten.size(); } }); insertGebruikersdoelen(verblijfsobjecten); insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobjecten); insertGerelateerdePanden(verblijfsobjecten); } }); } catch (DataAccessException e) { throw new DAOException("Error inserting verblijfsobjecten", e); } }
From source file:org.openanzo.datasource.nodecentric.sql.GlitterRdbWrapper.java
/** * Runs the selectUntimelyGraphs prepared statement. * <code>// w w w.j a va 2 s . c o m * SELECT TMP1.ID FROM {0}{1} TMP1 LEFT JOIN (SELECT NG.ID FROM NAMEDGRAPHS NG, {0}{2} TMP2 WHERE NG.ID = TMP2.ID AND ? >= NG.HSTART AND (NG.HEND IS NULL OR ? < NG.HEND) )AS TMP2 ON TMP1.ID=TMP2.ID WHERE TMP2.ID IS NULL * </code> * *@param stmtProvider * factory and cache of PreparedStatments *@param connection * connection to underlying database * *@param lastTransactionTime1 template parameter *@param lastTransactionTime2 template parameter * *@param sessionPrefix template parameter *@param tempgraph1 template parameter *@param tempgraph2 template parameter *@return org.openanzo.jdbc.utils.ClosableIterator *@throws org.openanzo.jdbc.utils.RdbException */ public static org.openanzo.jdbc.utils.ClosableIterator<Long> selectUntimelyGraphs( final org.openanzo.jdbc.utils.PreparedStatementProvider stmtProvider, final java.sql.Connection connection, Long lastTransactionTime1, Long lastTransactionTime2, String sessionPrefix, String tempgraph1, String tempgraph2) throws org.openanzo.jdbc.utils.RdbException { java.sql.PreparedStatement ps = null; //long startTimer=System.currentTimeMillis(); try { ps = stmtProvider.getPreparedSQLStatement(selectUntimelyGraphs, new String[] { sessionPrefix, tempgraph1, tempgraph2 }, connection); int argc = 1; if (lastTransactionTime1 == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, lastTransactionTime1); } if (lastTransactionTime2 == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, lastTransactionTime2); } java.sql.ResultSet rs = null; try { rs = ps.executeQuery(); } catch (java.sql.SQLException sqle) { if (sqle.getErrorCode() == 1205) { int retries = 0; while (retries < 5) { try { Thread.sleep(5000); } catch (InterruptedException ie) { throw sqle; } try { rs = ps.executeQuery(); break; } catch (java.sql.SQLException sqleInner) { if (sqleInner.getErrorCode() == 1205) { retries++; } else { throw sqleInner; } } } if (retries >= 5) { throw sqle; } } else { throw sqle; } } org.openanzo.jdbc.utils.ClosableIterator<Long> iter = new org.openanzo.jdbc.utils.ResultSetIterator<Long>( rs, ps, stmtProvider, transformSelectUntimelyGraphs); return iter; } catch (java.sql.SQLException e) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.FAILED_EXECUTING_SQL, e, "selectUntimelyGraphs", stmtProvider.getSqlString(selectUntimelyGraphs), "" + "lastTransactionTime1=" + ((lastTransactionTime1 != null) ? lastTransactionTime1.toString() : "null") + "," + "lastTransactionTime2=" + ((lastTransactionTime2 != null) ? lastTransactionTime2.toString() : "null"), "" + "sessionPrefix=" + ((sessionPrefix != null) ? sessionPrefix.toString() : "null") + "," + "tempgraph1=" + ((tempgraph1 != null) ? tempgraph1.toString() : "null") + "," + "tempgraph2=" + ((tempgraph2 != null) ? tempgraph2.toString() : "null")); } finally { //long endtimer=(System.currentTimeMillis()-startTimer); //if(endtimer>CUTOFF)System.out.println("[selectUntimelyGraphs]"+endtimer); } }
From source file:org.openanzo.datasource.nodecentric.sql.GlitterRdbWrapper.java
/** * Runs the selectUntimelyMetadataGraphs prepared statement. * <code>/* w ww . j av a 2s. c o m*/ * SELECT TMP1.ID FROM {0}{1} TMP1 LEFT JOIN (SELECT DISTINCT NG.METAID FROM NAMEDGRAPHS NG, {0}{2} TMP2 WHERE NG.METAID = TMP2.ID AND ? >= NG.HSTART AND (NG.HEND IS NULL OR ? < NG.HEND) )AS TMP2 ON TMP1.ID=TMP2.METAID WHERE TMP2.METAID IS NULL * </code> * *@param stmtProvider * factory and cache of PreparedStatments *@param connection * connection to underlying database * *@param lastTransactionTime1 template parameter *@param lastTransactionTime2 template parameter * *@param sessionPrefix template parameter *@param tempgraph1 template parameter *@param tempgraph2 template parameter *@return org.openanzo.jdbc.utils.ClosableIterator *@throws org.openanzo.jdbc.utils.RdbException */ public static org.openanzo.jdbc.utils.ClosableIterator<Long> selectUntimelyMetadataGraphs( final org.openanzo.jdbc.utils.PreparedStatementProvider stmtProvider, final java.sql.Connection connection, Long lastTransactionTime1, Long lastTransactionTime2, String sessionPrefix, String tempgraph1, String tempgraph2) throws org.openanzo.jdbc.utils.RdbException { java.sql.PreparedStatement ps = null; //long startTimer=System.currentTimeMillis(); try { ps = stmtProvider.getPreparedSQLStatement(selectUntimelyMetadataGraphs, new String[] { sessionPrefix, tempgraph1, tempgraph2 }, connection); int argc = 1; if (lastTransactionTime1 == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, lastTransactionTime1); } if (lastTransactionTime2 == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, lastTransactionTime2); } java.sql.ResultSet rs = null; try { rs = ps.executeQuery(); } catch (java.sql.SQLException sqle) { if (sqle.getErrorCode() == 1205) { int retries = 0; while (retries < 5) { try { Thread.sleep(5000); } catch (InterruptedException ie) { throw sqle; } try { rs = ps.executeQuery(); break; } catch (java.sql.SQLException sqleInner) { if (sqleInner.getErrorCode() == 1205) { retries++; } else { throw sqleInner; } } } if (retries >= 5) { throw sqle; } } else { throw sqle; } } org.openanzo.jdbc.utils.ClosableIterator<Long> iter = new org.openanzo.jdbc.utils.ResultSetIterator<Long>( rs, ps, stmtProvider, transformSelectUntimelyMetadataGraphs); return iter; } catch (java.sql.SQLException e) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.FAILED_EXECUTING_SQL, e, "selectUntimelyMetadataGraphs", stmtProvider.getSqlString(selectUntimelyMetadataGraphs), "" + "lastTransactionTime1=" + ((lastTransactionTime1 != null) ? lastTransactionTime1.toString() : "null") + "," + "lastTransactionTime2=" + ((lastTransactionTime2 != null) ? lastTransactionTime2.toString() : "null"), "" + "sessionPrefix=" + ((sessionPrefix != null) ? sessionPrefix.toString() : "null") + "," + "tempgraph1=" + ((tempgraph1 != null) ? tempgraph1.toString() : "null") + "," + "tempgraph2=" + ((tempgraph2 != null) ? tempgraph2.toString() : "null")); } finally { //long endtimer=(System.currentTimeMillis()-startTimer); //if(endtimer>CUTOFF)System.out.println("[selectUntimelyMetadataGraphs]"+endtimer); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void insert(final Pand pand) throws DAOException { try {/*from ww w. j a v a 2s . c om*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("insert into bag_pand (" + "bag_pand_id," + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel," + "pand_geometrie," + "bouwjaar," + "pand_status," + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)"); ps.setLong(1, pand.getIdentificatie()); ps.setInt(2, pand.getAanduidingRecordInactief().ordinal()); ps.setLong(3, pand.getAanduidingRecordCorrectie()); ps.setInt(4, pand.getOfficieel().ordinal()); ps.setString(5, pand.getPandGeometrie()); ps.setInt(6, pand.getBouwjaar()); ps.setString(7, pand.getPandStatus()); ps.setTimestamp(8, new Timestamp(pand.getBegindatumTijdvakGeldigheid().getTime())); if (pand.getEinddatumTijdvakGeldigheid() == null) ps.setNull(9, Types.TIMESTAMP); else ps.setTimestamp(9, new Timestamp(pand.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(10, pand.getInOnderzoek().ordinal()); ps.setDate(11, new Date(pand.getDocumentdatum().getTime())); ps.setString(12, pand.getDocumentnummer()); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error inserting pand: " + pand.getIdentificatie(), e); } }
From source file:org.batoo.jpa.jdbc.dbutils.QueryRunner.java
/** * Fill the <code>PreparedStatement</code> replacement parameters with the given objects. * //from ww w .ja va 2 s.c om * @param statement * PreparedStatement to fill * @param params * Query replacement parameters; <code>null</code> is a valid value to pass in. * @throws SQLException * if a database access error occurs */ private void fillStatement(PreparedStatement statement, Object... params) throws SQLException { // use local variable for performance boolean pmdKnownBroken = this.pmdKnownBroken; ParameterMetaData pmd = this.pmd; final boolean hasLob = this.hasLob; if (pmdKnownBroken) { ((PreparedStatementProxy) statement).setParamCount(params.length); } else { ((PreparedStatementProxy) statement).setParamCount(-1); } // if the jdbc adaptor wants to modify the parameters we let it do it its own way final JdbcAdaptor jdbcAdaptor = this.jdbcAdaptor; if ((jdbcAdaptor != null) && jdbcAdaptor.modifiesParameters()) { pmd = this.pmd = statement.getParameterMetaData(); jdbcAdaptor.modifyParameters(pmd, params); } for (int i = 0; i < params.length; i++) { final Object param = params[i]; if ((param != null) && (param != Void.TYPE)) { if (hasLob && (param instanceof Clob)) { if (this.jdbcAdaptor instanceof OracleAdaptor) { statement.setCharacterStream(i + 1, ((Clob) param).getCharacterStream()); } else { statement.setClob(i + 1, (Clob) param); } } else if (hasLob && (param instanceof Blob)) { if (this.jdbcAdaptor instanceof OracleAdaptor) { statement.setBinaryStream(i + 1, ((Blob) param).getBinaryStream()); } else { statement.setBlob(i + 1, (Blob) param); } } else { statement.setObject(i + 1, param); } } else { if (!pmdKnownBroken && (pmd == null)) { pmd = this.pmd = statement.getParameterMetaData(); } // VARCHAR works with many drivers regardless of the actual column type. // Oddly, NULL and OTHER don't work with Oracle's drivers. int sqlType = Types.VARCHAR; if (!pmdKnownBroken) { try { sqlType = pmd.getParameterType(i + 1); } catch (final SQLException e) { pmdKnownBroken = this.pmdKnownBroken = true; } } if (param != Void.TYPE) { statement.setNull(i + 1, sqlType); } } } }
From source file:org.latticesoft.util.resource.dao.Param.java
private void setValueToStatement(Object o, PreparedStatement pstmt) throws SQLException { if (log.isDebugEnabled()) { log.debug(this.sqlIndex + "=" + o); }//from w w w . j av a 2 s .c om switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = (String) o; pstmt.setString(this.sqlIndex, s); break; case Types.BOOLEAN: if (o != null && o instanceof Boolean) { boolean b = ((Boolean) o).booleanValue(); pstmt.setBoolean(this.sqlIndex, b); } break; case Types.INTEGER: if (o != null && o instanceof Integer) { int i = ((Integer) o).intValue(); pstmt.setInt(this.sqlIndex, i); } break; case Types.SMALLINT: if (o != null && o instanceof Short) { short ss = ((Short) o).shortValue(); pstmt.setShort(this.sqlIndex, ss); } break; case Types.TINYINT: if (o != null && o instanceof Byte) { byte bb = ((Byte) o).byteValue(); pstmt.setByte(this.sqlIndex, bb); } break; case Types.BIGINT: if (o != null && o instanceof Long) { long l = ((Long) o).longValue(); pstmt.setLong(this.sqlIndex, l); } break; case Types.DOUBLE: if (o != null && o instanceof Double) { double dd = ((Double) o).doubleValue(); pstmt.setDouble(this.sqlIndex, dd); } break; case Types.FLOAT: if (o != null && o instanceof Float) { float f = ((Float) o).floatValue(); pstmt.setFloat(this.sqlIndex, f); } break; case Types.NUMERIC: if (o != null && o instanceof BigDecimal) { BigDecimal bd = (BigDecimal) o; pstmt.setBigDecimal(this.sqlIndex, bd); } break; case Types.TIMESTAMP: if (o != null && o instanceof Timestamp) { Timestamp ts = (Timestamp) o; pstmt.setTimestamp(this.sqlIndex, ts); } break; case Types.NULL: if (log.isDebugEnabled()) { log.debug(this.sqlIndex + " IS NULL"); } pstmt.setNull(this.sqlIndex, Types.NULL); break; default: if (o != null) { pstmt.setObject(this.sqlIndex, o); } } }
From source file:org.openbel.framework.core.kam.JdbcKAMLoaderImpl.java
/** * {@inheritDoc}/*from w w w. ja v a 2 s . co m*/ */ @Override public void loadNodes(NamespaceTable nt, ParameterTable pt, TermTable tt, TermParameterMapTable tpmt, ProtoNodeTable pnt) throws SQLException { List<String> terms = tt.getTermValues(); Map<Integer, List<Integer>> tpmtidx = tpmt.getTermParameterIndex(); PreparedStatement knps = getPreparedStatement(KAM_NODE_SQL); // load kam nodes final List<String> nodes = pnt.getProtoNodes(); final Map<Integer, Integer> eqn = pnt.getEquivalences(); final Set<Integer> added = new HashSet<Integer>(); for (int i = 0, n = nodes.size(); i < n; i++) { final Integer eqId = eqn.get(i); // continue if we have already seen this equivalent proto node if (added.contains(eqId)) { continue; } added.add(eqId); final String nl = nodes.get(i); Integer knl = valueIndexMap.get(nl); if (knl == null) { knl = saveObject(1, nl); valueIndexMap.put(nl, knl); } String tf = nl.substring(0, nl.indexOf('(')); int fv = FunctionEnum.getFunctionEnum(tf).getValue(); // XXX offset knps.setInt(1, eqId + 1); knps.setInt(2, fv); knps.setInt(3, knl); knps.addBatch(); } knps.executeBatch(); PreparedStatement knpps = getPreparedStatement(KAM_NODE_PARAMETER_SQL); PreparedStatement knups = getPreparedStatement(KAM_PARAMETER_UUID_SQL); final Map<Integer, Integer> gpi = pt.getGlobalIndex(); final Map<Integer, SkinnyUUID> guu = pt.getGlobalUUIDs(); final Set<Integer> seenKamNodes = sizedHashSet(nodes.size()); final Set<Integer> seenGlobalIds = sizedHashSet(gpi.size()); // load kam node parameters final Map<Integer, Integer> nti = pnt.getNodeTermIndex(); for (int i = 0, n = nodes.size(); i < n; i++) { final Integer ti = nti.get(i); // XXX offset final Integer eqId = eqn.get(i) + 1; // don't add kam node parameters if we have already seen the // equivalent node. if (seenKamNodes.contains(eqId)) { continue; } List<Integer> gtpl = tpmtidx.get(ti); if (hasItems(gtpl)) { for (int j = 0; j < gtpl.size(); j++) { // get parameter index, retrieve global parameter, and set Integer parameterIndex = gtpl.get(j); final Integer gid = gpi.get(parameterIndex); // XXX offset knpps.setInt(1, gid + 1); knpps.setInt(2, eqId); knpps.setInt(3, j); knpps.addBatch(); if (seenGlobalIds.contains(gid)) { continue; } SkinnyUUID uuid = guu.get(gid); if (uuid != null) { // XXX offset knups.setInt(1, gid + 1); knups.setLong(2, uuid.getMostSignificantBits()); knups.setLong(3, uuid.getLeastSignificantBits()); knups.addBatch(); } seenGlobalIds.add(gid); } } // track equivalent kam node seenKamNodes.add(eqId); } knpps.executeBatch(); PreparedStatement pps = getPreparedStatement(TERM_PARAMETER_SQL); PreparedStatement tps = getPreparedStatement(TERM_SQL); final Map<Integer, Integer> termNodes = pnt.getTermNodeIndex(); // load term parameters and terms int tpindex = 0; for (int ti = 0; ti < terms.size(); ti++) { String t = terms.get(ti); // find node equivalence Integer nodeId = termNodes.get(ti); // XXX offset final Integer eqId = eqn.get(nodeId) + 1; Integer ctl = valueIndexMap.get(t); if (ctl == null) { ctl = saveObject(1, t); valueIndexMap.put(t, ctl); } // XXX offset tps.setInt(1, ti + 1); // XXX offset tps.setInt(2, eqId); tps.setInt(3, ctl); tps.addBatch(); int ord = 0; List<Integer> pl = tpmtidx.get(ti); if (hasItems(pl)) { for (Integer pi : pl) { TableParameter p = pt.getIndexTableParameter().get(pi); Integer cpv = valueIndexMap.get(p.getValue()); if (cpv == null) { cpv = saveObject(1, p.getValue()); valueIndexMap.put(p.getValue(), cpv); } final Integer gid = gpi.get(pi); // XXX offset pps.setInt(1, tpindex + 1); // XXX offset pps.setInt(2, gid + 1); // XXX offset pps.setInt(3, ti + 1); // find index for the parameter's namespace TableNamespace tn = p.getNamespace(); Integer ni = null; if (tn != null) { ni = nt.getNamespaceIndex().get(tn); } if (ni == null) { pps.setNull(4, Types.INTEGER); } else { // XXX offset pps.setInt(4, ni + 1); } pps.setInt(5, cpv); pps.setInt(6, ord); pps.addBatch(); ord++; tpindex++; if (seenGlobalIds.contains(gid)) { continue; } SkinnyUUID uuid = guu.get(gid); if (uuid != null) { // XXX offset knups.setInt(1, gid + 1); knups.setLong(2, uuid.getMostSignificantBits()); knups.setLong(3, uuid.getLeastSignificantBits()); knups.addBatch(); } seenGlobalIds.add(gid); } } } tps.executeBatch(); pps.executeBatch(); knups.executeBatch(); }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Nummeraanduiding nummeraanduiding) throws DAOException { try {//w w w. jav a2 s. com jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_nummeraanduiding set" + " aanduiding_record_inactief = ?," + " huisnummer = ?," + " officieel = ?," + " huisletter = ?," + " huisnummertoevoeging = ?," + " postcode = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " type_adresseerbaar_object = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " nummeraanduiding_status = ?," + " bag_woonplaats_id = ?," + " bag_openbare_ruimte_id = ?" + " where bag_nummeraanduiding_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, nummeraanduiding.getAanduidingRecordInactief().ordinal()); ps.setInt(2, nummeraanduiding.getHuisnummer()); ps.setInt(3, nummeraanduiding.getOfficieel().ordinal()); if (nummeraanduiding.getHuisletter() == null) ps.setNull(4, Types.INTEGER); else ps.setString(4, nummeraanduiding.getHuisletter()); if (nummeraanduiding.getHuisnummertoevoeging() == null) ps.setNull(5, Types.VARCHAR); else ps.setString(5, nummeraanduiding.getHuisnummertoevoeging()); if (nummeraanduiding.getPostcode() == null) ps.setNull(6, Types.VARCHAR); else ps.setString(6, nummeraanduiding.getPostcode()); if (nummeraanduiding.getEinddatumTijdvakGeldigheid() == null) ps.setNull(7, Types.TIMESTAMP); else ps.setTimestamp(7, new Timestamp(nummeraanduiding.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(8, nummeraanduiding.getInOnderzoek().ordinal()); ps.setInt(9, nummeraanduiding.getTypeAdresseerbaarObject().ordinal()); ps.setDate(10, new Date(nummeraanduiding.getDocumentdatum().getTime())); ps.setString(11, nummeraanduiding.getDocumentnummer()); ps.setInt(12, nummeraanduiding.getNummeraanduidingStatus().ordinal()); if (nummeraanduiding.getGerelateerdeWoonplaats() == null) ps.setNull(13, Types.INTEGER); else ps.setLong(13, nummeraanduiding.getGerelateerdeWoonplaats()); ps.setLong(14, nummeraanduiding.getGerelateerdeOpenbareRuimte()); ps.setLong(15, nummeraanduiding.getIdentificatie()); ps.setLong(16, nummeraanduiding.getAanduidingRecordCorrectie()); ps.setTimestamp(17, new Timestamp(nummeraanduiding.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating nummeraanduiding: " + nummeraanduiding.getIdentificatie(), e); } }
From source file:org.apache.marmotta.kiwi.persistence.KiWiConnection.java
/** * Return the identifier of the triple with the given subject, predicate, object and context, or null if this * triple does not exist. Used for quick existance checks of triples. * * @param subject// w ww . ja va 2 s. co m * @param predicate * @param object * @param context * @return */ public synchronized long getTripleId(final KiWiResource subject, final KiWiUriResource predicate, final KiWiNode object, final KiWiResource context) throws SQLException { if (tripleBatch != null && tripleBatch.size() > 0) { Collection<KiWiTriple> batched = tripleBatch.listTriples(subject, predicate, object, context, false); if (batched.size() > 0) { return batched.iterator().next().getId(); } } requireJDBCConnection(); PreparedStatement loadTripleId = getPreparedStatement("load.triple"); loadTripleId.setLong(1, subject.getId()); loadTripleId.setLong(2, predicate.getId()); loadTripleId.setLong(3, object.getId()); if (context != null) { loadTripleId.setLong(4, context.getId()); } else { loadTripleId.setNull(4, Types.BIGINT); } ResultSet result = loadTripleId.executeQuery(); try { if (result.next()) { return result.getLong(1); } else { return -1L; } } finally { result.close(); } }