public ServerMessage handleMessage(ClientMessage msg) {

        ErrorBundle errorBundle = new ErrorBundle();
        errorBundle.setClientMessage(msg);

        ClientMessageTypes type = msg.getType();
        switch (type) {
            case DELETE:
            case UPDATE_CELL:
            case UPDATE_ROW:
            case ADD:

                String query = createQuery(msg);

                if (query.equals(DOCTOR_COUNT_LIMIT_ERROR)) {
                    errorBundle.setErrorMsg(DOCTOR_COUNT_LIMIT_ERROR);
                    logger.log(Level.INFO, DOCTOR_COUNT_LIMIT_ERROR);
                    return createErrorMessage(errorBundle, ServerMessageTypes.QUERY_ERROR);
                }
                try {
                    if (connection.execute(query)) {
                        logger.log(Level.INFO, SUCCESSFUL_SQL_QUERY + query);
                        return createMessageResultSet(null, ServerMessageTypes.QUERY_OK);
                    } else {
                        logger.log(Level.SEVERE, ABSENT_DATABASE + query);
                        errorBundle.setErrorMsg(ABSENT_DATABASE + query);
                        return createErrorMessage(errorBundle, ServerMessageTypes.QUERY_ERROR);
                    }
                } catch (SQLException e) {
                    logger.log(Level.SEVERE, SQL_ERROR + e.getMessage());
                    errorBundle.setErrorMsg(e.getSQLState() + e.getMessage());
                    errorBundle.setErrorCode(e.getErrorCode());
                    return createErrorMessage(errorBundle, ServerMessageTypes.QUERY_ERROR);
                }


            default:
                ResultSet rSet = null;
                query = createQuery(msg);

                try {
                    rSet = connection.executeQuery(createQuery(msg));
                    if (rSet == null) {
                        errorBundle.setErrorMsg(ABSENT_DATABASE + query);
                        logger.log(Level.SEVERE, ABSENT_DATABASE + query);
                        return createErrorMessage(errorBundle, ServerMessageTypes.QUERY_ERROR);
                    }
                } catch (SQLException e) {
                    logger.log(Level.SEVERE, SQL_ERROR + e.getErrorCode() + e.getMessage());
                    errorBundle.setErrorMsg(e.getMessage() + e.getSQLState() + e.getErrorCode());
                    return createErrorMessage(errorBundle, ServerMessageTypes.QUERY_ERROR);
                }

                return createMessageResultSet(rSet, ServerMessageTypes.QUERY_OK);
        }

    }