public Message dequeueMessage(int reqClientId, int partSenderId, int queueId, boolean peek) throws MessageDequeueException, MessageDequeueQueueDoesNotExistException, MessageDequeueEmptyQueueException, MessageDequeueNotIntendedReceiverException {
        if (!(queueId == 0 && partSenderId == 0)) {
            try {
                CallableStatement callStat = _connection.prepareCall("{ call dequeueMessage(?,?,?,?) }");
                callStat.setInt(1, reqClientId);
                callStat.setInt(2, partSenderId);
                callStat.setInt(3, queueId);
                if (peek) {
                    callStat.setInt(4, 1);
                }
                callStat.setInt(4, 0);

                long startTime = System.nanoTime();
                ResultSet resSet = callStat.executeQuery();
                long stopTime = System.nanoTime();
                _EVALLOG6.log(startTime + "," + stopTime + ",DB_QUERY_DEQUEUE");


                resSet.next(); // if result set is empty we get an exception
                Message message = DBModelFactory.createMessage(resSet.getInt(1), resSet.getInt(2), resSet.getInt(3),
                        resSet.getInt(4), resSet.getTimestamp(5), resSet.getString(6));
                resSet.close();
                callStat.close();
                return message;
            } catch (SQLException e) {
                if (e.getSQLState().equals("V2007")) {
                    throw new MessageDequeueQueueDoesNotExistException(e);
                } else if (e.getSQLState().equals("V2008")) {
                    throw new MessageDequeueEmptyQueueException(e);
                } else if (e.getSQLState().equals("V2009") || e.getSQLState().equals("V2010") || e.getSQLState().equals("V2011")) {
                    throw new MessageDequeueNotIntendedReceiverException(e);
                }
                throw new MessageDequeueException(new Exception());
            }
        } else {
            throw new MessageDequeueException(new Exception());
        }
    }