@Override @Transactional public int softDelete(String uriKey) { int atomicNumber = DaoHelper.fromOtherBaseToDecimal(31, uriKey); Query query = getEntityManager() .createQuery( "UPDATE " + getEntityName() + " o SET o.isActive = :isActive WHERE o.atomicNumber = :atomicNumber"); query.setParameter("atomicNumber", atomicNumber); query.setParameter("isActive", false); int updated = query.executeUpdate(); return updated; }
@Override public T getByKey(String uriKey) { // It's possible the key is null, so check first if (uriKey == null) return null; // Convert to atomic number and search int atomicNumber = DaoHelper.fromOtherBaseToDecimal(31, uriKey); Query query = getEntityManager() .createQuery( "SELECT o FROM " + getEntityName() + " o WHERE o.atomicNumber = :atomicNumber"); query.setParameter("atomicNumber", atomicNumber); List<T> resultList = query.getResultList(); if (resultList.isEmpty()) { return null; } assert resultList.size() == 1 : "id should be unique"; return (T) resultList.get(0); }
@Override public String getUriKey() { return DaoHelper.fromDecimalToOtherBase(31, getAtomicNumber()); }