private Query createParticipantsDeleteQuery(final Long workoutId, final Set<Long> participants) { final SQLHelper.Predicate idPred = createInListPredicate("USER_ID", participants, "participant"); final Query query = entityManager.createNativeQuery( "delete FROM WORKOUT_USER WHERE WORKOUT_ID = :workoutId AND " + idPred); query.setParameter("workoutId", workoutId); idPred.bindVariables(query); return query; }
private Query createParticipantsInsertUnionQuery( final Long workoutId, final Set<Long> participants) { final SQLHelper.Predicate listPred = createInListPredicate("ID", participants, "participant"); final Query query = entityManager.createNativeQuery( "insert INTO WORKOUT_USER (USER_ID, WORKOUT_ID) SELECT ID, :workoutId FROM USERS WHERE" + " ID not in (select USER_ID from WORKOUT_USER where WORKOUT_ID = :workoutId) and " + listPred); query.setParameter("workoutId", workoutId); listPred.bindVariables(query); return query; }