Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static AuthenticationSession getSessionWithPendingRequestID(String pedingRequestID) {
    try {/*from  w ww .  java2s  .  c o m*/
        MiscUtil.assertNotNull(pedingRequestID, "pedingRequestID");
        Logger.trace("Get authenticated session with pedingRequestID " + pedingRequestID + " from database.");
        Session session = MOASessionDBUtils.getCurrentSession();

        List<AuthenticatedSessionStore> result;

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getSessionWithPendingRequestID");
            query.setParameter("sessionid", pedingRequestID);
            result = query.list();

            //send transaction
            session.getTransaction().commit();
        }

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

        //Assertion requires an unique artifact
        if (result.size() != 1) {
            Logger.trace("No entries found.");
            return null;
        }

        return decryptSession(result.get(0));

    } catch (Throwable e) {
        Logger.warn("MOASession deserialization-exception by using MOASessionID=" + pedingRequestID);
        return null;
    }
}

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static boolean deleteSessionWithPendingRequestID(String id) {
    MiscUtil.assertNotNull(id, "PendingRequestID");
    Logger.trace("Delete MOAsession with PendingRequestID " + id + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<AuthenticatedSessionStore> result;

    synchronized (session) {
        session.beginTransaction();/*from  ww  w.j  a  v  a  2s .c  o  m*/
        Query query = session.getNamedQuery("getSessionWithPendingRequestID");
        query.setParameter("sessionid", id);
        result = query.list();

        //send transaction
        session.getTransaction().commit();
    }

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

    //Assertion requires an unique artifact
    if (result.size() != 1) {
        Logger.trace("No entries found.");
        return false;

    } else {
        cleanDelete(result.get(0));
        return true;
    }

}

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static AuthenticationSession getSessionWithUserNameID(String nameID) {

    try {/*from ww  w  .j a  va 2  s.  c  om*/
        MiscUtil.assertNotNull(nameID, "nameID");
        Logger.trace("Get authenticated session with pedingRequestID " + nameID + " from database.");
        Session session = MOASessionDBUtils.getCurrentSession();

        List<AuthenticatedSessionStore> result;

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getMOAISessionWithUserNameID");
            query.setParameter("usernameid", StringEscapeUtils.escapeHtml(nameID));
            result = query.list();

            //send transaction
            session.getTransaction().commit();
        }

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

        //Assertion requires an unique artifact
        if (result.size() == 0) {
            Logger.trace("No entries found.");
            return null;
        }

        return decryptSession(result.get(0));

    } catch (Throwable e) {
        Logger.warn("MOASession deserialization-exception by using MOASessionID=" + nameID);
        return null;
    }

}

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static InterfederationSessionStore searchInterfederatedIDPFORSSOWithMOASession(String sessionID) {
    MiscUtil.assertNotNull(sessionID, "MOASession");
    Logger.trace("Get interfederated IDP for SSO with sessionID " + sessionID + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<AuthenticatedSessionStore> result;

    synchronized (session) {
        session.beginTransaction();// w w  w. j a  v a2s .  c om
        Query query = session.getNamedQuery("getInterfederatedIDPForSSOWithSessionID");
        query.setParameter("sessionID", sessionID);
        result = query.list();

        //send transaction
        session.getTransaction().commit();
    }

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

    //Assertion requires an unique artifact
    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;

    }

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

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static InterfederationSessionStore searchInterfederatedIDPFORSSOWithMOASessionIDPID(String sessionID,
        String idpID) {//from w  w w .ja va2s. co  m
    MiscUtil.assertNotNull(sessionID, "MOASession");
    MiscUtil.assertNotNull(idpID, "Interfederated IDP ID");
    Logger.trace(
            "Get interfederated IDP " + idpID + " for SSO with sessionID " + sessionID + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<AuthenticatedSessionStore> result;

    synchronized (session) {
        session.beginTransaction();
        Query query = session.getNamedQuery("getInterfederatedIDPForSSOWithSessionIDIDPID");
        query.setParameter("sessionID", sessionID);
        query.setParameter("idpID", idpID);
        result = query.list();

        //send transaction
        session.getTransaction().commit();
    }

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

    //Assertion requires an unique artifact
    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;

    }

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

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static InterfederationSessionStore searchInterfederatedIDPFORAttributeQueryWithSessionID(
        AuthenticationSession moaSession) {
    MiscUtil.assertNotNull(moaSession, "MOASession");
    Logger.trace("Get interfederated IDP for AttributeQuery with sessionID " + moaSession.getSessionID()
            + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<AuthenticatedSessionStore> result;

    synchronized (session) {
        session.beginTransaction();//w ww. j  a  v  a2 s.  c o m
        Query query = session.getNamedQuery("getInterfederatedIDPForAttributeQueryWithSessionID");
        query.setParameter("sessionID", moaSession.getSessionID());
        result = query.list();

        //send transaction
        session.getTransaction().commit();
    }

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

    //Assertion requires an unique artifact
    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;

    }

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

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

/**
 * @param entityID//from  ww  w. j av  a  2 s  .  c om
 * @param requestID
 */
public static boolean removeInterfederetedSession(String entityID, String pedingRequestID) {

    try {
        Logger.debug("Remove interfederated IDP from local SSO session ...");

        MiscUtil.assertNotNull(pedingRequestID, "pedingRequestID");
        Logger.trace("Get authenticated session with pedingRequestID " + pedingRequestID + " from database.");
        Session session = MOASessionDBUtils.getCurrentSession();

        List<AuthenticatedSessionStore> result;

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getSessionWithPendingRequestID");
            query.setParameter("sessionid", pedingRequestID);
            result = query.list();

            //send transaction
            session.getTransaction().commit();
        }

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

        //Assertion requires an unique artifact
        if (result.size() != 1) {
            Logger.trace("No entries found.");
            return false;
        }

        AuthenticatedSessionStore authsession = result.get(0);

        List<InterfederationSessionStore> idpSessions = authsession.getInderfederation();
        if (idpSessions != null) {
            for (InterfederationSessionStore idp : idpSessions) {
                if (idp.getIdpurlprefix().equals(entityID))
                    idpSessions.remove(idp);

            }
        }

        MOASessionDBUtils.saveOrUpdate(authsession);
        return true;

    } catch (Throwable e) {
        Logger.warn("MOASession deserialization-exception by using MOASessionID=" + pedingRequestID);
        return false;
    }
}

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

public static void clean(long now, long authDataTimeOutCreated, long authDataTimeOutUpdated) {
    Date expioredatecreate = new Date(now - authDataTimeOutCreated);
    Date expioredateupdate = new Date(now - authDataTimeOutUpdated);

    List<AuthenticatedSessionStore> results;
    Session session = MOASessionDBUtils.getCurrentSession();

    synchronized (session) {
        session.beginTransaction();// w w w  .j av  a 2 s. c o m
        Query query = session.getNamedQuery("getMOAISessionsWithTimeOut");
        query.setTimestamp("timeoutcreate", expioredatecreate);
        query.setTimestamp("timeoutupdate", expioredateupdate);
        results = query.list();
        session.getTransaction().commit();
    }

    if (results.size() != 0) {
        for (AuthenticatedSessionStore result : results) {
            try {
                cleanDelete(result);
                Logger.info("Authenticated session with sessionID=" + result.getSessionid()
                        + " after session timeout.");

            } catch (HibernateException e) {
                Logger.warn("Authenticated session with sessionID=" + result.getSessionid()
                        + " not removed after timeout! (Error during Database communication)", e);
            }
        }
    }
}

From source file:at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage.java

License:EUPL

@SuppressWarnings("rawtypes")
private static AuthenticatedSessionStore searchInDatabase(String sessionID, boolean commit)
        throws MOADatabaseException {
    MiscUtil.assertNotNull(sessionID, "moasessionID");
    Logger.trace("Get authenticated session with sessionID " + sessionID + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List result;/*from ww w.  j av  a 2  s .  co m*/

    synchronized (session) {
        session.beginTransaction();
        Query query = session.getNamedQuery("getSessionWithID");
        query.setParameter("sessionid", sessionID);
        result = query.list();

        //send transaction
        if (commit)
            session.getTransaction().commit();
    }

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

    //Assertion requires an unique artifact
    if (result.size() != 1) {
        Logger.trace("No entries found.");
        throw new MOADatabaseException("No session found with this sessionID");
    }

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

From source file:at.gv.egovernment.moa.id.storage.DBExceptionStoreImpl.java

License:EUPL

public void clean(long now, long exceptionTimeOut) {
    Date expioredate = new Date(now - exceptionTimeOut);

    List<ExceptionStore> results;
    Session session = MOASessionDBUtils.getCurrentSession();

    synchronized (session) {
        session.beginTransaction();//from  w w w  . j  av  a2 s  . co m
        Query query = session.getNamedQuery("getExceptionWithTimeOut");
        query.setTimestamp("timeout", expioredate);
        results = query.list();
        session.getTransaction().commit();
    }

    if (results.size() != 0) {
        for (ExceptionStore result : results) {
            try {
                MOASessionDBUtils.delete(result);
                Logger.info("Remove Exception with ID=" + result.getExid() + " after timeout.");

            } catch (HibernateException e) {
                Logger.warn("Exception with ID=" + result.getExid()
                        + " not removed after timeout! (Error during Database communication)", e);
            }

        }
    }
}