use of com.twinsoft.util.StringEx in project convertigo by convertigo.
the class DatabaseCacheManager method removeExpiredCacheEntries.
protected void removeExpiredCacheEntries(long time) throws EngineException {
try {
Engine.logCacheManager.debug("Trying to remove expired cache entries from the cache Database");
sqlRequester.checkConnection();
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_REMOVE_EXPIRED_CACHE_ENTRY));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
sqlRequest.replace("{CurrentTime}", Long.toString(time));
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
Statement statement = null;
try {
statement = sqlRequester.connection.createStatement();
int nResult = statement.executeUpdate(sSqlRequest);
Engine.logCacheManager.debug(nResult + " row(s) deleted.");
} finally {
if (statement != null) {
statement.close();
}
}
Engine.logCacheManager.debug("The expired cache entries has been removed.");
} catch (Exception e) {
throw new EngineException("Unable to remove the expired cache entries!", e);
}
}
use of com.twinsoft.util.StringEx in project convertigo by convertigo.
the class DatabaseCacheManager method removeStoredResponse.
protected synchronized void removeStoredResponse(CacheEntry cacheEntry) throws EngineException {
removeWeakResponse(cacheEntry);
DatabaseCacheEntry dbCacheEntry = (DatabaseCacheEntry) cacheEntry;
Engine.logCacheManager.debug("cacheEntry=[" + cacheEntry.toString() + "]");
long id = 0;
try {
Engine.logCacheManager.debug("Trying to remove stored response from the cache Database");
sqlRequester.checkConnection();
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_REMOVE_RESPONSE));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
id = dbCacheEntry.id;
sqlRequest.replace("{Id}", Long.toString(id));
Engine.logCacheManager.debug("Replacement done");
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
Statement statement = null;
try {
statement = sqlRequester.connection.createStatement();
int nResult = statement.executeUpdate(sSqlRequest);
Engine.logCacheManager.debug("" + nResult + " row(s) deleted.");
} finally {
if (statement != null) {
statement.close();
}
}
Engine.logCacheManager.debug("The stored response has sucessfully been removed.");
} catch (Exception e) {
throw new EngineException("Unable to remove the response! (id: " + id + ")", e);
}
}
use of com.twinsoft.util.StringEx in project convertigo by convertigo.
the class DatabaseCacheManager method getCacheEntry.
public CacheEntry getCacheEntry(String requestString) throws EngineException {
try {
DatabaseCacheEntry cacheEntry = null;
CacheEntry ce = null;
if ((ce = getWeakEntry(requestString)) != null && ce instanceof DatabaseCacheEntry) {
return ce;
}
Engine.logCacheManager.debug("Trying to get the cache entry from this request string: " + requestString);
sqlRequester.checkConnection();
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_GET_CACHE_ENTRY));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
sqlRequest.replace("{RequestString}", escapeString(requestString));
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
Statement statement = null;
ResultSet rs = null;
try {
statement = sqlRequester.connection.createStatement();
rs = statement.executeQuery(sSqlRequest);
if (rs.next()) {
cacheEntry = new DatabaseCacheEntry();
cacheEntry.requestString = requestString.trim();
cacheEntry.id = rs.getLong("Id");
cacheEntry.expiryDate = rs.getLong("ExpiryDate");
cacheEntry.sheetUrl = rs.getString("SheetUrl");
if (cacheEntry.sheetUrl != null)
cacheEntry.sheetUrl = cacheEntry.sheetUrl.trim();
cacheEntry.absoluteSheetUrl = rs.getString("AbsoluteSheetUrl");
if (cacheEntry.absoluteSheetUrl != null)
cacheEntry.absoluteSheetUrl = cacheEntry.absoluteSheetUrl.trim();
cacheEntry.contentType = rs.getString("ContentType");
if (cacheEntry.contentType != null)
cacheEntry.contentType = cacheEntry.contentType.trim();
}
} finally {
if (rs != null)
rs.close();
if (statement != null)
statement.close();
}
Engine.logCacheManager.debug("The cache entry has been retrieved: [" + cacheEntry + "]");
storeWeakEntry(cacheEntry);
return cacheEntry;
} catch (Exception e) {
throw new EngineException("Unable to get the cache entry! (requestString: " + requestString + ")", e);
}
}
use of com.twinsoft.util.StringEx in project convertigo by convertigo.
the class DatabaseCacheManager method getId.
private long getId(String requestString) throws EngineException {
try {
Engine.logCacheManager.debug("Trying to get Id.");
sqlRequester.checkConnection();
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_GET_ID));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
sqlRequest.replace("{RequestString}", escapeString(requestString));
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
Statement statement = null;
ResultSet rs = null;
long lId = 0;
try {
statement = sqlRequester.connection.createStatement();
rs = statement.executeQuery(sSqlRequest);
rs.next();
String sId = new String(rs.getString("Id"));
lId = Long.parseLong(sId);
} finally {
if (rs != null)
rs.close();
if (statement != null) {
statement.close();
}
}
Engine.logCacheManager.debug("ID retrieved: " + lId);
return lId;
} catch (Exception e) {
throw new EngineException("Unable to get the Id.", e);
}
}
use of com.twinsoft.util.StringEx in project convertigo by convertigo.
the class DatabaseCacheManager method getStoredResponse.
protected Document getStoredResponse(Requester requester, CacheEntry cacheEntry) throws EngineException {
Document document = getWeakResponse(cacheEntry);
if (document != null) {
return document;
}
DatabaseCacheEntry dbCacheEntry = (DatabaseCacheEntry) cacheEntry;
Engine.logCacheManager.debug("cacheEntry=[" + cacheEntry.toString() + "]");
try {
Engine.logCacheManager.debug("Trying to get from the cache the stored response corresponding to this cache entry.");
sqlRequester.checkConnection();
String jdbcURL = sqlRequester.getProperty(SqlRequester.PROPERTIES_JDBC_URL);
boolean isOracleServerDatabase = jdbcURL.indexOf(":oracle:") != -1;
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_GET_STORED_RESPONSE));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
long id = dbCacheEntry.id;
sqlRequest.replace("{Id}", Long.toString(id));
Engine.logCacheManager.debug("Replacement done");
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
// SELECT x.Xml.getCLOBVal() Xml FROM CacheTable x WHERE Id \= {Id}
if (isOracleServerDatabase && sSqlRequest.toUpperCase().indexOf("GETCLOBVAL()") != -1) {
PreparedStatement statement = null;
ResultSet rs = null;
java.sql.Clob clb = null;
try {
statement = sqlRequester.connection.prepareStatement(sSqlRequest);
rs = statement.executeQuery(sSqlRequest);
rs.next();
clb = rs.getClob("Xml");
Reader in = clb.getCharacterStream();
StringWriter w = new StringWriter();
IOUtils.copy(in, w);
String xml = w.toString();
document = requester.parseDOM(xml);
} finally {
if (clb != null) {
clb.free();
}
if (rs != null) {
rs.close();
}
if (statement != null) {
statement.close();
}
}
} else // Other cases
// SELECT Xml FROM CacheTable WHERE Id \= {Id}
{
Statement statement = null;
ResultSet rs = null;
try {
statement = sqlRequester.connection.createStatement();
rs = statement.executeQuery(sSqlRequest);
rs.next();
String xml = rs.getString("Xml");
document = requester.parseDOM(xml);
} finally {
if (rs != null) {
rs.close();
}
if (statement != null) {
statement.close();
}
}
}
Engine.logCacheManager.debug("Response built from the cache");
storeWeakResponse(document, cacheEntry.requestString);
return document;
} catch (Exception e) {
throw new EngineException("Unable to get the response [" + cacheEntry.toString() + "] from the cache !", e);
}
}
Aggregations