Example usage for org.springframework.transaction.annotation Propagation MANDATORY

List of usage examples for org.springframework.transaction.annotation Propagation MANDATORY

Introduction

In this page you can find the example usage for org.springframework.transaction.annotation Propagation MANDATORY.

Prototype

Propagation MANDATORY

To view the source code for org.springframework.transaction.annotation Propagation MANDATORY.

Click Source Link

Document

Support a current transaction, throw an exception if none exists.

Usage

From source file:com.epam.catgenome.dao.BiologicalDataItemDao.java

/**
 * Finds files with names matching a specified file name, performs substring, case insensitive search
 * @param name search query//  w w w  . j a v  a 2 s  .co m
 * @return {@code List} of files with a matching name
 */
@Transactional(propagation = Propagation.MANDATORY)
public List<BiologicalDataItem> loadFilesByName(final String name) {
    final MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(BiologicalDataItemParameters.NAME.name(), "%" + name.toLowerCase() + "%");
    return getNamedParameterJdbcTemplate().query(loadBiologicalDataItemsByNameQuery, params, getRowMapper());
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

/**
 * Loads a persisted {@code Reference} entity from the database by a specified ID
 * @param referenceId {@code Reference} ID to load
 * @return loaded {@code Reference} instance
 *///from  w  w  w  .j av a 2 s.co  m
@Transactional(propagation = Propagation.MANDATORY)
public Reference loadReferenceGenome(final Long referenceId) {
    final List<Reference> list = getNamedParameterJdbcTemplate().query(loadReferenceGenomeByIdQuery,
            new MapSqlParameterSource(GenomeParameters.REFERENCE_GENOME_ID.name(), referenceId),
            GenomeParameters.getReferenceGenomeMapper());
    return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
}

From source file:org.bytesoft.bytetcc.supports.spring.CompensableAnnotationValidator.java

private void validateTransactionalPropagation(Method method, Class<?> clazz) throws IllegalStateException {
    Transactional transactional = method.getAnnotation(Transactional.class);
    if (transactional == null) {
        Class<?> declaringClass = method.getDeclaringClass();
        transactional = declaringClass.getAnnotation(Transactional.class);
    }//ww w.j av a 2s .  c  o  m

    if (transactional == null) {
        throw new IllegalStateException(
                String.format("Method(%s) must be specificed a Transactional annotation!", method));
    }
    Propagation propagation = transactional.propagation();
    if (Propagation.REQUIRED.equals(propagation) == false //
            && Propagation.MANDATORY.equals(propagation) == false //
            && Propagation.REQUIRES_NEW.equals(propagation) == false) {
        throw new IllegalStateException(
                String.format("Method(%s) not support propagation level: %s!", method, propagation.name()));
    }
}

From source file:com.epam.catgenome.dao.DaoHelper.java

@Transactional(propagation = Propagation.MANDATORY)
public Long createTempStringList(final Long listId, final Collection<String> list) {
    Assert.notNull(listId);/*  www.  j ava2  s  .c o m*/
    Assert.isTrue(CollectionUtils.isNotEmpty(list));
    // creates a new local temporary table if it doesn't exists to handle temporary lists
    getJdbcTemplate().update(createTemporaryStringListQuery);
    // fills in a temporary list by given values
    int i = 0;
    final Iterator<String> iterator = list.iterator();
    final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()];
    while (iterator.hasNext()) {
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(HelperParameters.LIST_ID.name(), listId);
        params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next());
        batchArgs[i] = params;
        i++;
    }
    getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryStringListItemQuery, batchArgs);
    return listId;
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

/**
 * Loads a persisted {@code Reference} entity from the database by a specified Biological dataItemID
 * @param itemID {@code Reference} Biological DataItemID to load
 * @return loaded {@code Reference} instance
 *///from  ww  w.j a v  a  2s  . c  o m
@Transactional(propagation = Propagation.MANDATORY)
public Reference loadReferenceGenomeByBioItemId(final Long itemID) {
    final List<Reference> list = getNamedParameterJdbcTemplate().query(loadReferenceGenomeByBioIdQuery,
            new MapSqlParameterSource(GenomeParameters.BIO_DATA_ITEM_ID.name(), itemID),
            GenomeParameters.getReferenceGenomeMapper());
    return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
}

From source file:com.epam.catgenome.dao.vcf.VcfFileDao.java

/**
 * Load sample metadata from the database for all files, corresponding the given reference ID.
 *
 * @param vcfFileId {@code long} reference ID for which files samples were saved.
 * @return {@code Map&lt;Long, List&lt;Sample&gt;&gt;} with file IDs for giver reference ID as keys, and with
 * lists of samples, corresponding this file IDs as values.
 */// w w  w  . jav  a2s .c  om
@Transactional(propagation = Propagation.MANDATORY)
public Map<Long, List<VcfSample>> loadSamplesForFilesByReference(long vcfFileId) {
    Map<Long, List<VcfSample>> sampleFileMap = new HashMap<>();

    getJdbcTemplate().query(loadSamplesForFilesByReferenceIdQuery, rs -> {
        Long fileId = rs.getLong(SampleParameters.VCF_ID.name());
        if (!sampleFileMap.containsKey(fileId)) {
            sampleFileMap.put(fileId, new ArrayList<>());
        }

        VcfSample sample = new VcfSample();

        sample.setId(rs.getLong(SampleParameters.VCF_SAMPLE_ID.name()));
        sample.setName(rs.getString(SampleParameters.SAMPLE_NAME.name()));
        sample.setIndex(rs.getInt(SampleParameters.ORDER_INDEX.name()));

        sampleFileMap.get(fileId).add(sample);
    }, vcfFileId);

    return sampleFileMap;
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

/**
 * Loads all persisted {@code Reference} entities from the database
 * @return all {@code Reference} instances, saved in the database
 *///  ww w  .  j a  v  a2  s  .  c o m
@Transactional(propagation = Propagation.MANDATORY)
public List<Reference> loadAllReferenceGenomes() {
    return getNamedParameterJdbcTemplate().query(loadAllReferenceGenomesQuery,
            GenomeParameters.getReferenceGenomeMetaDataMapper());
}

From source file:com.epam.catgenome.dao.DaoHelper.java

@Transactional(propagation = Propagation.MANDATORY)
public Long createTempList(final Long listId, final Collection<? extends BaseEntity> list) {
    Assert.notNull(listId);/*from   w w w .j a va 2  s. c om*/
    Assert.isTrue(CollectionUtils.isNotEmpty(list));
    // creates a new local temporary table if it doesn't exists to handle temporary lists
    getJdbcTemplate().update(createTemporaryListQuery);
    // fills in a temporary list by given values
    int i = 0;
    final Iterator<? extends BaseEntity> iterator = list.iterator();
    final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()];
    while (iterator.hasNext()) {
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(HelperParameters.LIST_ID.name(), listId);
        params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next().getId());
        batchArgs[i] = params;
        i++;
    }
    getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryListItemQuery, batchArgs);
    return listId;
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

/**
 * Saves {@code List} of {@code Chromosome} entities with a specified ID in the database
 * as one reference//ww w.j a v a2s .c  o m
 * @param referenceId for the chromosomes
 * @param chromosomes {@code List} of {@code Chromosome} entities to store int the database
 * @return an array containing the numbers of rows affected by each update in the batch
 */
@Transactional(propagation = Propagation.MANDATORY)
public int[] saveChromosomes(final Long referenceId, final List<Chromosome> chromosomes) {
    final int count = chromosomes.size();
    final List<Long> chromosomeIds = daoHelper.createIds(chromosomeSequenceName, count);
    final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[count];
    for (int i = 0; i < count; i++) {
        final Chromosome chromosome = chromosomes.get(i);
        chromosome.setId(chromosomeIds.get(i));
        chromosome.setReferenceId(referenceId);
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(GenomeParameters.NAME.name(), chromosome.getName());
        params.addValue(GenomeParameters.SIZE.name(), chromosome.getSize());
        params.addValue(GenomeParameters.PATH.name(), chromosome.getPath());
        params.addValue(GenomeParameters.HEADER.name(), chromosome.getHeader());
        params.addValue(GenomeParameters.CHROMOSOME_ID.name(), chromosome.getId());
        params.addValue(GenomeParameters.REFERENCE_GENOME_ID.name(), chromosome.getReferenceId());
        batchArgs[i] = params;
    }
    return getNamedParameterJdbcTemplate().batchUpdate(createChromosomeQuery, batchArgs);
}

From source file:com.bitsofproof.supernode.model.JpaStore.java

@Override
@Transactional(propagation = Propagation.MANDATORY)
public void storeColor(StoredColor color) {
    entityManager.persist(color);
}