use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class SqlLibraryDAO method findSqlLibraryByKey.
/**
* Short one line description.
* <p/>
* Longer description. If there were any, it would be here. <p> And even
* more explanations to follow in consecutive paragraphs separated by HTML
* paragraph breaks.
*
* @param name Description text text text.
* @return Description text text text.
*/
@Override
public SqlLibrary findSqlLibraryByKey(String name) throws CerberusException {
boolean throwEx = false;
SqlLibrary result = null;
final String query = "SELECT * FROM sqllibrary WHERE NAME = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, name);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String type = resultSet.getString("Type");
String database = resultSet.getString("Database");
String script = resultSet.getString("Script");
String description = resultSet.getString("Description");
result = factorySqlLib.create(name, type, database, script, description);
} else {
throwEx = true;
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwEx) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SQLLIB_NOT_FOUND));
}
return result;
}
use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class SqlLibraryDAO method readByKey.
@Override
public AnswerItem readByKey(String key) {
AnswerItem a = new AnswerItem();
StringBuilder query = new StringBuilder();
SqlLibrary p = new SqlLibrary();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
query.append("SELECT * FROM sqllibrary `sql` WHERE Name = ?");
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
preStat.setString(1, key);
try (ResultSet resultSet = preStat.executeQuery()) {
// gets the data
while (resultSet.next()) {
p = this.loadFromResultSet(resultSet);
}
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
} catch (SQLException e) {
LOG.error("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));
}
} catch (SQLException e) {
LOG.error("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));
}
a.setResultMessage(msg);
a.setItem(p);
return a;
}
use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class SqlLibraryService method updateSqlLibrary.
@Override
public void updateSqlLibrary(String name, String type, String database, String description, String script) {
try {
SqlLibrary s = sqlLibraryDao.findSqlLibraryByKey(name);
s.setType(type);
s.setDatabase(database);
s.setDescription(description);
s.setScript(script);
sqlLibraryDao.updateSqlLibrary(s);
} catch (CerberusException e) {
LOG.warn("Unable to execute query : " + e.toString());
}
}
Aggregations