use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class BuildRevisionInvariantDAO method create.
@Override
public Answer create(BuildRevisionInvariant buildRevisionInvariant) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO buildrevisioninvariant (system, level, seq, versionname) ");
query.append("VALUES (?, ?, ?, ?)");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, buildRevisionInvariant.getSystem());
preStat.setInt(2, buildRevisionInvariant.getLevel());
preStat.setInt(3, buildRevisionInvariant.getSeq());
preStat.setString(4, buildRevisionInvariant.getVersionName());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class BuildRevisionInvariantDAO method update.
@Override
public Answer update(String system, Integer level, Integer seq, BuildRevisionInvariant buildRevisionInvariant) {
MessageEvent msg = null;
final String query = "UPDATE buildrevisioninvariant SET system = ?, level = ?, seq = ?, versionname = ? WHERE system = ? and level = ? and seq = ? ";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, buildRevisionInvariant.getSystem());
preStat.setInt(i++, buildRevisionInvariant.getLevel());
preStat.setInt(i++, buildRevisionInvariant.getSeq());
preStat.setString(i++, buildRevisionInvariant.getVersionName());
preStat.setString(i++, system);
preStat.setInt(i++, level);
preStat.setInt(i++, seq);
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class AppServiceContentDAO method create.
@Override
public Answer create(AppServiceContent object) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO appservicecontent (`service`, `key`, `value`, `sort`, `active`, `description`, `usrcreated`) ");
query.append("VALUES (?,?,?,?,?,?,?)");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
try {
int i = 1;
preStat.setString(i++, object.getService());
preStat.setString(i++, object.getKey());
preStat.setString(i++, object.getValue());
preStat.setInt(i++, object.getSort());
preStat.setString(i++, object.getActive());
preStat.setString(i++, object.getDescription());
preStat.setString(i++, object.getUsrCreated());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class AppServiceContentDAO method update.
@Override
public Answer update(String service, String key, AppServiceContent object) {
MessageEvent msg = null;
final String query = "UPDATE appservicecontent SET `Service` = ?, `Key` = ?, description = ?, sort = ?, `active` = ?, `value` = ?, " + "dateModif = NOW(), usrModif= ? WHERE `Service` = ? and `Key` = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.service : " + object.getService());
LOG.debug("SQL.param.key : " + object.getKey());
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
int i = 1;
preStat.setString(i++, object.getService());
preStat.setString(i++, object.getKey());
preStat.setString(i++, object.getDescription());
preStat.setInt(i++, object.getSort());
preStat.setString(i++, object.getActive());
preStat.setString(i++, object.getValue());
preStat.setString(i++, object.getUsrModif());
preStat.setString(i++, service);
preStat.setString(i++, key);
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class UserDAO method create.
@Override
public Answer create(User user) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO user (Login, Password, Name, Request, ReportingFavorite, RobotHost, DefaultSystem, Team, Language, Email, UserPreferences)");
query.append(" VALUES (?, SHA(?), ?, ?, ?, ?, ?, ?, ?, ?, '')");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, user.getLogin());
preStat.setString(2, user.getPassword());
preStat.setString(3, user.getName());
preStat.setString(4, user.getRequest());
preStat.setString(5, user.getReportingFavorite());
preStat.setString(6, user.getRobotHost());
preStat.setString(7, user.getDefaultSystem());
preStat.setString(8, user.getTeam());
preStat.setString(9, user.getLanguage());
preStat.setString(10, user.getEmail());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
return new Answer(msg);
}
Aggregations