Archive for category JPA

JPQL

Delete statement


@Transactional
public void delete(String date) {
logger.info("calling delete metod...");
StringBuffer queryBuffer = new StringBuffer(" delete from ListChangeNotification p where p.incomingSequenceTimestamp<= to_date ( ?1, 'dd/MM/yyyy hh24:mi:ss' ) ");
Query query = em.createQuery(queryBuffer.toString());
query.setParameter(1, date);
int deletedRows = query.executeUpdate();
logger.info(deletedRows + " deleteted from ListChangeNotification table ");

}
</

Select Statement-Dynamic
public List getScheduledJob(String startTime, String currentTime, String endTime,
boolean isEndTimeGreaterThanCurrentTime) {
// TODO Auto-generated method stub
TypedQuery query = null;
StringBuffer queryBuffer = new StringBuffer(” select p from ScheduledJob p “);
if (startTime != null && endTime != null) {

if (isEndTimeGreaterThanCurrentTime) {
queryBuffer.append(” where p.startTime>= to_date ( ?1, ‘dd/MM/yyyy hh24:mi’ )”);
queryBuffer.append(” and p.startTime<= to_date ( ?2, 'dd/MM/yyyy hh24:mi' )");
//create query
query = (TypedQuery) em.createQuery(queryBuffer.toString());
//set parameter
query.setParameter(1, startTime);
query.setParameter(2, currentTime);

} else {
queryBuffer.append(” where p.startTime>= to_date ( ?1, ‘dd/MM/yyyy hh24:mi’ )”);
queryBuffer.append(” and p.startTime<= to_date ( ?2, 'dd/MM/yyyy hh24:mi' )");
//create query
query = (TypedQuery) em.createQuery(queryBuffer.toString());
//set parameter
query.setParameter(1, startTime);
query.setParameter(2, endTime);

}

}

List list = query.getResultList();
return list;
}

, , , , ,

Leave a comment