Example usage for org.springframework.transaction.support TransactionCallback TransactionCallback

List of usage examples for org.springframework.transaction.support TransactionCallback TransactionCallback

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionCallback TransactionCallback.

Prototype

TransactionCallback

Source Link

Usage

From source file:ch.tatool.app.service.impl.DataServiceImpl.java

/**
 * Get all distinct session property names contained in a module
 * /*from w w  w  . j ava  2 s .  c o m*/
 * @return a List of object arrays containing [0] the item name and [1] the property name
 */
@SuppressWarnings("unchecked")
public List<Object[]> findDistinctSessionPropertyNames(final Module module) {
    final ModuleImpl moduleImpl = (ModuleImpl) module;
    return (List<Object[]>) moduleImpl.getTransactionTemplate().execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            return moduleImpl.getSessionDAO().findDistinctSessionPropertyNames(moduleImpl);
        }
    });
}

From source file:com.hs.mail.imap.user.DefaultUserManager.java

public int updateAlias(final Alias alias) {
    return (Integer) getTransactionTemplate().execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            try {
                return DaoFactory.getUserDao().updateAlias(alias);
            } catch (DataAccessException ex) {
                status.setRollbackOnly();
                throw ex;
            }//  w w w. j a v a  2 s .  c o m
        }
    });
}

From source file:jp.go.aist.six.util.core.persist.castor.CastorDatastore.java

public <K, T extends Persistable<K>> Collection<K> findIdentity(final Class<T> type, final Binding filter,
        final List<? extends Order> ordering, final Limit limit) {
    Collection<K> p_ids = _executeTx("findIdentity", type, filter, new TransactionCallback<Collection<K>>() {
        public Collection<K> doInTransaction(final TransactionStatus status) {
            return getDao(type).findIdentity(filter, ordering, limit);
        }//w  w  w. ja v a 2s.co m
    });

    return p_ids;
}

From source file:org.openremote.beehive.configuration.www.SensorsAPI.java

@PUT
@Path("/{sensorId}")
public Response updateSensor(@PathParam("sensorId") Long sensorId, final SensorDTOIn sensorDTO) {
    final Sensor existingSensor = device.getSensorById(sensorId);

    Sensor optionalSensorWithSameName = device.getSensorByName(sensorDTO.getName());
    if (optionalSensorWithSameName != null
            && !optionalSensorWithSameName.getId().equals(existingSensor.getId())) {
        return Response.status(Response.Status.CONFLICT)
                .entity(new ErrorDTO(409, "A sensor with the same name already exists")).build();
    }//www .ja  va 2  s. c o  m

    try {
        Command command = device.getCommandById(sensorDTO.getCommandId());
    } catch (NotFoundException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity(new ErrorDTO(400, "Referenced command does not exist")).build();
    }

    return Response.ok(new SensorDTOOut(
            new TransactionTemplate(platformTransactionManager).execute(new TransactionCallback<Sensor>() {
                @Override
                public Sensor doInTransaction(TransactionStatus transactionStatus) {
                    // TODO: check for more optimal solution for update of sensor states

                    SensorType newType = SensorType.valueOf(sensorDTO.getType());
                    Sensor sensor;

                    if (existingSensor.getSensorType() == newType) {
                        populateSensorFromDTO(existingSensor, sensorDTO);
                        sensor = existingSensor;
                    } else {
                        device.removeSensor(existingSensor);
                        sensorRepository.delete(existingSensor);
                        sensor = createSensorFromDTO(sensorDTO);
                    }
                    sensorRepository.save(sensor);
                    return sensor;
                }
            }))).build();
}

From source file:com.vladmihalcea.HibernateCriteriaTest.java

private List<Product> getProducts_Gracefully() {
    return transactionTemplate.execute(new TransactionCallback<List<Product>>() {
        @Override/*  w w w.  j  ava 2 s.c  o m*/
        public List<Product> doInTransaction(TransactionStatus transactionStatus) {
            return entityManager
                    .createQuery(
                            "select distinct p " + "from Image i " + "inner join i.product p " + "where "
                                    + "   lower(p.name) like :name and " + "   i.index > :index ",
                            Product.class)
                    .setParameter("name", "%tv%").setParameter("index", 0).getResultList();
        }
    });
}

From source file:com.thoughtworks.go.server.service.ScheduledPipelineLoaderIntegrationTest.java

@Test
public void shouldUpdateScmConfigurationOfPluggableScmMaterialsOnPipeline() {
    String jobName = "job-one";
    PipelineConfig pipelineConfig = setupPipelineWithScmMaterial("pipeline_with_pluggable_scm_mat", "stage",
            jobName);//w  ww.j a va 2 s.co m
    final Pipeline previousSuccessfulBuildWithOlderScmConfig = simulateSuccessfulPipelineRun(pipelineConfig);
    PipelineConfig updatedPipelineConfig = configHelper.updatePipeline(pipelineConfig.name(),
            new GoConfigFileHelper.Updater<PipelineConfig>() {
                @Override
                public void update(PipelineConfig config) {
                    PluggableSCMMaterialConfig materialConfig = (PluggableSCMMaterialConfig) config
                            .materialConfigs().first();
                    materialConfig.getSCMConfig().getConfiguration().getProperty("password")
                            .setConfigurationValue(new ConfigurationValue("new_value"));
                }
            });

    final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderScmConfig);

    Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
        }
    });

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    Configuration updatedConfiguration = ((PluggableSCMMaterial) revisions
            .findRevisionFor(updatedPipelineConfig.materialConfigs().first()).getMaterial()).getScmConfig()
                    .getConfiguration();
    assertThat(updatedConfiguration.size(), is(2));
    assertThat(updatedConfiguration.getProperty("password").getConfigurationValue(),
            is(new ConfigurationValue("new_value")));
}

From source file:org.openvpms.component.business.service.archetype.ArchetypeServiceListenerTestCase.java

/**
 * Verifies that the {@link IMObject#getVersion()} is correctly reported within an {@link IArchetypeServiceListener}
 * in the context of a transaction./*from www . j  a va 2s.  c  o m*/
 */
@Test
public void testVersion() {
    final MutableInt version = new MutableInt();
    final IArchetypeService service = getArchetypeService();

    final Party person = createPerson();
    service.addListener("party.customerperson", new AbstractArchetypeServiceListener() {
        @Override
        public void saved(IMObject object) {
            version.setValue(object.getVersion());
        }
    });

    template.execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(TransactionStatus status) {
            save(person);
            return null;
        }
    });
    assertEquals(0, person.getVersion());
    assertEquals(0, version.intValue());

    person.getDetails().put("lastName", "Gum");
    template.execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(TransactionStatus status) {
            save(person);
            return null;
        }
    });
    assertEquals(1, person.getVersion());
    assertEquals(1, version.intValue());
}

From source file:org.jspresso.hrsample.backend.JspressoModelTest.java

/**
 * Tests EAGER uninitialized merge on null value.
 *//*from w w  w  . j a va 2 s.co  m*/
@Test
public void testUninitializedMerge() {
    final HibernateBackendController hbc = (HibernateBackendController) getBackendController();
    EnhancedDetachedCriteria crit = EnhancedDetachedCriteria.forClass(Department.class);
    final Department d1 = hbc.findFirstByCriteria(crit, EMergeMode.MERGE_LAZY, Department.class);
    d1.straightSetProperty("company", null);

    Department d2 = hbc.getTransactionTemplate().execute(new TransactionCallback<Department>() {

        @Override
        public Department doInTransaction(TransactionStatus status) {
            Department d = (Department) hbc.getHibernateSession().get(Department.class, d1.getId());
            status.setRollbackOnly();
            return d;
        }
    });
    d2 = hbc.merge(d2, EMergeMode.MERGE_EAGER);
    assertSame(d1, d2);
}

From source file:jp.go.aist.six.util.core.persist.castor.CastorDatastore.java

public <K, T extends Persistable<K>> List<Object> search(final Class<T> type, final SearchCriteria criteria) {
    List<Object> p_objects = _executeTx("search", type, criteria, new TransactionCallback<List<Object>>() {
        public List<Object> doInTransaction(final TransactionStatus status) {
            return getDao(type).search(criteria);
        }//from  www .  ja va 2  s  .c  o m
    });

    return p_objects;
}

From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelTrainerTask.java

/**
 * Mark model as training in a separate transaction to ensure external
 * visibility//  w ww . ja v a  2 s.c om
 * 
 * @return - id of marked model
 */
private Long findAndMark() {
    return this.transactionTemplate.execute(new TransactionCallback<Long>() {
        @Override
        public Long doInTransaction(TransactionStatus txStatus) {
            return OpenNLPMaxentModelTrainerTask.this.modelDao.findAndMarkOne(ModelState.PENDING,
                    ModelState.TRAINING);
        }
    });
}