Example usage for org.hibernate StatelessSession update

List of usage examples for org.hibernate StatelessSession update

Introduction

In this page you can find the example usage for org.hibernate StatelessSession update.

Prototype

void update(Object entity);

Source Link

Document

Update a row.

Usage

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

protected void setSubjectUidSequenceLock(Study study, boolean lock) {
    // Stateless sessions should be used to avoid locking the record for future update
    // by getSession(), which relies on the "open session filter" mechanism
    StatelessSession session = getStatelessSession();
    Transaction tx = session.getTransaction();
    tx.begin();//ww w.j  a v  a2s  .c om
    BiospecimenUidSequence biospecimenUidSeq = getBiospecimenUidSequence(study);
    if (biospecimenUidSeq == null) {
        // create a new record if it doens't exist
        biospecimenUidSeq = new BiospecimenUidSequence();
        biospecimenUidSeq.setStudyNameId(study.getName());
        biospecimenUidSeq.setUidSequence(new Integer(0));
        biospecimenUidSeq.setInsertLock(lock);
        session.insert(biospecimenUidSeq);
    } else {
        biospecimenUidSeq.setInsertLock(lock);
        session.update(biospecimenUidSeq);
    }
    tx.commit();
    session.close();
}

From source file:com.jredrain.dao.HibernateDao.java

License:Apache License

@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
protected <T> void save(List<T> entities) {
    StatelessSession session = sessionFactory.openStatelessSession();
    for (T entity : entities) {
        session.update(entity);
    }/*from   w w w  .  ja  v a  2s. c  om*/
    session.close();
}

From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityDao.java

License:Open Source License

/**
 * Updates an existing entity. If the entity does not exist in the database, an exception is
 * thrown./*from   w ww  . jav  a 2  s.co  m*/
 *
 * @param statelessSession
 * @param entity
 */
@Override
public void update(final StatelessSession statelessSession, final E entity) {
    statelessSession.update(entity);
}

From source file:edu.psu.iam.cpr.core.database.batch.AccessAccountStatus.java

License:Creative Commons License

/**
 * This method is used to remove a service from a user, if they have it assigned to them.
 * @param personId contains the person identifier associated with the user.
 * @param userid contains the userid./*ww w  .  ja va 2 s.  c  o  m*/
 * @param accessAccountServiceType contains the access account service type to be expired.
 */
public void removeService(final long personId, final String userid,
        final AccessAccountServiceType accessAccountServiceType) {

    final StatelessSession session = getDatabaseSession();
    final Date d = getServiceDate();
    final String updatedBy = getBatchDataSource().toString();

    final Query query = session.createQuery(
            "from UserServiceStatus where personId = :person_id AND userid = :userid AND serviceKey = :service_key AND deprovisionDate is NULL");
    query.setParameter("person_id", personId);
    query.setParameter("userid", userid);
    query.setParameter("service_key", accessAccountServiceType.index());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final UserServiceStatus userServiceStatus = (UserServiceStatus) it.next();
        userServiceStatus.setDeprovisionDate(d);
        userServiceStatus.setLastUpdateBy(updatedBy);
        userServiceStatus.setLastUpdateOn(d);
        session.update(userServiceStatus);
    }

}

From source file:edu.psu.iam.cpr.core.database.batch.PersonBio.java

License:Creative Commons License

/**
 * This method is used to update a PSU ID record or add a new one.
 * @param psuId contains the PSU ID to be updated.
 *//*  w w  w. j av  a  2  s .  c o  m*/
public void updatePsuId(final String psuId) {

    // Do not attempt to update null PSU IDs.
    if (ValidateHelper.isFieldEmpty(psuId)) {
        return;
    }

    boolean matchFound = false;

    // Perform a query to find the active PSU IDs for the user, there should only ever be one.
    final StatelessSession session = getDatabaseSession();
    final Date d = getUpdateDate();
    final String updatedBy = getBatchDataSource().toString();

    final Query query = session.createQuery("from PsuId where personId = :person_id and endDate is null");
    query.setParameter(PERSON_ID, getPersonId());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final PsuId bean = (PsuId) it.next();

        // Does the bean's PSU ID, equal the incoming psu id, if so we can ignore the update.
        if (bean.getPsuId().equals(psuId)) {
            matchFound = true;
        }

        // PSU ID change, so expire the existing one.
        else {
            bean.setEndDate(d);
            bean.setLastUpdateBy(updatedBy);
            bean.setLastUpdateOn(d);
            session.update(bean);
            setOldPsuId(bean);
        }
    }

    // If we did not find a match, we need to add the new PSU ID.
    if (!matchFound) {
        addPsuId(psuId);
    }
}

From source file:edu.psu.iam.cpr.core.database.batch.PersonBio.java

License:Creative Commons License

/**
 * This method is used to update gender record with a new gender if one differs from what's stored in the database.
 * @param genderType contains the incoming gender type.
 *//*from  ww w .  j a v a  2s  . c om*/
public void updateGender(final GenderType genderType) {

    // do not attempt to store a null gender type.
    if (genderType == null) {
        return;
    }

    boolean matchFound = false;

    // Perform a query to find the active genders for the user, there should only ever be one.
    final StatelessSession session = getDatabaseSession();
    final Date d = getUpdateDate();
    final String updatedBy = getBatchDataSource().toString();

    final Query query = session
            .createQuery("from PersonGender where personId = :person_id and endDate is null");
    query.setParameter(PERSON_ID, getPersonId());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final PersonGender bean = (PersonGender) it.next();

        // Does the bean's Gender, equal the incoming gender, if so we can ignore the update.
        if (bean.getDataTypeKey().equals(genderType.index())) {
            matchFound = true;
        }

        // Gender change, so expire the existing one.
        else {
            bean.setEndDate(d);
            bean.setLastUpdateBy(updatedBy);
            bean.setLastUpdateOn(d);
            session.update(bean);
            setOldPersonGender(bean);
        }
    }

    // If we did not find a match, we need to add the new gender.
    if (!matchFound) {
        addGender(genderType);
    }

}

From source file:edu.psu.iam.cpr.core.database.batch.PersonBio.java

License:Creative Commons License

/**
 * This method is used to update/add a date of birth record.  The input is a dob string formatted as MMDDYYYY string.
 * A check will be made to ensure the DOB does not already exist.  Otherwise, it will expire the existing on and add
 * a new one./*  w w  w .  ja  v a 2 s.c o  m*/
 * @param dobString contains the date of birth string formatted as MMDDYYYY.
 * @throws ParseException will be thrown if the Date of Birth cannot be parsed.
 */
public void updateDateOfBirth(final String dobString) throws ParseException {

    // do not attempt to store a null date of birth.
    if (ValidateHelper.isFieldEmpty(dobString)) {
        return;
    }

    boolean matchFound = false;

    // Perform a query to find the active date of births for the user, there should only ever be one.
    final StatelessSession session = getDatabaseSession();
    final Date d = getUpdateDate();
    final String updatedBy = getBatchDataSource().toString();

    final Query query = session.createQuery("from DateOfBirth where personId = :person_id and endDate is null");
    query.setParameter(PERSON_ID, getPersonId());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final DateOfBirth bean = (DateOfBirth) it.next();

        // Does the bean's dobString, equal the incoming dobString, if so we can ignore the update.
        if (bean.getDobChar().equals(dobString)) {
            matchFound = true;
        }

        // Date of birth change, so expire the existing one.
        else {
            bean.setEndDate(d);
            bean.setLastUpdateBy(updatedBy);
            bean.setLastUpdateOn(d);
            session.update(bean);
            setOldDateOfBirth(bean);
        }
    }

    // If we did not find a match, we need to add the new date of birth.
    if (!matchFound) {
        addDateOfBirth(dobString);
    }
}

From source file:edu.psu.iam.cpr.core.database.batch.PersonBio.java

License:Creative Commons License

/**
 * This method is used to determine how to process an email address update.  It will search to see if there is an email address
 * that matches the incoming email address.  If so the update is ignored.  Otherwise, the existing one is expired and the new one
 * is added.// w w  w  .  j  a va2  s.c o  m
 * @param emailAddress contains the email address to be added.
 */
public void updateEmailAddress(final String emailAddress) {

    // If the email address is null, ignore the update.
    if (ValidateHelper.isFieldEmpty(emailAddress)) {
        return;
    }

    final Date d = getUpdateDate();
    final String updatedBy = getBatchDataSource().toString();
    final StatelessSession session = getDatabaseSession();
    final EmailAddressType emailAddressType = getEmailAddressType(emailAddress);
    boolean matchFound = false;

    // Perform a query to find the active email addresses for the user, there should only ever be one.
    final Query query = session.createQuery(
            "from EmailAddress where personId = :person_id and endDate is null and dataTypeKey = :data_type_key");
    query.setParameter(PERSON_ID, getPersonId());
    query.setParameter(DATA_TYPE_KEY, emailAddressType.index());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final EmailAddress bean = (EmailAddress) it.next();

        // Does the bean's email address equal the incoming email address, if so we can ignore the update.
        if (bean.getEmailAddress().equalsIgnoreCase(emailAddress)) {
            matchFound = true;
        }

        // Date of birth change, so expire the existing one.
        else {
            bean.setEndDate(d);
            bean.setLastUpdateBy(updatedBy);
            bean.setLastUpdateOn(d);
            session.update(bean);
            setOldEmailAddress(bean);
        }
    }

    // If we did not find a match, we need to add the new email address.
    if (!matchFound) {
        addEmailAddress(emailAddress);
    }
}

From source file:edu.psu.iam.cpr.core.database.batch.PersonBio.java

License:Creative Commons License

/**
 * This method is used to update a telephone number.
 * @param phoneType contains the type of telephone number to be updated.
 * @param phoneNumber contains the actual telephone number.
 * @param extension contains the extension.
 *///  www  .j  a  v  a  2  s  . c o  m
public void updatePhone(final PhoneType phoneType, final String phoneNumber, final String extension) {

    // Only do an update if we have a phone #.
    if (ValidateHelper.isFieldEmpty(phoneNumber)) {
        return;
    }

    final String localPhoneNumber = phoneNumber.replaceAll("\\s", "");
    final StatelessSession session = getDatabaseSession();
    final Date d = getUpdateDate();
    final String updatedBy = getBatchDataSource().toString();
    boolean matchFound = false;

    final Query query = session.createQuery(
            "from Phones where personId = :person_id AND dataTypeKey = :data_type_key AND endDate IS NULL");
    query.setParameter(PERSON_ID, getPersonId());
    query.setParameter(DATA_TYPE_KEY, phoneType.index());
    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        final Phones bean = (Phones) it.next();
        if (Utility.areStringFieldsEqual(localPhoneNumber, bean.getPhoneNumber())) {
            matchFound = true;
        }

        // Based on the data we are receiving from the feeds this is the best we can do at this time.  Not sure what to do about
        // the home phone.
        else if (phoneType == PhoneType.LOCAL_PHONE || phoneType == PhoneType.WORK_PHONE) {
            bean.setEndDate(d);
            bean.setLastUpdateBy(updatedBy);
            bean.setLastUpdateOn(d);
            session.update(bean);
            setOldPhone(bean);
        }
    }

    // If we did not find a match, we need to determine what the new group id will be.
    if (!matchFound) {

        Long groupId = null;
        final Query maxQuery = session.createQuery(
                "select max(groupId) from Phones where personId = :person_id and dataTypeKey = :data_type_key");
        maxQuery.setParameter(PERSON_ID, getPersonId());
        maxQuery.setParameter(DATA_TYPE_KEY, phoneType.index());
        groupId = (Long) maxQuery.list().get(0);
        if (groupId == null) {
            groupId = 1L;
        } else {
            groupId++;
        }

        addPhone(phoneType, localPhoneNumber, extension, groupId);
    }
}

From source file:edu.psu.iam.cpr.core.database.postprocess.AddressPostProcessor.java

License:Creative Commons License

/**
 * This method is used to expire an old names bean, because a new one will be created.
 * @param db contains the database session.
 * @param bean contains the bean that will be expired.
 * @param updatedBy contains the updated by user.
 *//* ww w . j a v  a2 s  . c om*/
public void expireAddress(final StatelessSession db, final Addresses bean, final String updatedBy) {
    final Date d = new Date();

    bean.setEndDate(d);
    bean.setLastUpdateBy(updatedBy);
    bean.setLastUpdateOn(d);
    db.update(bean);

    setOldAddressBean(bean);

}