use of com.dexels.navajo.adapter.sqlmap.ResultSetMap in project navajo by Dexels.
the class QueryMap method store.
@Override
public void store() throws MappableException, UserException {
// Construct Navajo message.
try {
Message recordSet = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY);
try {
outputDoc.addMessage(recordSet);
} catch (NavajoException ex) {
throw new UserException(-1, ex.getMessage(), ex);
}
ResultSetMap[] resultSet = getResultSet();
for (int i = 0; i < resultSet.length; i++) {
Message record = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY_ELEMENT);
recordSet.addElement(record);
RecordMap[] columns = resultSet[i].getRecords();
for (int j = 0; j < columns.length; j++) {
try {
Object value = columns[j].getRecordValue();
String type = (value != null ? MappingUtils.determineNavajoType(value) : "unknown");
Property prop = NavajoFactory.getInstance().createProperty(outputDoc, columns[j].recordName, type, null, 0, "", Property.DIR_IN);
prop.setAnyValue(value);
record.addProperty(prop);
} catch (Exception ex1) {
throw new UserException(-1, ex1.getMessage(), ex1);
}
}
}
} finally {
super.store();
}
}
use of com.dexels.navajo.adapter.sqlmap.ResultSetMap in project navajo by Dexels.
the class SQLMap method getResultSet.
protected ResultSetMap[] getResultSet(boolean updateOnly) throws UserException {
requestCount++;
ResultSet rs = null;
long start = 0;
if (debug || timeAlert > 0) {
start = System.currentTimeMillis();
}
try {
if (resultSet == null) {
rs = getDBResultSet(updateOnly);
}
if (debug) {
Access.writeToConsole(myAccess, "SQLMAP, QUERY HAS BEEN EXECUTED, RETRIEVING RESULTSET\n");
}
if (rs != null) {
int columns = 0;
ResultSetMetaData meta = null;
try {
meta = rs.getMetaData();
columns = meta.getColumnCount();
} catch (Exception e) {
throw new UserException(-1, "Error getting metadata / columns", e);
}
ArrayList dummy = new ArrayList();
int index = 1;
remainCount = 0;
rowCount = 0;
while (rs.next()) {
if ((index >= startIndex) && (index <= endIndex)) {
ResultSetMap rm = getResultSetMap(meta, columns, rs);
dummy.add(rm);
viewCount++;
}
// else if (index >= startIndex) {
// remainCount++;
// }
rowCount++;
index++;
}
if (debug) {
Access.writeToConsole(myAccess, "GOT RESULTSET\n");
}
resultSet = new ResultSetMap[dummy.size()];
resultSet = (ResultSetMap[]) dummy.toArray(resultSet);
}
} catch (SQLException sqle) {
logger.error("The following query failed: {}", this.getQuery());
AuditLog.log("SQLMap", sqle.getMessage(), sqle, Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
throw new UserException(-1, sqle.getMessage(), sqle);
} catch (Exception sqle) {
AuditLog.log("SQLMap", sqle.getMessage(), sqle, Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
throw new UserException(-1, sqle.getMessage(), sqle);
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace(Access.getConsoleWriter(myAccess));
}
rs = null;
}
this.resetAll();
}
if (debug || timeAlert > 0) {
long end = System.currentTimeMillis();
double total = (end - start) / 1000.0;
if (timeAlert > 0 && (int) (end - start) > timeAlert) {
AuditLogEvent ale = new AuditLogEvent("SQLMAPTIMEALERT", "Query took " + (end - start) + " millis:\n" + (query != null ? query : update), Level.WARNING);
ale.setAccessId(myAccess.accessID);
NavajoEventRegistry.getInstance().publishEvent(ale);
}
// Log total if needed....
// totaltiming += total;
}
return resultSet;
}
Aggregations