/** * Useful for building SQL strings * @param value may be {@code null} */ private static String valueOrNullLiteral(String value) { return value == null ? "null" : quoteString(value); } static String quoteString(String input) {
private void deleteReplTxnMapEntry(Connection dbConn, long sourceTxnId, String replPolicy) throws SQLException { String s = "delete from REPL_TXN_MAP where RTM_SRC_TXN_ID = " + sourceTxnId + " and RTM_REPL_POLICY = ?"; try (PreparedStatement pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, Arrays.asList(replPolicy))) { LOG.info("Going to execute <" + s.replaceAll("\\?", "{}") + ">", quoteString(replPolicy)); pst.executeUpdate(); } }
@Override public void releaseLocks() { rollbackDBConn(dbConn); close(rs, stmt, dbConn); if(derbySemaphore != null) { derbySemaphore.release(); } for(String key : keys) { LOG.debug(quoteString(key) + " unlocked by " + quoteString(TxnHandler.hostname)); } } }
private enum LockAction {ACQUIRE, WAIT, KEEP_LOOKING}
private ValidTxnList getValidTxnList(Connection dbConn, String fullTableName, Long writeId) throws MetaException, SQLException { PreparedStatement pst = null; ResultSet rs = null; try { String[] names = TxnUtils.getDbTableName(fullTableName); assert names.length == 2; List<String> params = Arrays.asList(names[0], names[1]); String s = "select t2w_txnid from TXN_TO_WRITE_ID where t2w_database = ? and t2w_table = ? and t2w_writeid = " + writeId; pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query <" + s.replaceAll("\\?", "{}") + ">", quoteString(names[0]), quoteString(names[1])); rs = pst.executeQuery(); if (rs.next()) { return TxnCommonUtils.createValidReadTxnList(getOpenTxns(), rs.getLong(1)); } throw new MetaException("invalid write id " + writeId + " for table " + fullTableName); } finally { close(rs, pst, null); } }
List<String> params = Arrays.asList(replPolicy); for (String query : inQueries) { LOG.debug("Going to execute select <" + query.replaceAll("\\?", "{}") + ">", quoteString(replPolicy)); pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, params); rs = pst.executeQuery();
String where = " where "; if(oldPartName != null) { update += "TC_PARTITION = " + quoteString(newPartName) + ", "; where += "TC_PARTITION = " + quoteString(oldPartName) + " AND "; update += "TC_TABLE = " + quoteString(normalizeCase(newTabName)) + ", "; where += "TC_TABLE = " + quoteString(normalizeCase(oldTabName)) + " AND "; update += "TC_DATABASE = " + quoteString(normalizeCase(newDbName)); where += "TC_DATABASE = " + quoteString(normalizeCase(oldDbName)); where = " where "; if(oldPartName != null) { update += "CTC_PARTITION = " + quoteString(newPartName) + ", "; where += "CTC_PARTITION = " + quoteString(oldPartName) + " AND "; update += "CTC_TABLE = " + quoteString(normalizeCase(newTabName)) + ", "; where += "CTC_TABLE = " + quoteString(normalizeCase(oldTabName)) + " AND "; update += "CTC_DATABASE = " + quoteString(normalizeCase(newDbName)); where += "CTC_DATABASE = " + quoteString(normalizeCase(oldDbName)); where = " where "; if(oldPartName != null) { update += "HL_PARTITION = " + quoteString(newPartName) + ", "; where += "HL_PARTITION = " + quoteString(oldPartName) + " AND "; update += "HL_TABLE = " + quoteString(normalizeCase(newTabName)) + ", "; where += "HL_TABLE = " + quoteString(normalizeCase(oldTabName)) + " AND ";
pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query<" + s.replaceAll("\\?", "{}") + ">", quoteString(names[0]), quoteString(names[1])); rs = pst.executeQuery(); if (rs.next()) { pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query<" + s.replaceAll("\\?", "{}") + ">", quoteString(names[0]), quoteString(names[1])); rs = pst.executeQuery(); if (rs.next()) { pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query<" + s.replaceAll("\\?", "{}") + ">", quoteString(names[0]), quoteString(names[1])); rs = pst.executeQuery(); while (rs.next()) {
pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, Arrays.asList(dbName, tblName)); LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); ResultSet rs = pst.executeQuery(); long txnId = -1;
pst = sqlGenerator.prepareStmtWithParameters(dbConn, selectQ, params); LOG.debug("Going to execute query <" + selectQ.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tableName)); rs = pst.executeQuery(); if(rs.next()) { pst = sqlGenerator.prepareStmtWithParameters(dbConn, insertQ, params); LOG.debug("Going to execute update <" + insertQ.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tableName)); pst.executeUpdate(); LOG.debug("Going to commit");
pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, Arrays.asList(dbName, tableName)); LOG.debug("Going to execute update <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tableName)); int rc = pst.executeUpdate(); if (rc < 1) {
"from WRITE_SET where ws_commit_id >= " + writeSet.get(0).txnId + " and (");//see commitTxn() for more info on this inequality for(LockInfo info : writeSet) { sb.append("(ws_database = ").append(quoteString(info.db)).append(" and ws_table = ") .append(quoteString(info.table)).append(" and ws_partition ") .append(info.partition == null ? "is null" : "= " + quoteString(info.partition)).append(") or ");
pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, params); LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") + ">", quoteString(db), quoteString(catalog)); rs = pst.executeQuery(); if (!rs.next()) { params = Arrays.asList(table); pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, params); LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") + ">", quoteString(table));
pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, query, params); LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); rs = pStmt.executeQuery(); while (rs.next()) { pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); rs = pStmt.executeQuery(); if (!rs.next()) { pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute insert <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); pStmt.execute(); } else { pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute update <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); pStmt.executeUpdate(); pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute delete <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); pStmt.executeUpdate();
String state = compactorStateToResponse(rs.getString(2).charAt(0)); LOG.info("Ignoring request to compact " + rqst.getDbname() + "/" + rqst.getTablename() + "/" + rqst.getPartitionname() + " since it is already " + quoteString(state) + " with id=" + enqueuedId); return new CompactionResponse(enqueuedId, state, false);
pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, Arrays.asList(rqst.getDbName(), rqst.getTblName())); LOG.debug("Going to execute insert <" + s.replaceAll("\\?", "{}") + ">", quoteString(rqst.getDbName()), quoteString(rqst.getTblName())); pst.execute(); LOG.debug("Going to commit");
pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, sql, params); LOG.debug("Going to execute query <" + sql.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); rs = pStmt.executeQuery(); if (rs.next()) { pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, sql, params); LOG.debug("Going to execute insert <" + sql.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); pStmt.execute();
+ " PARAM_VALUE = " + quoteString(rqst.getKeyValue().getValue()) + " WHERE TBL_ID = " + rqst.getKeyValue().getTableId() + " AND PARAM_KEY = " + quoteString(rqst.getKeyValue().getKey()); LOG.debug("Going to execute update <" + s + ">"); int affectedRows = stmt.executeUpdate(s);
pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, s, Arrays.asList(dbName, tblName)); LOG.debug("Going to execute query <" + s.replaceAll("\\?", "{}") + ">", quoteString(dbName), quoteString(tblName)); rs = pStmt.executeQuery(); if (rs.next()) { (tblName == null ? "null" : "?") + ", " + (partName == null ? "null" : "?")+ "," + quoteString(OperationType.fromDataOperationType(lc.getOperationType()).toString())+ "," + (writeId == null ? "null" : writeId)); List<String> params = new ArrayList<>();