class InvitecodeMgmtService {

    /**
     * Logger.
     */
    private static final Logger LOGGER = LogManager.getLogger(InvitecodeMgmtService.class);

    /**
     * Invitecode repository.
     */
    @Inject
    private InvitecodeRepository invitecodeRepository;

    /**
     * Expires invitecodes.
     */
    @Transactional
    public void expireInvitecodes() {
        final long now = System.currentTimeMillis();
        final long expired = now - Symphonys.INVITECODE_EXPIRED;

        final Query query = new Query().setPage(1, Integer.MAX_VALUE).
                setFilter(CompositeFilterOperator.and(
                        new PropertyFilter(Invitecode.STATUS, FilterOperator.EQUAL, Invitecode.STATUS_C_UNUSED),
                        new PropertyFilter(Invitecode.GENERATOR_ID, FilterOperator.NOT_EQUAL, Pointtransfer.ID_C_SYS),
                        new PropertyFilter(Keys.OBJECT_ID, FilterOperator.LESS_THAN_OR_EQUAL, expired)
                ));

        JSONObject result;
        try {
            result = invitecodeRepository.get(query);
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Gets invitecodes failed", e);
            return;
        }

        final List<JSONObject> data = (List<JSONObject>) result.opt(Keys.RESULTS);
        try {
            for (final JSONObject invitecode : data) {
                final String invitecodeId = invitecode.optString(Keys.OBJECT_ID);
                invitecodeRepository.remove(invitecodeId);
            }
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Expires invitecodes failed", e);
        }
    }

    /**
     * User generates an invitecode.
     *
     * @param userId   the specified user id
     * @param userName the specified user name
     * @return invitecode
     */
    public String userGenInvitecode(final String userId, final String userName) {
        final Transaction transaction = invitecodeRepository.beginTransaction();

        try {
            final String ret = RandomStringUtils.randomAlphanumeric(16);
            final JSONObject invitecode = new JSONObject();
            invitecode.put(Invitecode.CODE, ret);
            invitecode.put(Invitecode.MEMO, "User [" + userName + "," + userId + "] generated");
            invitecode.put(Invitecode.STATUS, Invitecode.STATUS_C_UNUSED);
            invitecode.put(Invitecode.GENERATOR_ID, userId);
            invitecode.put(Invitecode.USER_ID, "");
            invitecode.put(Invitecode.USE_TIME, 0);

            invitecodeRepository.add(invitecode);

            transaction.commit();

            return ret;
        } catch (final RepositoryException e) {
            if (transaction.isActive()) {
                transaction.rollback();
            }

            LOGGER.log(Level.ERROR, "Generates invitecode failed", e);

            return null;
        }
    }

    /**
     * Admin generates invitecodes with the specified quantity and memo.
     *
     * @param quantity the specified quantity
     * @param memo     the specified memo
     */
    public void adminGenInvitecodes(final int quantity, final String memo) {<FILL_FUNCTION_BODY>}

    /**
     * Updates the specified invitecode by the given invitecode id.
     *
     * @param invitecodeId the given invitecode id
     * @param invitecode   the specified invitecode
     * @throws ServiceException service exception
     */
    public void updateInvitecode(final String invitecodeId, final JSONObject invitecode) throws ServiceException {
        final Transaction transaction = invitecodeRepository.beginTransaction();

        try {
            invitecodeRepository.update(invitecodeId, invitecode);

            transaction.commit();
        } catch (final RepositoryException e) {
            if (transaction.isActive()) {
                transaction.rollback();
            }

            LOGGER.log(Level.ERROR, "Updates an invitecode[id=" + invitecodeId + "] failed", e);
            throw new ServiceException(e);
        }
    }
}

        final Transaction transaction = invitecodeRepository.beginTransaction();

        try {
            for (int i = 0; i < quantity; i++) {
                final JSONObject invitecode = new JSONObject();
                invitecode.put(Invitecode.CODE, RandomStringUtils.randomAlphanumeric(16));
                invitecode.put(Invitecode.MEMO, memo);
                invitecode.put(Invitecode.STATUS, Invitecode.STATUS_C_UNUSED);
                invitecode.put(Invitecode.GENERATOR_ID, Pointtransfer.ID_C_SYS);
                invitecode.put(Invitecode.USER_ID, "");
                invitecode.put(Invitecode.USE_TIME, 0);

                invitecodeRepository.add(invitecode);
            }

            transaction.commit();
        } catch (final RepositoryException e) {
            if (transaction.isActive()) {
                transaction.rollback();
            }

            LOGGER.log(Level.ERROR, "Generates invitecodes failed", e);
        }
    
<no_super_class>