Search in sources :

Example 6 with DatabaseSpring

use of org.cerberus.database.DatabaseSpring in project cerberus-source by cerberustesting.

the class RobotDAO method readByKey.

@Override
public Robot readByKey(String robot) throws CerberusException {
    Robot result;
    final String query = "SELECT * FROM `robot` WHERE `robot` = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    try {
        result = RequestDbUtils.executeQuery(databaseSpring, query, ps -> {
            ps.setString(1, robot);
        }, rs -> {
            return loadFromResultSet(rs);
        });
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR), exception);
    }
    // sets the message
    return result;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) Connection(java.sql.Connection) Autowired(org.springframework.beans.factory.annotation.Autowired) ParameterParserUtil(org.cerberus.util.ParameterParserUtil) MessageEventEnum(org.cerberus.enums.MessageEventEnum) ArrayList(java.util.ArrayList) StringUtil(org.cerberus.util.StringUtil) Strings(com.google.common.base.Strings) SQLException(java.sql.SQLException) DatabaseSpring(org.cerberus.database.DatabaseSpring) SqlUtil(org.cerberus.util.SqlUtil) ResultSet(java.sql.ResultSet) Map(java.util.Map) IFactoryRobot(org.cerberus.crud.factory.IFactoryRobot) MessageEvent(org.cerberus.engine.entity.MessageEvent) RequestDbUtils(org.cerberus.crud.utils.RequestDbUtils) Repository(org.springframework.stereotype.Repository) FactoryRobot(org.cerberus.crud.factory.impl.FactoryRobot) Answer(org.cerberus.util.answer.Answer) CerberusException(org.cerberus.exception.CerberusException) PreparedStatement(java.sql.PreparedStatement) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Robot(org.cerberus.crud.entity.Robot) IRobotDAO(org.cerberus.crud.dao.IRobotDAO) Statement(java.sql.Statement) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) AnswerItem(org.cerberus.util.answer.AnswerItem) LogManager(org.apache.logging.log4j.LogManager) MessageGeneralEnum(org.cerberus.enums.MessageGeneralEnum) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) IFactoryRobot(org.cerberus.crud.factory.IFactoryRobot) FactoryRobot(org.cerberus.crud.factory.impl.FactoryRobot) Robot(org.cerberus.crud.entity.Robot)

Aggregations

Connection (java.sql.Connection)6 DatabaseSpring (org.cerberus.database.DatabaseSpring)6 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 ServletException (javax.servlet.ServletException)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ArrayList (java.util.ArrayList)2 ILogEventService (org.cerberus.crud.service.ILogEventService)2 MessageEvent (org.cerberus.engine.entity.MessageEvent)2 AnswerItem (org.cerberus.util.answer.AnswerItem)2 AnswerList (org.cerberus.util.answer.AnswerList)2 PolicyFactory (org.owasp.html.PolicyFactory)2 Strings (com.google.common.base.Strings)1 Statement (java.sql.Statement)1 List (java.util.List)1 Map (java.util.Map)1 LogManager (org.apache.logging.log4j.LogManager)1