lQueryCount++;
final String sConnection = getKey();
AtomicInteger ai = chmQueryCount.get(sConnection);
AtomicLong al = null;
if (ai == null) {
ai = new AtomicInteger(1);
chmQueryCount.put(sConnection, ai);
al = new AtomicLong(0);
chmQueryTime.put(sConnection, al);
} else {
ai.incrementAndGet();
al = chmQueryTime.get(sConnection);
}
if (al == null) {
al = new AtomicLong(0);
chmQueryTime.put(sConnection, al);
}
final String sStripPassword = sConnection.substring(0, sConnection.lastIndexOf('/'));
if (this.rsRezultat != null) {
try {
this.rsRezultat.close();
} catch (Throwable e) {
// ignore this
}
this.rsRezultat = null;
}
if (this.stat != null) {
try {
this.stat.close();
} catch (Throwable e) {
// ignore this
}
this.stat = null;
}
this.bIsUpdate = false;
this.iUpdateCount = -1;
this.first = false;
final long lStartTime = System.currentTimeMillis();
if (!connect()) {
try {
throw new SQLException("connection failed"); //$NON-NLS-1$
} catch (Exception e) {
Log.log(Log.ERROR, "lazyj.DBFunctions", sStripPassword + " --> cannot connect for query because "+getConnectFailReason()+" : \n" + sQuery, e); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
al.addAndGet(System.currentTimeMillis() - lStartTime);
return false;
}
try {
this.stat = this.dbc.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
if (this.stat.execute(sQuery, Statement.NO_GENERATED_KEYS)) {
this.rsRezultat = this.stat.getResultSet();
}
else {
this.bIsUpdate = true;
this.iUpdateCount = this.stat.getUpdateCount();
this.stat.close();
this.stat = null;
}
if (!this.bIsUpdate) {
this.first = true;
try {
if (!this.rsRezultat.next())
this.first = false;
} catch (Exception e) {
this.first = false;
}
} else
this.first = false;
this.dbc.free();
return true;
} catch (Exception e) {
this.rsRezultat = null;
this.first = false;
final String s = e.getMessage();
if (!bIgnoreErrors && s.indexOf("duplicate key") < 0 && s.indexOf("drop table") < 0) { //$NON-NLS-1$//$NON-NLS-2$
Log.log(Log.ERROR, "lazyj.DBFunctions", sStripPassword + " --> Error executing '" + sQuery + "'", e); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
// in case of an error, close the connection
this.dbc.close();
} else {
// if the error is expected, or not fatal, silently free the connection for later
// use
this.dbc.free();
}
return false;
} finally {
al.addAndGet(System.currentTimeMillis() - lStartTime);
}
}