Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

In this page you can find the example usage for javax.persistence Query getResultList.

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static OnlineApplication getOnlineApplication(long dbid) {
    MiscUtil.assertNotNull(dbid, "OnlineApplictionID");
    Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database.");

    List result;// w w  w  .ja  v a  2s  .c o  m
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithDBID"));
    //query.setParameter("id", id+"%");
    query.setParameter("id", dbid);
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }

    return (OnlineApplication) result.get(0);
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static OnlineApplication getOnlineApplication(String id) {
    MiscUtil.assertNotNull(id, "OnlineApplictionID");
    Logger.trace("Getting OnlineApplication with ID " + id + " from database.");

    List result;//from  w w w  .j av  a 2s  .  c  o m
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithID"));
    //query.setParameter("id", id+"%");
    query.setParameter("id", id);
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }

    if (result.size() > 1) {
        Logger.warn("OAIdentifier match to more then one DB-entry!");
        return null;
    }

    return (OnlineApplication) result.get(0);
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static OnlineApplication getActiveOnlineApplication(String id) {
    MiscUtil.assertNotNull(id, "OnlineApplictionID");
    Logger.trace("Getting OnlineApplication with ID " + id + " from database.");

    List result;//from   w ww  .  j  a v a  2 s. co  m
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getActiveOnlineApplicationWithID"));
    //query.setParameter("id", id+"%");
    query.setParameter("id", StringEscapeUtils.escapeHtml4(id));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.debug("No entries found.");
        return null;
    }

    if (result.size() > 1) {
        Logger.warn("OAIdentifier match to more then one DB-entry!");
        return null;
    }

    return (OnlineApplication) result.get(0);
}

From source file:models.ModuleVersion.java

public static SortedMap<String, SortedSet<ModuleVersion>> findDependants(String moduleName, String version) {
    String query = "SELECT d.version, v FROM ModuleVersion v JOIN v.dependencies d LEFT JOIN FETCH v.module WHERE d.name=:name";
    if (version != null && !version.isEmpty()) {
        query += " AND d.version=:version";
    }/*from  ww  w .  ja  v  a2s  .c  om*/
    Query jpa = JPA.em().createQuery(query).setParameter("name", moduleName);
    if (version != null && !version.isEmpty()) {
        jpa.setParameter("version", version);
    }
    List<Object[]> results = jpa.getResultList();

    Comparator<String> versionComparator = new Comparator<String>() {
        @Override
        public int compare(String v1, String v2) {
            return Util.compareVersions(v1, v2);
        }
    };

    Comparator<ModuleVersion> dependantComparator = new Comparator<ModuleVersion>() {
        @Override
        public int compare(ModuleVersion v1, ModuleVersion v2) {
            int result = v1.module.name.compareTo(v2.module.name);
            if (result == 0) {
                result = Util.compareVersions(v1.version, v2.version);
            }
            return result;
        }
    };

    SortedMap<String, SortedSet<ModuleVersion>> dependantsMap = new TreeMap<String, SortedSet<ModuleVersion>>(
            versionComparator);
    for (Object[] result : results) {
        String ver = (String) result[0];
        ModuleVersion dependant = (ModuleVersion) result[1];

        SortedSet<ModuleVersion> dependants = dependantsMap.get(ver);
        if (dependants == null) {
            dependants = new TreeSet<ModuleVersion>(dependantComparator);
            dependantsMap.put(ver, dependants);
        }
        dependants.add(dependant);
    }

    return dependantsMap;
}

From source file:entity.files.SYSFilesTools.java

/**
 * <code>putFile(String)</code> speichert eine Datei auf dem FTP Server ab und erstellt eine SYSFiles EntityBean. Die Methode geht dabei wie folgt vor:
 * <ol>// w  ww .jav  a  2s  .  c o  m
 * <li>Zuerst wird der MD5 der zu speichernden Datei berechnet.</li>
 * <li>Anhand dieser MD5 Signatur wird ermittelt, ob es schon einen entsprechenden Eintrag in der Datenbank gibt.
 * <ul>
 * <li>Wenn ja, dann wird einfach der PK zurckgegeben. Nochmal speichern braucht man das ja nicht. <b>RETURN</b></li>
 * <li>Wenn nicht, dann geht die Bearbeitung weiter.</li>
 * </ul>
 * <li>Erstellen einer SYSFiles EB</li>
 * <li>Senden der Datei an den FTP Server</li>
 * <li>Wenn die letzten beiden Schritte erfolgreich waren, dann wird die neue EB als Ergebnis zurck gegeben. null, bei Fehler.</li>
 * </ol>
 *
 * @param file File Objekt der zu speichernden Datei
 * @return EB der neuen Datei. null bei Fehler.
 */
private static SYSFiles putFile(EntityManager em, FileTransferClient ftp, File file) throws Exception {
    SYSFiles sysfile = null;

    String md5 = SYSTools.getMD5Checksum(file);
    Query query = em.createQuery("SELECT s FROM SYSFiles s WHERE s.md5 = :md5");
    query.setParameter("md5", md5);

    ArrayList<SYSFiles> alreadyExistingFiles = new ArrayList<SYSFiles>(query.getResultList());

    // Gibts die Datei schon ?
    if (alreadyExistingFiles.isEmpty()) { // nein, noch nicht
        sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(),
                OPDE.getLogin().getUser()));
        //            FileInputStream fis = new FileInputStream(file);
        ftp.uploadFile(file.getPath(), sysfile.getRemoteFilename());

        //            ftp.storeF.storeFile(file.getPath(),sysfile.getRemoteFilename());
        OPDE.info(
                SYSTools.xx("misc.msg.upload") + ": " + sysfile.getFilename() + " (" + sysfile.getMd5() + ")");
        //            fis.close();
    } else { // Ansonsten die bestehende Datei zurckgeben

        sysfile = alreadyExistingFiles.get(0);

        // Does the User own this file already ?
        //            for (SYSFiles mySYSfile : alreadyExistingFiles) {
        //                if (mySYSfile.getResident().equals(resident)) {
        //                    sysfile = mySYSfile;
        //                    break;
        //                }
        //            }
        //            if (sysfile == null) {
        //                sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(), OPDE.getLogin().getUser(), resident));
        //            }
    }

    return sysfile;
}

From source file:mx.com.misha.demo.trabajadornomina.persistence.TrabajadorDaoImpl.java

@Override
public List<Trabajador> buscarTodos() {
    String query = "select t from Trabajador t";
    Query q = em.createQuery(query);

    return q.getResultList();
}

From source file:bankconsoleapp.repositories.EmployeeDao.java

public List<Employee> getAllEmp() {

    Query q = em.createQuery("FROM Employee");
    List<Employee> emp = q.getResultList();
    return emp;//w  ww . jav  a 2 s  .  c  om

}

From source file:com.tamnd.app.core.repositories.jpa.AccountRepoImpl.java

@Override
public List<Account> findAllAccounts() {
    Query query = em.createQuery("SELECT a FROM Account a");
    return query.getResultList();
}

From source file:dev.archiecortez.jfacelog.services.EmployeeDTO.java

public List<DTREmployee> listEmployees() {
    Query q = em.createQuery("select e from DTREmployee e");
    return q.getResultList();
}

From source file:com.consol.citrus.samples.flightbooking.persistence.impl.FlightDaoImpl.java

@SuppressWarnings("unchecked")
public List<Flight> findAll() {
    Query query = em.createQuery("from FlightEntity f");

    return query.getResultList();
}