コード例 #1
0
 @Override
 public void deleteHomeInvite(HomeInvite homeInvite) throws StorageException {
   Transaction tx = ebean.beginTransaction();
   tx.setPersistCascade(false);
   ebean.delete(homeInvite, tx);
   tx.commit();
 }
コード例 #2
0
  @Transactional
  public void doSomething(EBasicVer v) {

    EbeanServer server = Ebean.getServer(null);

    inMethodTransaction = server.currentTransaction();

    Transaction t = server.createTransaction();
    SqlUpdate u =
        server.createSqlUpdate("update e_basicver set last_update = last_update+1 where id = ?");
    u.setParameter(1, v.getId());
    int count = server.execute(u, t);
    Assert.assertEquals(1, count);

    t.commit();

    v.setName("some change");
    try {
      Ebean.save(v);
      // never get here
      Assert.assertTrue(false);
    } catch (PersistenceException e) {
      throw e;
    }
  }
  @Test
  public void testGetForValidId() throws IOException {
    final UUID uuid = UUID.randomUUID();
    Assert.assertFalse(exprRepo.get(uuid, Organization.DEFAULT).isPresent());
    final models.ebean.Expression ebeanExpression = TestBeanFactory.createEbeanExpression();
    ebeanExpression.setUuid(uuid);
    ebeanExpression.setOrganization(
        models.ebean.Organization.findByOrganization(Organization.DEFAULT));
    try (Transaction transaction = Ebean.beginTransaction()) {
      Ebean.save(ebeanExpression);
      transaction.commit();
    }

    final Optional<Expression> expected = exprRepo.get(uuid, Organization.DEFAULT);
    Assert.assertTrue(expected.isPresent());
    Assert.assertTrue(isExpressionEbeanEquivalent(expected.get(), ebeanExpression));
  }
 @Test
 public void testGetExpressionCountWithMultipleExpr() throws IOException {
   Assert.assertEquals(0, exprRepo.getExpressionCount(Organization.DEFAULT));
   try (Transaction transaction = Ebean.beginTransaction()) {
     final models.ebean.Expression ebeanExpression1 = TestBeanFactory.createEbeanExpression();
     ebeanExpression1.setUuid(UUID.randomUUID());
     ebeanExpression1.setOrganization(
         models.ebean.Organization.findByOrganization(Organization.DEFAULT));
     Ebean.save(ebeanExpression1);
     final models.ebean.Expression ebeanExpression2 = TestBeanFactory.createEbeanExpression();
     ebeanExpression2.setUuid(UUID.randomUUID());
     ebeanExpression2.setOrganization(
         models.ebean.Organization.findByOrganization(Organization.DEFAULT));
     Ebean.save(ebeanExpression2);
     transaction.commit();
   }
   Assert.assertEquals(2, exprRepo.getExpressionCount(Organization.DEFAULT));
 }
 @Test
 public void addOrUpdateExpressionUpdateCase() throws IOException {
   final UUID uuid = UUID.randomUUID();
   final models.ebean.Organization organization;
   try (Transaction transaction = Ebean.beginTransaction()) {
     final models.ebean.Expression ebeanExpression = TestBeanFactory.createEbeanExpression();
     ebeanExpression.setUuid(uuid);
     organization = ebeanExpression.getOrganization();
     Ebean.save(ebeanExpression);
     transaction.commit();
   }
   final Expression actual =
       TestBeanFactory.createExpressionBuilder().setId(uuid).setCluster("new-cluster").build();
   exprRepo.addOrUpdateExpression(actual, TestBeanFactory.organizationFrom(organization));
   final Expression expected =
       exprRepo.get(uuid, TestBeanFactory.organizationFrom(organization)).get();
   Assert.assertEquals(expected, actual);
 }
 @Test(expected = PersistenceException.class)
 public void testThrowsExceptionWhenQueryFails() {
   final UUID uuid = UUID.randomUUID();
   exprRepo.addOrUpdateExpression(
       TestBeanFactory.createExpressionBuilder().setId(uuid).setCluster("new-cluster").build(),
       Organization.DEFAULT);
   models.ebean.Expression ebeanExpression1 =
       Ebean.find(models.ebean.Expression.class).where().eq("uuid", uuid).findUnique();
   models.ebean.Expression ebeanExpression2 =
       Ebean.find(models.ebean.Expression.class).where().eq("uuid", uuid).findUnique();
   try (Transaction transaction = Ebean.beginTransaction()) {
     ebeanExpression1.setCluster("new-cluster1");
     ebeanExpression2.setCluster("new-cluster2");
     ebeanExpression2.save();
     ebeanExpression1.save();
     transaction.commit();
   } catch (final IOException e) {
     // Do Nothing
   }
 }
コード例 #7
0
 @Override
 public void saveHomeInvite(HomeInvite homeInvite) {
   Transaction tx = ebean.beginTransaction();
   ebean.save(homeInvite, tx);
   tx.commit();
 }