Example usage for org.hibernate Session flush

List of usage examples for org.hibernate Session flush

Introduction

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

Prototype

void flush() throws HibernateException;

Source Link

Document

Force this session to flush.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
 *//*  ww  w .j  ava2  s . c  om*/
@Test
public void testAddRigToSchedServerActiveRig() {
    Session ses = DataAccessActivator.getNewSession();

    String name = "register1";
    String type = "registertest";
    String caps = "a,b,c,d,e,f";
    String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService";

    RigType existType = new RigType(type, 180, false);
    RigCapabilities existCaps = new RigCapabilities(caps);
    ses.beginTransaction();
    ses.save(existType);
    ses.save(existCaps);
    ses.getTransaction().commit();
    ses.flush();
    ses.evict(existType);
    ses.evict(existCaps);

    Rig existRig = new Rig(existType, existCaps, name, contactUrl, new Date(), false, "Broken.", false, true,
            true);
    ses.beginTransaction();
    ses.save(existRig);
    ses.getTransaction().commit();
    ses.flush();
    ses.evict(existRig);

    assertFalse(this.register.registerRig(name, type, caps, contactUrl));

    RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps);
    RigType typeRec = new RigTypeDao(ses).findByName(type);
    Rig rigRec = new RigDao(ses).findByName(name);

    /* Cleanup. */
    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rigRec.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rigRec);
    ses.delete(capsRec);
    ses.delete(typeRec);
    ses.getTransaction().commit();

    assertEquals("Exists", this.register.getFailedReason());
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.requests.RigMaintenance.java

License:Open Source License

/**
 * Actually makes the maintenance request.
 * //from w  ww .  j  a  v a 2 s .  co m
 * @param rig rig to request
 * @param offline whether the rig s being put offline
 * @param tests whether exerciser tests should be run
 * @param db database session
 */
private void makeMaintenaceRequest(Rig rig, boolean offline, boolean tests, Session db) {
    try {
        RigClientAsyncService service = new RigClientAsyncService(rig.getName(), db);
        service.setMaintenance(offline, tests, this);
    } catch (Exception e) {
        this.logger.error("Failed calling rig client set maintenance to " + rig.getName() + " at "
                + rig.getContactUrl() + " because of error " + e.getMessage() + ".");

        /* Set rig inactive. */
        rig.setInSession(false);
        rig.setOnline(false);
        rig.setOfflineReason("Set maintenance operation failed.");
        rig.setSession(null);
        db.beginTransaction();
        db.flush();
        db.getTransaction().commit();

        /* Log when the rig is offline. */
        RigLogDao rigLogDao = new RigLogDao(db);
        rigLogDao.addOfflineLog(rig,
                "Set maintenance with failed. Supplied params: offline=" + offline + ", tests=" + tests + ".");

        /* Fire event the rig is offline. */
        RigProviderActivator.notifyRigEvent(RigStateChangeEvent.OFFLINE, rig, db);
    }
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.requests.RigMaintenance.java

License:Open Source License

@Override
public void setMaintenanceResponseCallback(SetMaintenanceResponse response) {
    OperationResponseType op = response.getSetMaintenanceResponse();

    if (!op.getSuccess()) {
        ErrorType err = op.getError();
        this.logger.error("Set maintenance for rig " + this.rig.getName() + " failed. Error reason is '"
                + err.getReason() + "'.");

        Session db = DataAccessActivator.getNewSession();
        this.rig.setInSession(false);
        this.rig.setOnline(false);
        this.rig.setOfflineReason("Set maintenance failed with reason: '" + err.getReason() + "'.");
        this.rig.setSession(null);
        db.beginTransaction();//from  ww w  . j  a va 2s  .co  m
        db.flush();
        db.getTransaction().commit();

        /* Log when the rig is offline. */
        RigLogDao rigLogDao = new RigLogDao(db);
        rigLogDao.addOfflineLog(this.rig, "Set maintenance failed with reason: " + err.getReason());

        /* Fire event the rig is offline. */
        RigProviderActivator.notifyRigEvent(RigStateChangeEvent.OFFLINE, this.rig, db);
    }
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.requests.RigMaintenance.java

License:Open Source License

@Override
public void setMaintenanceErrorCallback(final Exception e) {
    this.logger.error("Set maintenance for rig " + this.rig.getName() + " failed with exception: '"
            + e.getClass().getSimpleName() + ", message: " + e.getMessage() + "'.");

    Session db = DataAccessActivator.getNewSession();
    this.rig.setInSession(false);
    this.rig.setOnline(false);
    this.rig.setOfflineReason("Set maintenance failed with exception: '" + e.getClass().getSimpleName()
            + ", message: " + e.getMessage() + "'.");
    this.rig.setSession(null);

    db.beginTransaction();/*from w  ww.jav a  2s .c om*/
    db.flush();
    db.getTransaction().commit();

    /* Log when the rig is offline. */
    RigLogDao rigLogDao = new RigLogDao(db);
    rigLogDao.addOfflineLog(this.rig, "Set maintenance failed with exception: '" + e.getClass().getSimpleName()
            + ", message: " + e.getMessage() + "'.");

    /* Fire event the rig is offline. */
    RigProviderActivator.notifyRigEvent(RigStateChangeEvent.OFFLINE, this.rig, db);
}

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public ItemRecord getItemRecord(String id) {
    Session session = HibernateUtil.getSession();
    Criteria crit = session.createCriteria(ItemRecord.class);
    crit.add(Restrictions.eq("id", id));
    List results = crit.list();/*from ww w .j ava 2  s . co m*/
    if ((results == null) || results.size() == 0) {
        return null;
    }
    ItemRecord item = (ItemRecord) results.get(0);
    session.flush();
    session.clear();

    return item;
}

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public List<ItemRecord> getAllItemRecords() {
    Session session = HibernateUtil.getSession();
    Criteria crit = session.createCriteria(ItemRecord.class);
    List<ItemRecord> itemRecords = crit.list();
    session.flush();
    session.clear();/*w  ww  .jav a  2 s . c  o m*/

    return itemRecords;
}

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public List<ItemRecord> getItemRecordsBySubDir(String subdir) {
    Session session = HibernateUtil.getSession();
    Criteria crit = session.createCriteria(ItemRecord.class);

    //TODO add a restriction to the criteria so it actually gets filtered. 
    List<ItemRecord> itemRecords = crit.list();
    session.flush();
    session.clear();/*from   w w w.jav a 2 s  .  co m*/

    return itemRecords;
}

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public void saveItemRecord(ItemRecord itemRecord) {
    logger.fine("Persisting Item Record");
    Session session = HibernateUtil.getSession();
    session.saveOrUpdate(itemRecord);//from w  w w.  ja  va  2s . c o  m
    session.flush();
    session.clear();
    logger.fine("Item Record Persisted.");
}

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public void removeItemRecord(ItemRecord itemRecord) {
    logger.fine("Removing Item Record");
    Session session = HibernateUtil.getSession();
    session.delete(itemRecord);/*w  ww.j  av a  2s.  c om*/
    session.flush();
    session.clear();
    logger.fine("Item Record Removed.");
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public void createOrUpdateArkModuleFunction(ArkModule arkModule, Collection<ArkFunction> selectedArkFunctions) {
    Session session = getSession();

    // Remove previous list of ArkFunctions
    Collection<ArkModuleFunction> arkModuleFunctions = getArkModuleFunctionByArkModule(arkModule);
    for (ArkModuleFunction arkModuleFunctionToRemove : arkModuleFunctions) {
        session.delete(arkModuleFunctionToRemove);
    }/*from  w w w.  ja v  a  2  s.co  m*/

    // Insert the ArkFunctions for the ArkModule
    Long functionSequence = new Long(1);
    for (Iterator<ArkFunction> iterator = selectedArkFunctions.iterator(); iterator.hasNext();) {
        ArkModuleFunction arkModuleFunction = new ArkModuleFunction();
        ArkFunction arkFunction = iterator.next();
        arkModuleFunction.setArkModule(arkModule);
        arkModuleFunction.setArkFunction(arkFunction);
        arkModuleFunction.setFunctionSequence(functionSequence++);
        session.save(arkModuleFunction);
    }

    // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that.
    session.flush();
}