Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

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

License:EUPL

public static OASessionStore searchActiveOASSOSession(AuthenticationSession moaSession, String oaID,
        String protocolType) {//w w w.  ja  va2 s .  c o  m
    MiscUtil.assertNotNull(moaSession, "MOASession");
    MiscUtil.assertNotNull(oaID, "OnlineApplicationIdentifier");
    MiscUtil.assertNotNull(protocolType, "usedProtocol");
    Logger.trace("Get active OnlineApplication for sessionID " + moaSession.getSessionID() + " with OAID "
            + oaID + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<AuthenticatedSessionStore> result;

    synchronized (session) {
        session.beginTransaction();
        Query query = session.getNamedQuery("getActiveOAWithSessionIDandOAIDandProtocol");
        query.setParameter("sessionID", moaSession.getSessionID());
        query.setParameter("oaID", oaID);
        query.setParameter("protocol", protocolType);
        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).getActiveOAsessions().get(0);
}

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

License:EUPL

public static AuthenticationSession getSessionWithPendingRequestID(String pedingRequestID) {
    try {//from w w  w .j  a  va2 s. co  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 www  .j  a  v a  2s.c  om*/
        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 {//w w  w  .  java2 s  .c o  m
        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();/*from  w  w  w .java  2  s . co  m*/
        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  va 2  s . c  om
    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();/*from   w  w w .j  a  v a2 s .  co 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/*  w  w 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  a  v a  2 s . co  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  w w w  .j a  v a2s.c om

    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);
}