code: protected int getLastOrderNumber() throws RepositoryException
     {
        checkIfOpened();
        try
        {
           ResultSet count = findLastOrderNumber(1, true);
           try
           {
              if (count.next())
              {
                 return count.getInt(1) - 1;
              }
              else
              {
                 return -1;
              }
           }
           finally
           {
              try
              {
                 count.close();
              }
              catch (SQLException e)
              {
                 LOG.error("Can't close the ResultSet: " + e.getMessage());
              }
           }
        }
        catch (SQLException e)
        {
           throw new RepositoryException(e);
        }
     }
docs: Gets the last order number from the sequence
  @throws RepositoryException if any error occurs while retrieving the
  value of the sequence