use of com.twinsoft.convertigo.engine.util.SqlRequester in project convertigo by convertigo.
the class DatabaseCacheManager method init.
public void init() throws EngineException {
super.init();
try {
sqlRequester = new SqlRequester(DB_PROP_FILE_NAME);
sqlRequester.open();
} catch (IOException e) {
throw new EngineException("[DatabaseCacheManager] Unable to load the SQLRequester properties file: " + DB_PROP_FILE_NAME, e);
} catch (SQLException e) {
throw new EngineException("[DatabaseCacheManager] Unable to establish connection with the dataBase.", e);
} catch (ClassNotFoundException e) {
throw new EngineException("[DatabaseCacheManager] Unable to load JDBC Driver.", e);
}
}
use of com.twinsoft.convertigo.engine.util.SqlRequester in project convertigo by convertigo.
the class Configure method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
this.document = document;
root = document.getDocumentElement();
cacheType = request.getParameter("cacheType");
if (cacheType != null && cacheType.equals("database")) {
cacheType = cacheManagerDatabaseType;
} else {
cacheType = cacheManagerFileType;
}
dbCachePropFileName = Engine.CONFIGURATION_PATH + DatabaseCacheManager.DB_PROP_FILE_NAME;
PropertiesUtils.load(dbCacheProp, dbCachePropFileName);
try {
saveProps(request);
} catch (Exception e) {
throw new ServiceException("Unable to save the cache manager properties.", e.getCause());
}
String create = request.getParameter("create");
if (create != null && cacheType.equals(cacheManagerDatabaseType)) {
boolean dbCreationSupport = true;
String databaseDriver = dbCacheProp.getProperty("jdbc.driver.class_name");
String sqlCreateTableFileName = "/create_cache_table_";
String sqlTest = "select * from CacheTable limit 1";
String sqlRequest = "";
if (sqlServerDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "sqlserver.sql";
sqlTest = "select top 1 * FROM CacheTable";
} else if (mySQLDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "mysql.sql";
sqlTest = "select * from CacheTable limit 1";
} else if (oracleDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "oracle.sql";
sqlTest = "select * from CacheTable where rownum <= 1";
dbCreationSupport = false;
}
if (dbCreationSupport) {
// Create Cache table into Database
String fileName = Engine.WEBAPP_PATH + "/WEB-INF/sql" + sqlCreateTableFileName;
BufferedReader br = new BufferedReader(new FileReader(fileName.toString()));
try {
SqlRequester sqlRequester = null;
java.sql.Statement statement = null;
while ((sqlRequest = br.readLine()) != null) {
try {
sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
sqlRequester.open();
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest = sqlRequest.substring(0, sqlRequest.length() - 1);
sqlRequest = sqlRequest.replaceAll("CacheTable", cacheTableName);
statement = sqlRequester.connection.createStatement();
statement.execute(sqlRequest);
ServiceUtils.addMessage(document, root, "Request: \"" + sqlRequest + "\" executed.", "message");
} finally {
if (statement != null) {
statement.close();
}
sqlRequester.close();
}
}
ServiceUtils.addMessage(document, root, "Cache table created.", "message");
} catch (Exception e) {
throw new ServiceException("Unable to create the cache table.", e);
} finally {
br.close();
}
}
// Test if Cache table exist
SqlRequester sqlRequester = null;
java.sql.Statement statement = null;
try {
sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
sqlRequester.open();
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest = sqlTest.replaceAll("CacheTable", cacheTableName);
statement = sqlRequester.connection.createStatement();
statement.execute(sqlRequest);
ServiceUtils.addMessage(document, root, "Request: \"" + sqlRequest + "\" executed.", "message");
ServiceUtils.addMessage(document, root, "Cache table tested.", "message");
} catch (Exception e) {
throw new ServiceException("Unable to test the cache table.", e);
} finally {
if (statement != null) {
statement.close();
}
sqlRequester.close();
}
}
restartCacheManager();
}
use of com.twinsoft.convertigo.engine.util.SqlRequester in project convertigo by convertigo.
the class Supervision method getServiceResult.
@Override
protected String getServiceResult(HttpServletRequest request) throws Exception {
boolean isConvertigoStarted = Engine.isStarted;
boolean bCacheDatabase = false;
String cacheType = EnginePropertiesManager.getProperty(PropertyName.CACHE_MANAGER_CLASS);
if ("com.twinsoft.convertigo.engine.cache.DatabaseCacheManager".equals(cacheType)) {
try {
SqlRequester sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
sqlRequester.open();
Statement statement = null;
ResultSet resultSet = null;
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_GET_CACHE_ENTRY));
sqlRequest.replace("{RequestString}", "<supervision>");
String sSqlRequest = sqlRequest.toString();
try {
statement = sqlRequester.connection.createStatement();
resultSet = statement.executeQuery(sSqlRequest);
} finally {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
sqlRequester.close();
}
bCacheDatabase = true;
} catch (Exception e) {
System.err.println("supervision: error while the database access for the Convertigo Cache");
e.printStackTrace();
}
}
String result = "";
result += "convertigo.started=" + (isConvertigoStarted ? "OK" : "KO") + "\n";
result += "convertigo.database.cache=" + (bCacheDatabase ? "OK" : "KO") + "\n";
return result;
}
Aggregations