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:com.vladmihalcea.HibernateCriteriaTest.java

private Product getProduct_Mercifully() {
    return transactionTemplate.execute(new TransactionCallback<Product>() {
        @Override/* w ww .  j a va  2  s  .c o m*/
        public Product doInTransaction(TransactionStatus transactionStatus) {
            CriteriaBuilder cb = entityManager.getCriteriaBuilder();
            CriteriaQuery<Product> query = cb.createQuery(Product.class);
            Root<Product> productRoot = query.from(Product.class);
            Join<Product, WarehouseProductInfo> warehouseProductInfoJoin = productRoot
                    .join(Product_.warehouseProductInfo);

            query.select(productRoot).where(cb.and(cb.equal(productRoot.get(Product_.code), "tvCode"),
                    cb.gt(warehouseProductInfoJoin.get(WarehouseProductInfo_.quantity), 50)));
            return entityManager.createQuery(query).getSingleResult();
        }
    });
}

From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDao.java

public void insertOrUpdatePipelineCounter(Pipeline pipeline, Integer lastCount, Integer newCount) {
    Map<String, Object> args = arguments("pipelineName", pipeline.getName()).and("count", newCount).asMap();
    Integer hasPipelineRow = (Integer) getSqlMapClientTemplate().queryForObject("hasPipelineInfoRow",
            pipeline.getName());//from www .ja  v a 2 s .  c om
    transactionTemplate.execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(TransactionStatus status) {
            pipelineByBuildIdCache.flushOnCommit();
            if (hasPipelineRow == 0) {
                getSqlMapClientTemplate().insert("insertPipelineLabelCounter", args);
            } else if (newCount > lastCount) {
                // Counter will not be updated when using other types of labels such as Date or Revision.
                getSqlMapClientTemplate().update("updatePipelineLabelCounter", args, 1);
            }

            return null;
        }
    });
}

From source file:com.vladmihalcea.HibernateBagMultiLevelFetchTest.java

protected void clean() {
    transactionTemplate.execute(new TransactionCallback<Void>() {
        @Override//from w  w  w  .  j a v  a2 s . c  o m
        public Void doInTransaction(TransactionStatus transactionStatus) {
            entityManager.createQuery("delete from BagLeaf where id > 0").executeUpdate();
            entityManager.createQuery("delete from BagBranch where id > 0").executeUpdate();
            entityManager.createQuery("delete from BagTree where id > 0").executeUpdate();
            entityManager.createQuery("delete from BagForest where id > 0").executeUpdate();
            entityManager.flush();
            return null;
        }
    });
}

From source file:org.fireflow.engine.modules.schedule.impl.SchedulerSpringQuartzImpl.java

/**
 * ??//  www .j ava  2s  . c o  m
 */
public void onTimerTriggered(final ScheduleJob scheduleJob, final RuntimeContext runtimeContext) {
    PersistenceService persistenceService = runtimeContext.getEngineModule(PersistenceService.class,
            scheduleJob.getProcessType());
    final ScheduleJobPersister persister = persistenceService.getScheduleJobPersister();
    final TokenPersister tokenPersister = persistenceService.getTokenPersister();
    final CalendarService calendarService = runtimeContext.getEngineModule(CalendarService.class,
            scheduleJob.getProcessType());

    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement statement = session.createWorkflowStatement(scheduleJob.getProcessType());
    if (scheduleJob.isCreateNewProcessInstance()) {
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                try {
                    statement.startProcess(scheduleJob.getProcessId(), scheduleJob.getVersion(), null, null);
                    ((ScheduleJobImpl) scheduleJob).setTriggeredTimes(scheduleJob.getTriggeredTimes() + 1);
                    ((ScheduleJobImpl) scheduleJob).setLatestTriggeredTime(calendarService.getSysDate());

                    persister.saveOrUpdate(scheduleJob);

                } catch (InvalidModelException e) {
                    ((ScheduleJobImpl) scheduleJob).setState(ScheduleJobState.FAULTED);
                    ((ScheduleJobImpl) scheduleJob).setEndTime(calendarService.getSysDate());
                    ((ScheduleJobImpl) scheduleJob).setNote(e.getMessage());
                    persister.saveOrUpdate(scheduleJob);
                    unSchedule(scheduleJob, runtimeContext);
                    e.printStackTrace();
                } catch (WorkflowProcessNotFoundException e) {
                    // TODO Auto-generated catch block
                    ((ScheduleJobImpl) scheduleJob).setState(ScheduleJobState.FAULTED);
                    ((ScheduleJobImpl) scheduleJob).setEndTime(calendarService.getSysDate());
                    ((ScheduleJobImpl) scheduleJob).setNote(e.getMessage());
                    persister.saveOrUpdate(scheduleJob);
                    unSchedule(scheduleJob, runtimeContext);
                    e.printStackTrace();
                } catch (InvalidOperationException e) {
                    // TODO Auto-generated catch block
                    ((ScheduleJobImpl) scheduleJob).setState(ScheduleJobState.FAULTED);
                    ((ScheduleJobImpl) scheduleJob).setEndTime(calendarService.getSysDate());
                    ((ScheduleJobImpl) scheduleJob).setNote(e.getMessage());
                    persister.saveOrUpdate(scheduleJob);
                    unSchedule(scheduleJob, runtimeContext);
                    e.printStackTrace();
                }
                return null;
            }

        });

    } else {
        transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus arg0) {
                ActivityInstance activityInstance = scheduleJob.getActivityInstance();

                if (activityInstance == null || activityInstance.getState()
                        .getValue() > ActivityInstanceState.DELIMITER.getValue()) {
                    ((ScheduleJobImpl) scheduleJob).setState(ScheduleJobState.FAULTED);
                    ((ScheduleJobImpl) scheduleJob).setEndTime(calendarService.getSysDate());
                    if (activityInstance == null) {
                        ((ScheduleJobImpl) scheduleJob).setNote("The activity instance is null.");
                    } else {
                        ((ScheduleJobImpl) scheduleJob).setNote("The state of the activity instance is dead.");
                    }
                    persister.saveOrUpdate(scheduleJob);
                    unSchedule(scheduleJob, runtimeContext);
                    return null;
                }

                //??
                ((ScheduleJobImpl) scheduleJob).setLatestTriggeredTime(calendarService.getSysDate());
                ((ScheduleJobImpl) scheduleJob).setTriggeredTimes(scheduleJob.getTriggeredTimes() + 1);
                persister.saveOrUpdate(scheduleJob);

                ProcessInstance processInstance = activityInstance.getProcessInstance(session);
                ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(activityInstance);
                ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(processInstance);

                RuntimeContext ctx = ((WorkflowSessionLocalImpl) session).getRuntimeContext();
                ActivityInstanceManager activityInstanceMgr = ctx.getEngineModule(ActivityInstanceManager.class,
                        activityInstance.getProcessType());

                activityInstanceMgr.onServiceCompleted(session, activityInstance);

                //?activity
                if (scheduleJob.isCancelAttachedToActivity()) {
                    Token thisToken = tokenPersister.find(Token.class, activityInstance.getTokenId());
                    Token attachedToToken = tokenPersister.find(Token.class,
                            thisToken.getAttachedToToken() == null ? "" : thisToken.getAttachedToToken());
                    if (attachedToToken != null
                            && attachedToToken.getState().getValue() < TokenState.DELIMITER.getValue()) {
                        KernelManager kernelManager = ctx.getEngineModule(KernelManager.class,
                                attachedToToken.getProcessType());

                        BookMark bookMark = new BookMark();
                        bookMark.setToken(attachedToToken);
                        bookMark.setExecutionEntrance(ExecutionEntrance.HANDLE_CANCELLATION);
                        bookMark.setExtraArg(BookMark.SOURCE_TOKEN, thisToken);

                        kernelManager.addBookMark(bookMark);

                        kernelManager.execute(session);
                    }
                }
                return null;
            }

        });

    }
}

From source file:com.github.rholder.spring.transaction.TransactionBindingSupportTest.java

/**
 * Tests the condition whereby a listener can cause failure by attempting to bind itself to
 * the transaction in the pre-commit callback.  This is caused by the listener set being
 * modified during calls to the listeners.
 *///from ww  w . j a va  2  s .  com
@Test
public void testPreCommitListenerBinding() throws Exception {
    final String beforeCommit = "beforeCommit";
    final String afterCommitInner = "afterCommit - inner";
    final String afterCommitOuter = "afterCommit = outer";

    // the listeners will play with this
    final List<String> testList = new ArrayList<String>(1);
    testList.add(beforeCommit);
    testList.add(afterCommitInner);
    testList.add(afterCommitOuter);

    final TransactionListener listener = new TransactionListenerAdapter() {
        @Override
        public int hashCode() {
            // force this listener to be first in the bound set
            return 100;
        }

        @Override
        public void beforeCommit(boolean readOnly) {
            testList.remove(beforeCommit);
            TransactionListener postCommitListener = new TransactionListenerAdapter() {
                @Override
                public void afterCommit() {
                    testList.remove(afterCommitInner);
                }
            };
            // register bogus on the transaction
            TransactionBindingSupport.bindListener(postCommitListener);
        }

        @Override
        public void afterCommit() {
            testList.remove(afterCommitOuter);
        }
    };

    final TransactionListener dummyListener = new TransactionListenerAdapter() {
        @Override
        public int hashCode() {
            // force the dummy listener to be AFTER the binding listener
            return 200;
        }
    };

    // start a transaction and kick it off
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            // just bind the listener to the transaction
            TransactionBindingSupport.bindListener(dummyListener);
            TransactionBindingSupport.bindListener(listener);
            return null;
        }
    });

    // make sure that the binding all worked
    Assert.assertTrue("Expected callbacks not all processed: " + testList, testList.size() == 0);
}

From source file:org.cfr.capsicum.server.ServerRuntimeFactoryBean.java

/**
 * {@inheritDoc}//from  w w w .  ja v a 2  s.  c o m
 */
@Override
public <T> T performInTransaction(final TransactionalOperation<T> op) {
    TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
    return transactionTemplate.execute(new TransactionCallback<T>() {

        @Override
        public T doInTransaction(TransactionStatus status) {
            return op.perform();
        }
    });
}

From source file:org.tibetjungle.demo.service.DataSourcePopulator.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull(mutableAclService, "mutableAclService required");
    Assert.notNull(template, "dataSource required");
    Assert.notNull(tt, "platformTransactionManager required");

    // Set a user account that will initially own all the created data
    Authentication authRequest = new UsernamePasswordAuthenticationToken("rod", "koala",
            AuthorityUtils.createAuthorityList("ROLE_IGNORED"));
    SecurityContextHolder.getContext().setAuthentication(authRequest);

    try {/*www  .ja v a 2  s .c  o  m*/
        template.execute("DROP TABLE CONTACTS");
        template.execute("DROP TABLE AUTHORITIES");
        template.execute("DROP TABLE USERS");
        template.execute("DROP TABLE ACL_ENTRY");
        template.execute("DROP TABLE ACL_OBJECT_IDENTITY");
        template.execute("DROP TABLE ACL_CLASS");
        template.execute("DROP TABLE ACL_SID");
    } catch (Exception e) {
        System.out.println("Failed to drop tables: " + e.getMessage());
    }

    template.execute("CREATE TABLE ACL_SID("
            + "ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,"
            + "PRINCIPAL BOOLEAN NOT NULL," + "SID VARCHAR_IGNORECASE(100) NOT NULL,"
            + "CONSTRAINT UNIQUE_UK_1 UNIQUE(SID,PRINCIPAL));");
    template.execute("CREATE TABLE ACL_CLASS("
            + "ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,"
            + "CLASS VARCHAR_IGNORECASE(100) NOT NULL," + "CONSTRAINT UNIQUE_UK_2 UNIQUE(CLASS));");
    template.execute("CREATE TABLE ACL_OBJECT_IDENTITY("
            + "ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,"
            + "OBJECT_ID_CLASS BIGINT NOT NULL," + "OBJECT_ID_IDENTITY BIGINT NOT NULL,"
            + "PARENT_OBJECT BIGINT," + "OWNER_SID BIGINT," + "ENTRIES_INHERITING BOOLEAN NOT NULL,"
            + "CONSTRAINT UNIQUE_UK_3 UNIQUE(OBJECT_ID_CLASS,OBJECT_ID_IDENTITY),"
            + "CONSTRAINT FOREIGN_FK_1 FOREIGN KEY(PARENT_OBJECT)REFERENCES ACL_OBJECT_IDENTITY(ID),"
            + "CONSTRAINT FOREIGN_FK_2 FOREIGN KEY(OBJECT_ID_CLASS)REFERENCES ACL_CLASS(ID),"
            + "CONSTRAINT FOREIGN_FK_3 FOREIGN KEY(OWNER_SID)REFERENCES ACL_SID(ID));");
    template.execute("CREATE TABLE ACL_ENTRY("
            + "ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,"
            + "ACL_OBJECT_IDENTITY BIGINT NOT NULL,ACE_ORDER INT NOT NULL,SID BIGINT NOT NULL,"
            + "MASK INTEGER NOT NULL,GRANTING BOOLEAN NOT NULL,AUDIT_SUCCESS BOOLEAN NOT NULL,"
            + "AUDIT_FAILURE BOOLEAN NOT NULL,CONSTRAINT UNIQUE_UK_4 UNIQUE(ACL_OBJECT_IDENTITY,ACE_ORDER),"
            + "CONSTRAINT FOREIGN_FK_4 FOREIGN KEY(ACL_OBJECT_IDENTITY) REFERENCES ACL_OBJECT_IDENTITY(ID),"
            + "CONSTRAINT FOREIGN_FK_5 FOREIGN KEY(SID) REFERENCES ACL_SID(ID));");

    template.execute(
            "CREATE TABLE USERS(USERNAME VARCHAR_IGNORECASE(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR_IGNORECASE(60) NOT NULL,ENABLED BOOLEAN NOT NULL);");
    template.execute(
            "CREATE TABLE AUTHORITIES(USERNAME VARCHAR_IGNORECASE(50) NOT NULL,AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL,CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME));");
    template.execute("CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY);");

    template.execute(
            "CREATE TABLE CONTACTS(ID BIGINT NOT NULL PRIMARY KEY, CONTACT_NAME VARCHAR_IGNORECASE(50) NOT NULL, EMAIL VARCHAR_IGNORECASE(50) NOT NULL)");

    /*
       Passwords encoded using MD5, NOT in Base64 format, with null as salt
       Encoded password for rod is "koala"
       Encoded password for dianne is "emu"
       Encoded password for scott is "wombat"
       Encoded password for peter is "opal" (but user is disabled)
       Encoded password for bill is "wombat"
       Encoded password for bob is "wombat"
       Encoded password for jane is "wombat"
            
     */
    template.execute(
            "INSERT INTO USERS VALUES('rod','$2a$10$75pBjapg4Nl8Pzd.3JRnUe7PDJmk9qBGwNEJDAlA3V.dEJxcDKn5O',TRUE);");
    template.execute(
            "INSERT INTO USERS VALUES('dianne','$2a$04$bCMEyxrdF/7sgfUiUJ6Ose2vh9DAMaVBldS1Bw2fhi1jgutZrr9zm',TRUE);");
    template.execute(
            "INSERT INTO USERS VALUES('scott','$2a$06$eChwvzAu3TSexnC3ynw4LOSw1qiEbtNItNeYv5uI40w1i3paoSfLu',TRUE);");
    template.execute(
            "INSERT INTO USERS VALUES('peter','$2a$04$8.H8bCMROLF4CIgd7IpeQ.tcBXLP5w8iplO0n.kCIkISwrIgX28Ii',FALSE);");
    template.execute(
            "INSERT INTO USERS VALUES('bill','$2a$04$8.H8bCMROLF4CIgd7IpeQ.3khQlPVNWbp8kzSQqidQHGFurim7P8O',TRUE);");
    template.execute(
            "INSERT INTO USERS VALUES('bob','$2a$06$zMgxlMf01SfYNcdx7n4NpeFlAGU8apCETz/i2C7VlYWu6IcNyn4Ay',TRUE);");
    template.execute(
            "INSERT INTO USERS VALUES('jane','$2a$05$ZrdS7yMhCZ1J.AAidXZhCOxdjD8LO/dhlv4FJzkXA6xh9gdEbBT/u',TRUE);");
    template.execute("INSERT INTO AUTHORITIES VALUES('rod','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('rod','ROLE_SUPERVISOR');");
    template.execute("INSERT INTO AUTHORITIES VALUES('dianne','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('scott','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('peter','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('bill','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('bob','ROLE_USER');");
    template.execute("INSERT INTO AUTHORITIES VALUES('jane','ROLE_USER');");

    template.execute("INSERT INTO contacts VALUES (1, 'John Smith', 'john@somewhere.com');");
    template.execute("INSERT INTO contacts VALUES (2, 'Michael Citizen', 'michael@xyz.com');");
    template.execute("INSERT INTO contacts VALUES (3, 'Joe Bloggs', 'joe@demo.com');");
    template.execute("INSERT INTO contacts VALUES (4, 'Karen Sutherland', 'karen@sutherland.com');");
    template.execute("INSERT INTO contacts VALUES (5, 'Mitchell Howard', 'mitchell@abcdef.com');");
    template.execute("INSERT INTO contacts VALUES (6, 'Rose Costas', 'rose@xyz.com');");
    template.execute("INSERT INTO contacts VALUES (7, 'Amanda Smith', 'amanda@abcdef.com');");
    template.execute("INSERT INTO contacts VALUES (8, 'Cindy Smith', 'cindy@smith.com');");
    template.execute("INSERT INTO contacts VALUES (9, 'Jonathan Citizen', 'jonathan@xyz.com');");

    for (int i = 10; i < createEntities; i++) {
        String[] person = selectPerson();
        template.execute("INSERT INTO contacts VALUES (" + i + ", '" + person[2] + "', '"
                + person[0].toLowerCase() + "@" + person[1].toLowerCase() + ".com');");
    }

    // Create acl_object_identity rows (and also acl_class rows as needed
    for (int i = 1; i < createEntities; i++) {
        final ObjectIdentity objectIdentity = new ObjectIdentityImpl(Contact.class, new Long(i));
        tt.execute(new TransactionCallback<Object>() {
            public Object doInTransaction(TransactionStatus arg0) {
                mutableAclService.createAcl(objectIdentity);

                return null;
            }
        });
    }

    // Now grant some permissions
    grantPermissions(1, "rod", BasePermission.ADMINISTRATION);
    grantPermissions(2, "rod", BasePermission.READ);
    grantPermissions(3, "rod", BasePermission.READ);
    grantPermissions(3, "rod", BasePermission.WRITE);
    grantPermissions(3, "rod", BasePermission.DELETE);
    grantPermissions(4, "rod", BasePermission.ADMINISTRATION);
    grantPermissions(4, "dianne", BasePermission.ADMINISTRATION);
    grantPermissions(4, "scott", BasePermission.READ);
    grantPermissions(5, "dianne", BasePermission.ADMINISTRATION);
    grantPermissions(5, "dianne", BasePermission.READ);
    grantPermissions(6, "dianne", BasePermission.READ);
    grantPermissions(6, "dianne", BasePermission.WRITE);
    grantPermissions(6, "dianne", BasePermission.DELETE);
    grantPermissions(6, "scott", BasePermission.READ);
    grantPermissions(7, "scott", BasePermission.ADMINISTRATION);
    grantPermissions(8, "dianne", BasePermission.ADMINISTRATION);
    grantPermissions(8, "dianne", BasePermission.READ);
    grantPermissions(8, "scott", BasePermission.READ);
    grantPermissions(9, "scott", BasePermission.ADMINISTRATION);
    grantPermissions(9, "scott", BasePermission.READ);
    grantPermissions(9, "scott", BasePermission.WRITE);
    grantPermissions(9, "scott", BasePermission.DELETE);

    // Now expressly change the owner of the first ten contacts
    // We have to do this last, because "rod" owns all of them (doing it sooner would prevent ACL updates)
    // Note that ownership has no impact on permissions - they're separate (ownership only allows ACl editing)
    changeOwner(5, "dianne");
    changeOwner(6, "dianne");
    changeOwner(7, "scott");
    changeOwner(8, "dianne");
    changeOwner(9, "scott");

    String[] users = { "bill", "bob", "jane" }; // don't want to mess around with consistent sample data
    Permission[] permissions = { BasePermission.ADMINISTRATION, BasePermission.READ, BasePermission.DELETE };

    for (int i = 10; i < createEntities; i++) {
        String user = users[rnd.nextInt(users.length)];
        Permission permission = permissions[rnd.nextInt(permissions.length)];
        grantPermissions(i, user, permission);

        String user2 = users[rnd.nextInt(users.length)];
        Permission permission2 = permissions[rnd.nextInt(permissions.length)];
        grantPermissions(i, user2, permission2);
    }

    SecurityContextHolder.clearContext();
}

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

@Test
public void shouldUpdatePackageMaterialConfigurationOfMaterialsOnPipeline() throws Exception {
    String jobName = "job-one";
    PipelineConfig pipelineConfig = setupPipelineWithPackageMaterial("pipeline_with_pluggable_scm_mat", "stage",
            jobName);/*  w  w w . ja v  a 2 s.co  m*/
    final Pipeline previousSuccessfulBuildWithOlderPackageConfig = simulateSuccessfulPipelineRun(
            pipelineConfig);
    PipelineConfig updatedPipelineConfig = configHelper.updatePipeline(pipelineConfig.name(),
            new GoConfigFileHelper.Updater<PipelineConfig>() {
                @Override
                public void update(PipelineConfig config) {
                    PackageMaterialConfig materialConfig = (PackageMaterialConfig) config.materialConfigs()
                            .first();
                    materialConfig.getPackageDefinition().getConfiguration().getProperty("package-key2")
                            .setConfigurationValue(new ConfigurationValue("package-updated-value"));
                    materialConfig.getPackageDefinition().getRepository().getConfiguration()
                            .getProperty("repo-key2")
                            .setConfigurationValue(new ConfigurationValue("repo-updated-value"));
                }
            });
    final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderPackageConfig);
    Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
        }
    });

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    PackageMaterial updatedMaterial = (PackageMaterial) revisions
            .findRevisionFor(updatedPipelineConfig.materialConfigs().first()).getMaterial();
    Configuration updatedConfiguration = updatedMaterial.getPackageDefinition().getConfiguration();
    assertThat(updatedConfiguration.size(), is(2));
    assertThat(updatedConfiguration.getProperty("package-key2").getConfigurationValue(),
            is(new ConfigurationValue("package-updated-value")));
    assertThat(updatedMaterial.getPackageDefinition().getRepository().getConfiguration().size(), is(2));
    assertThat(updatedMaterial.getPackageDefinition().getRepository().getConfiguration()
            .getProperty("repo-key2").getConfigurationValue(),
            is(new ConfigurationValue("repo-updated-value")));
}

From source file:com.vladmihalcea.HibernateCriteriaTest.java

private Product getProduct_Gracefully() {
    return transactionTemplate.execute(new TransactionCallback<Product>() {
        @Override/*from   ww  w .j av a2  s  .  c  o  m*/
        public Product doInTransaction(TransactionStatus transactionStatus) {
            return entityManager
                    .createQuery("select p " + "from Product p " + "inner join p.warehouseProductInfo w "
                            + "where " + "   p.code = :code and " + "   w.quantity > :quantity ", Product.class)
                    .setParameter("code", "tvCode").setParameter("quantity", 50).getSingleResult();
        }
    });
}