in oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java [441:527]
public List<RDBRow> query(Connection connection, RDBTableMetaData tmd, String minId, String maxId,
List<String> excludeKeyPatterns, List<QueryCondition> conditions, int limit) throws SQLException {
long start = System.currentTimeMillis();
List<RDBRow> result = new ArrayList<RDBRow>();
long dataTotal = 0, bdataTotal = 0;
PreparedStatement stmt = null;
String fields;
if (tmd.hasSplitDocs()) {
fields = "ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, VERSION, SDTYPE, SDMAXREVTIME, DATA, BDATA";
} else if (tmd.hasVersion()) {
fields = "ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, VERSION, DATA, BDATA";
} else {
fields = "ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, DATA, BDATA";
}
ResultSet rs = null;
try {
long pstart = PERFLOG.start(PERFLOG.isDebugEnabled()
? ("querying: table=" + tmd.getName() + ", minId=" + minId + ", maxId=" + maxId + ", excludeKeyPatterns="
+ excludeKeyPatterns + ", conditions=" + conditions + ", limit=" + limit)
: null);
stmt = prepareQuery(connection, tmd, fields, minId,
maxId, excludeKeyPatterns, conditions, limit, "ID");
rs = stmt.executeQuery();
while (rs.next() && result.size() < limit) {
int field = 1;
String id = getIdFromRS(tmd, rs, field++);
if ((minId != null && id.compareTo(minId) < 0) || (maxId != null && id.compareTo(maxId) > 0)) {
throw new DocumentStoreException(
"unexpected query result: '" + minId + "' < '" + id + "' < '" + maxId + "' - broken DB collation?");
}
long modified = readLongFromResultSet(rs, field++);
long modcount = readLongFromResultSet(rs, field++);
long cmodcount = readLongFromResultSet(rs, field++);
Long hasBinary = readLongOrNullFromResultSet(rs, field++);
Boolean deletedOnce = readBooleanOrNullFromResultSet(rs, field++);
long schemaVersion = tmd.hasVersion() ? readLongFromResultSet(rs, field++) : 0;
long sdType = tmd.hasSplitDocs() ? readLongFromResultSet(rs, field++) : RDBRow.LONG_UNSET;
long sdMaxRevTime = tmd.hasSplitDocs() ? readLongFromResultSet(rs, field++) : RDBRow.LONG_UNSET;
String data = rs.getString(field++);
byte[] bdata = rs.getBytes(field++);
result.add(new RDBRow(id, hasBinary, deletedOnce, modified, modcount, cmodcount, schemaVersion, sdType,
sdMaxRevTime, data, bdata));
dataTotal += data == null ? 0 : data.length();
bdataTotal += bdata == null ? 0 : bdata.length;
PERFLOG.end(pstart, 10, "queried: table={} -> id={}, modcount={}, modified={}, data={}, bdata={}", tmd.getName(), id,
modcount, modified, (data == null ? 0 : data.length()), (bdata == null ? 0 : bdata.length));
}
} finally {
closeStatement(stmt);
closeResultSet(rs);
}
long elapsed = System.currentTimeMillis() - start;
if ((this.queryHitsLimit != 0 && result.size() > this.queryHitsLimit)
|| (this.queryTimeLimit != 0 && elapsed > this.queryTimeLimit)) {
String params = String.format("params minid '%s' maxid '%s' excludeKeyPatterns %s conditions %s limit %d.", minId,
maxId, excludeKeyPatterns, conditions, limit);
String resultRange = "";
if (result.size() > 0) {
resultRange = String.format(" Result range: '%s'...'%s'.", result.get(0).getId(),
result.get(result.size() - 1).getId());
}
String postfix = String.format(" Read %d chars from DATA and %d bytes from BDATA. Check calling method.", dataTotal,
bdataTotal);
if (this.queryHitsLimit != 0 && result.size() > this.queryHitsLimit) {
String message = String.format(
"Potentially excessive query on %s with %d hits (limited to %d, configured QUERYHITSLIMIT %d), elapsed time %dms, %s%s%s",
tmd.getName(), result.size(), limit, this.queryHitsLimit, elapsed, params, resultRange, postfix);
LOG.info(message, new Exception("call stack"));
}
if (this.queryTimeLimit != 0 && elapsed > this.queryTimeLimit) {
String message = String.format(
"Long running query on %s with %d hits (limited to %d), elapsed time %dms (configured QUERYTIMELIMIT %d), %s%s%s",
tmd.getName(), result.size(), limit, elapsed, this.queryTimeLimit, params, resultRange, postfix);
LOG.info(message, new Exception("call stack"));
}
}
return result;
}