Example usage for org.hibernate Query setTimestamp

List of usage examples for org.hibernate Query setTimestamp

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setTimestamp(String name, Date value) 

Source Link

Document

Bind the value and the time of a given Date object to a named query parameter.

Usage

From source file:ar.com.zauber.commons.web.cache.impl.repo.hibernate.HibernateLastModifiedRepository.java

License:Apache License

/** @see LastModifiedRepository#updateTimestamp(EntityKey, Date) */
@Transactional/*from w  ww. j  a  v a2  s  . c  o  m*/
public final void updateTimestamp(final StringEntityKey key, final Date timestamp) {
    Validate.notNull(key);
    Validate.notNull(timestamp);

    Query query = this.sessionFactory.getCurrentSession().getNamedQuery("lastModified.updateForEntity");

    query.setString("entityKey", key.getAsString());
    query.setTimestamp("timestamp", timestamp);
    int updatedEntities = query.executeUpdate();

    // create record if no one exist
    if (updatedEntities == 0) {
        this.sessionFactory.getCurrentSession().save(new LastModifiedRecord(timestamp, key.getAsString()));
    }
}

From source file:at.gv.egovernment.moa.id.monitoring.DatabaseTestModule.java

License:EUPL

private String testMOASessionDatabase() throws Exception {
    Logger.trace("Start Test: MOASessionDatabase");

    Date expioredate = new Date(new Date().getTime() - 120);

    try {/* w  w w  . jav  a 2  s  .  c  o m*/
        List<AssertionStore> results;
        Session session = MOASessionDBUtils.getCurrentSession();

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getAssertionWithTimeOut");
            query.setTimestamp("timeout", expioredate);
            results = query.list();
            session.getTransaction().commit();
        }

        Logger.trace("Finish Test: MOASessionDatabase");
        return null;

    } catch (Throwable e) {
        Logger.warn("Failed Test: MOASessionDatabase", e);
        return "MOASessionDatabase: " + e.getMessage();
    }
}

From source file:at.gv.egovernment.moa.id.monitoring.DatabaseTestModule.java

License:EUPL

private String testMOAAdvancedLoggingDatabase() {

    Date expioredate = new Date(new Date().getTime() - 120);
    try {//from w  ww . java2  s.c  om
        Session session = StatisticLogDBUtils.getCurrentSession();

        List<StatisticLog> results;

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getAllEntriesNotBeforeTimeStamp");
            query.setTimestamp("timeout", expioredate);
            results = query.list();
            session.getTransaction().commit();
        }

        Logger.trace("Finish Test: AdvancedLoggingDataBase");
        return null;

    } catch (Throwable e) {
        Logger.warn("Failed Test: AdvancedLoggingDataBase", e);
        return "AdvancedLoggingDataBase: " + e.getMessage();
    }
}

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

License:EUPL

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

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

    synchronized (session) {
        session.beginTransaction();/*from  w w w .j  a va  2  s.  com*/
        Query query = session.getNamedQuery("getAssertionWithTimeOut");
        query.setTimestamp("timeout", expioredate);
        results = query.list();
        session.getTransaction().commit();
    }

    if (results.size() != 0) {
        for (AssertionStore result : results) {
            try {
                cleanDelete(result);
                Logger.info("Remove sessioninformation with ID=" + result.getArtifact() + " after timeout.");

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

        }
    }
}

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  2s. 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.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();/* w w w. j  a va2  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);
            }

        }
    }
}

From source file:au.edu.uts.eng.remotelabs.schedserver.session.SessionActivator.java

License:Open Source License

@Override
public void stop(BundleContext context) throws Exception {
    this.logger.info("Stopping the Session bundle...");
    this.soapReg.unregister();
    this.terminatorService.unregister();
    this.sessionCheckerReg.unregister();
    SessionActivator.bookingsTracker.close();

    /* Terminate all in progress sessions. */
    Session ses = DataAccessActivator.getNewSession();
    if (ses != null) {
        Query qu = ses
                .createQuery("UPDATE Session SET active=:false, removal_reason=:reason, removal_time=:time "
                        + " WHERE active=:true");
        qu.setBoolean("false", false);
        qu.setBoolean("true", true);
        qu.setString("reason", "Scheduling Server shutting down.");
        qu.setTimestamp("time", new Date());

        ses.beginTransaction();//from  w  w  w . j  ava  2  s . c  o m
        int num = qu.executeUpdate();
        ses.getTransaction().commit();
        this.logger.info("Terminated " + num + " sessions for shutdown.");
        ses.close();
    }
}

From source file:com.appeligo.alerts.KeywordAlert.java

License:Apache License

public static ChunkedResults<KeywordAlert> getAllInNormalizedQueryOrder() {
    Permissions.checkUser(Permissions.SUPERUSER);
    Session session = getSession();//from   w  ww .  j a  v a  2  s  .  c  o  m
    Query query = session.getNamedQuery("KeywordAlert.getAllInNormalizedQueryOrder");
    query.setTimestamp("latestCreationTime", new Date());
    return new ChunkedResults<KeywordAlert>(query);
}

From source file:com.appeligo.alerts.KeywordMatch.java

License:Apache License

public static void deleteOldProgramMatches() {
    Permissions.checkUser(Permissions.SUPERUSER);
    Session session = getSession();/*from  w  w w.  j a  v a  2s. c o  m*/
    Query query = session.getNamedQuery("KeywordMatch.deleteOldProgramMatches");
    // Make sure it has been at least a half hour since the show
    // ended.  We can't remove the KeywordMatch too quickly (e.g., RIGHT
    // after it ends), or the LiveLuceneIndex may not have yet purged the
    // program, and we would get our match all over again (duplicate
    // keyword alerts were a problem)
    query.setTimestamp("thirtyMinutesAgo", new Date(System.currentTimeMillis() - (30 * 60 * 1000)));
    query.executeUpdate();
}

From source file:com.appeligo.alerts.PendingAlert.java

License:Apache License

public static void deleteOldFired() {
    Permissions.checkUser(Permissions.SUPERUSER);
    Session session = getSession();// w ww . java2 s.  c  o  m
    Query query = session.getNamedQuery("PendingAlert.deleteOldFired");
    query.setTimestamp("currentTime", new Date());
    query.executeUpdate();
}