Skip to content

Commit

Permalink
LIMIT not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuechner committed May 9, 2022
1 parent 62ad324 commit de18199
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static List<BeaconFile> getBeaconFiles(TYPE type, boolean onlyLatest) {
String qs = "SELECT f FROM BeaconFile AS f ";

if (onlyLatest && lastDate != null && type != null) {
qs += "WHERE f.created = :lastDate AND f.type = :type";
qs += "WHERE f.created = :lastDate AND f.type = :type ";
} else if (onlyLatest && lastDate != null) {
qs += "WHERE f.created = :lastDate ";
} else if (type != null) {
Expand All @@ -93,10 +93,6 @@ public static List<BeaconFile> getBeaconFiles(TYPE type, boolean onlyLatest) {

qs += "ORDER BY f.created DESC, f.type, f.sector ";

if (onlyLatest) {
qs += "LIMIT 1";
}

final EntityManager em = EntityManagerUtil.getInstance().getEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
Expand All @@ -111,6 +107,10 @@ public static List<BeaconFile> getBeaconFiles(TYPE type, boolean onlyLatest) {
q2.setParameter("type", type);
}

if (onlyLatest) {
q2.setMaxResults(1);
}

final List<BeaconFile> result = q2.getResultList();
return result;
} catch (Exception e) {
Expand Down Expand Up @@ -139,14 +139,17 @@ public static List<BeaconFile> getBeaconFiles(TYPE type, SECTOR sector, boolean
qs += "f.type = :type AND ";
}

qs += "f.sector = :mysector ORDER BY f.created DESC, f.type, f.sector";
qs += "f.sector = :mysector ORDER BY f.created DESC, f.type, f.sector ";

final EntityManager em = EntityManagerUtil.getInstance().getEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
try {
final Query q2 = em.createQuery(qs, BeaconFile.class);
q2.setParameter("mysector", sector);
if (onlyLatest) {
q2.setMaxResults(1);
}
if (type != null) {
q2.setParameter("type", type);
}
Expand Down Expand Up @@ -179,7 +182,6 @@ public static Date getLastDate(TYPE type) {
}

qs += "ORDER BY f.created DESC ";
qs += "LIMIT 1";

final EntityManager em = EntityManagerUtil.getInstance().getEntityManager();
final EntityTransaction tx = em.getTransaction();
Expand Down

0 comments on commit de18199

Please sign in to comment.