Search in sources :

Example 16 with ApplicationObject

use of org.cerberus.crud.entity.ApplicationObject in project cerberus-source by cerberustesting.

the class ApplicationObjectDAO method readByApplication.

@Override
public AnswerList readByApplication(String Application) {
    AnswerList ans = new AnswerList();
    MessageEvent msg = null;
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_APP)) {
        // Prepare and execute query
        preStat.setString(1, Application);
        ResultSet rs = preStat.executeQuery();
        try {
            List<ApplicationObject> al = new ArrayList<ApplicationObject>();
            while (rs.next()) {
                al.add(loadFromResultSet(rs));
            }
            ans.setDataList(al);
            // Set the final message
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "READ_BY_APP");
        } catch (Exception e) {
            LOG.warn("Unable to execute query : " + e.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
        } finally {
            if (rs != null) {
                rs.close();
            }
        }
    } catch (Exception e) {
        LOG.warn("Unable to read by app: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) MessageEvent(org.cerberus.engine.entity.MessageEvent) IFactoryApplicationObject(org.cerberus.crud.factory.IFactoryApplicationObject) ApplicationObject(org.cerberus.crud.entity.ApplicationObject) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

ApplicationObject (org.cerberus.crud.entity.ApplicationObject)16 AnswerItem (org.cerberus.util.answer.AnswerItem)11 IFactoryApplicationObject (org.cerberus.crud.factory.IFactoryApplicationObject)9 MessageEvent (org.cerberus.engine.entity.MessageEvent)9 IApplicationObjectService (org.cerberus.crud.service.IApplicationObjectService)7 JSONObject (org.json.JSONObject)7 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 AnswerList (org.cerberus.util.answer.AnswerList)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 ILogEventService (org.cerberus.crud.service.ILogEventService)3 LogEventService (org.cerberus.crud.service.impl.LogEventService)3 Answer (org.cerberus.util.answer.Answer)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Timestamp (java.sql.Timestamp)2 List (java.util.List)2 Map (java.util.Map)2