Example usage for org.springframework.transaction.annotation Isolation REPEATABLE_READ

List of usage examples for org.springframework.transaction.annotation Isolation REPEATABLE_READ

Introduction

In this page you can find the example usage for org.springframework.transaction.annotation Isolation REPEATABLE_READ.

Prototype

Isolation REPEATABLE_READ

To view the source code for org.springframework.transaction.annotation Isolation REPEATABLE_READ.

Click Source Link

Document

A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.

Usage

From source file:org.projectforge.database.DatabaseDao.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public String rebuildDatabaseSearchIndices(final Class<?> clazz, final ReindexSettings settings) {
    if (currentReindexRun != null) {
        return "Another re-index job is already running. The job was started at: " + DateTimeFormatter
                .instance().getFormattedDateTime(currentReindexRun, Locale.ENGLISH, DateHelper.UTC) + " (UTC)";
    }/* w  w w .j av a  2s  .  c om*/
    final StringBuffer buf = new StringBuffer();
    reindex(clazz, settings, buf);
    return buf.toString();
}

From source file:org.projectforge.database.DatabaseDao.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void reindex(final Class<?> clazz, final ReindexSettings settings, final StringBuffer buf) {
    if (currentReindexRun != null) {
        buf.append(" (cancelled due to another running index-job)");
        return;//from  w  w  w.  ja v a  2  s  .  c om
    }
    synchronized (this) {
        try {
            currentReindexRun = new Date();
            buf.append(ClassUtils.getShortClassName(clazz));
            final File file = new File(ConfigXml.getInstance().getApplicationHomeDir() + "/hibernate-search/"
                    + clazz.getName() + "/write.lock");
            if (file.exists() == true) {
                final Date lastModified = new Date(file.lastModified());
                final String message;
                if (System.currentTimeMillis() - file.lastModified() > 60000) { // Last modified date is older than 60 seconds.
                    message = "(*** write.lock with last modification '"
                            + DateTimeFormatter.instance().getFormattedDateTime(lastModified)
                            + "' exists (skip re-index). May-be your admin should delete this file (see log). ***)";
                    log.error(file.getAbsoluteFile() + " " + message);
                } else {
                    message = "(*** write.lock temporarily exists (skip re-index). ***)";
                    log.info(file.getAbsolutePath() + " " + message);
                }
                buf.append(" ").append(message);
            } else {
                reindex(clazz, settings);
            }
            buf.append(", ");
        } finally {
            currentReindexRun = null;
        }
    }
}

From source file:org.projectforge.fibu.datev.DatevImportDao.java

@SuppressWarnings("unchecked")
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void commit(final ImportStorage<?> storage, final String sheetName) {
    checkLoggeinUserRight(accessChecker);
    Validate.notNull(storage.getSheets());
    final ImportedSheet<?> sheet = storage.getNamedSheet(sheetName);
    Validate.notNull(sheet);// w w w.  j  av a 2 s.c  om
    Validate.isTrue(sheet.getStatus() == ImportStatus.RECONCILED);
    int no = -1;
    if (storage.getId() == Type.KONTENPLAN) {
        no = commitKontenplan((ImportedSheet<KontoDO>) sheet);
    } else {
        no = commitBuchungsdaten((ImportedSheet<BuchungssatzDO>) sheet);
    }
    sheet.setNumberOfCommittedElements(no);
    sheet.setStatus(ImportStatus.IMPORTED);
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * @param obj/*from  ww w .  j  a  va  2  s .c  o m*/
 * @return the generated identifier.
 * @throws AccessException
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public Integer save(final O obj) throws AccessException {
    long begin = System.currentTimeMillis();
    Validate.notNull(obj);
    if (avoidNullIdCheckBeforeSave == false) {
        Validate.isTrue(obj.getId() == null);
    }
    checkPartOfCurrentTenant(obj, OperationType.INSERT);
    checkLoggedInUserInsertAccess(obj);
    accessChecker.checkRestrictedOrDemoUser();
    Integer result = internalSave(obj);
    long end = System.currentTimeMillis();
    log.info("BaseDao.save took: " + (end - begin) + " ms.");
    return result;
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * This method is for internal use e. g. for updating objects without check access.
 *
 * @param obj//w  w  w  .j a  v  a  2  s  .c o  m
 * @return the generated identifier.
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public Integer internalSave(final O obj) {
    Validate.notNull(obj);
    //TODO: Muss der richtige Tenant gesetzt werden. Ist nur Workaround.
    if (obj.getTenant() == null) {
        obj.setTenant(getDefaultTenant());
    }
    obj.setCreated();
    obj.setLastUpdate();
    onSave(obj);
    onSaveOrModify(obj);
    BaseDaoJpaAdapter.prepareInsert(obj);
    Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
    Integer id = (Integer) session.save(obj);
    log.info("New object added (" + id + "): " + obj.toString());
    prepareHibernateSearch(obj, OperationType.INSERT);
    if (NO_UPDATE_MAGIC == true) {
        // safe will assocated not working
        hibernateTemplate.merge(obj);
    }
    flushSession();
    flushSearchSession();
    HistoryBaseDaoAdapter.inserted(obj);
    afterSaveOrModify(obj);
    afterSave(obj);

    return id;
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * @param obj/* w  w w .  ja  v  a 2s  .  c  o  m*/
 * @return true, if modifications were done, false if no modification detected.
 * @throws AccessException
 * @see #internalUpdate(ExtendedBaseDO, boolean)
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public ModificationStatus update(final O obj) throws AccessException {
    Validate.notNull(obj);
    if (obj.getId() == null) {
        final String msg = "Could not update object unless id is not given:" + obj.toString();
        log.error(msg);
        throw new RuntimeException(msg);
    }
    return internalUpdate(obj, true);
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * This method is for internal use e. g. for updating objects without check access.<br/>
 * Please note: update ignores the field deleted. Use markAsDeleted, delete and undelete methods instead.
 *
 * @param obj//from w  w w.  j a v a 2s . c o  m
 * @param checkAccess If false, any access check will be ignored.
 * @return true, if modifications were done, false if no modification detected.
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ)
public ModificationStatus internalUpdate(final O obj, final boolean checkAccess) {
    onSaveOrModify(obj);
    if (checkAccess == true) {
        accessChecker.checkRestrictedOrDemoUser();
    }
    final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
    if (checkAccess == true) {
        checkPartOfCurrentTenant(obj, OperationType.UPDATE);
        checkLoggedInUserUpdateAccess(obj, dbObj);
    }
    onChange(obj, dbObj);
    final O dbObjBackup;
    if (supportAfterUpdate == true) {
        dbObjBackup = getBackupObject(dbObj);
    } else {
        dbObjBackup = null;
    }
    final boolean wantsReindexAllDependentObjects = wantsReindexAllDependentObjects(obj, dbObj);
    ModificationStatus result = HistoryBaseDaoAdapter.wrappHistoryUpdate(dbObj, () -> {
        // Copy all values of modified user to database object, ignore field 'deleted'.
        final ModificationStatus tresult = copyValues(obj, dbObj, "deleted");

        if (tresult != ModificationStatus.NONE) {
            BaseDaoJpaAdapter.prepareUpdate(dbObj);
            dbObj.setLastUpdate();
            log.info("Object updated: " + dbObj.toString());
        } else {
            log.info("No modifications detected (no update needed): " + dbObj.toString());
        }
        prepareHibernateSearch(obj, OperationType.UPDATE);
        // TODO HIBERNATE5 Magie nicht notwendig?!?!?!
        if (NO_UPDATE_MAGIC == true) {
            // update doesn't work, because of referenced objects
            hibernateTemplate.merge(dbObj);
        }
        flushSession();
        flushSearchSession();
        return tresult;
    });

    afterSaveOrModify(obj);
    if (supportAfterUpdate == true) {
        afterUpdate(obj, dbObjBackup, result != ModificationStatus.NONE);
        afterUpdate(obj, dbObjBackup);
    } else {
        afterUpdate(obj, null, result != ModificationStatus.NONE);
        afterUpdate(obj, null);
    }
    if (wantsReindexAllDependentObjects == true) {
        reindexDependentObjects(obj);
    }
    return result;
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * Object will be marked as deleted (boolean flag), therefore undelete is always possible without any loss of data.
 *
 * @param obj//from w  w w .  jav  a2  s  .  c o m
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void markAsDeleted(final O obj) throws AccessException {
    Validate.notNull(obj);
    if (obj.getId() == null) {
        final String msg = "Could not delete object unless id is not given:" + obj.toString();
        log.error(msg);
        throw new RuntimeException(msg);
    }
    final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
    checkPartOfCurrentTenant(obj, OperationType.DELETE);
    checkLoggedInUserDeleteAccess(obj, dbObj);
    accessChecker.checkRestrictedOrDemoUser();
    internalMarkAsDeleted(obj);
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void internalMarkAsDeleted(final O obj) {
    if (HistoryBaseDaoAdapter.isHistorizable(obj) == false) {
        log.error(//from ww  w.j  a v  a2 s. c  om
                "Object is not historizable. Therefore marking as deleted is not supported. Please use delete instead.");
        throw new InternalErrorException();
    }
    onDelete(obj);
    final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
    onSaveOrModify(obj);
    BaseDaoJpaAdapter.beforeUpdateCopyMarkDelete(dbObj, obj);
    copyValues(obj, dbObj, "deleted"); // If user has made additional changes.
    dbObj.setDeleted(true);
    dbObj.setLastUpdate();
    flushSession();
    flushSearchSession();
    afterSaveOrModify(obj);
    afterDelete(obj);
    flushSession();
    log.info("Object marked as deleted: " + dbObj.toString());
}

From source file:org.projectforge.framework.persistence.api.BaseDao.java

/**
 * Object will be deleted finally out of the data base.
 *
 * @param obj//from  ww  w  . j  a  va2  s. c om
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void delete(final O obj) throws AccessException {
    Validate.notNull(obj);
    if (HistoryBaseDaoAdapter.isHistorizable(obj) == true) {
        final String msg = EXCEPTION_HISTORIZABLE_NOTDELETABLE + obj.toString();
        log.error(msg);
        throw new RuntimeException(msg);
    }
    if (obj.getId() == null) {
        final String msg = "Could not destroy object unless id is not given: " + obj.toString();
        log.error(msg);
        throw new RuntimeException(msg);
    }
    accessChecker.checkRestrictedOrDemoUser();
    onDelete(obj);
    final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
    checkPartOfCurrentTenant(obj, OperationType.DELETE);
    checkLoggedInUserDeleteAccess(obj, dbObj);
    hibernateTemplate.delete(dbObj);
    log.info("Object deleted: " + obj.toString());
    afterSaveOrModify(obj);
    afterDelete(obj);
}