Examples of SqlUpdate


Examples of com.avaje.ebean.SqlUpdate

    Ebean.runCacheWarming(Country.class);
    int cacheSize = countryCache.size();
    Assert.assertTrue("cacheSize: " + cacheSize, cacheSize > 0);

    SqlUpdate sqlUpdate = Ebean
        .createSqlUpdate("update o_country set name = :name where code = :code");
    sqlUpdate.setParameter("name", "Aotearoa");
    sqlUpdate.setParameter("code", "NZ");

    // this should just clear the entire country cache
    int rows = sqlUpdate.execute();
    Assert.assertEquals(1, rows);
    Assert.assertEquals(0, countryCache.size());

    // set it back...
    sqlUpdate.setParameter("name", "New Zealand");
    sqlUpdate.setParameter("code", "NZ");
    rows = sqlUpdate.execute();
    Assert.assertEquals(1, rows);
  }
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

  public void test() {

    // Ebean.getServer(null);

    String sql = "insert into audit_log (id, description, modified_description) values (?,?,?)";
    SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql);
    sqlUpdate.setParameter(1, 10000);
    sqlUpdate.setParameter(2, "hello");
    sqlUpdate.setParameter(3, "rob");

    sqlUpdate.execute();

  }
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

  private void init() {

    Ebean.beginTransaction();
    try {
      String sql;
      SqlUpdate delete;

      sql = "delete from td_child";
      delete = Ebean.createSqlUpdate(sql);
      delete.execute();

      sql = "delete from td_parent";
      delete = Ebean.createSqlUpdate(sql);
      delete.execute();

      EdParent parent = new EdParent();
      parent.setName("MyComputer");

      EdChild child = new EdChild();
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

        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();
       
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

public class TestM2MVanilla extends BaseTestCase {

  @Test
  public void testVanilla() {

    SqlUpdate delInt = Ebean.createSqlUpdate("delete from mrole_muser");
    SqlUpdate delRoles = Ebean.createSqlUpdate("delete from mrole");
    SqlUpdate delUsers = Ebean.createSqlUpdate("delete from muser");
   
    Ebean.execute(delInt);
    Ebean.execute(delRoles);
    Ebean.execute(delUsers);
   
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

   
    final Long id = log2.getId();
    final String updateDml = "update audit_log set description = :desc where id = :id";
    final String updateModDml = "update audit_log set modified_description = :desc";
   
    SqlUpdate sqlUpdate = Ebean.createSqlUpdate(updateDml);
    sqlUpdate.setParameter("desc", "foo2");
    sqlUpdate.setParameter("id", id);
    sqlUpdate.execute();
   
    SqlUpdate updateMod = Ebean.createSqlUpdateupdateModDml ) ;
    updateMod.setParameter("desc", "mod0");
    updateMod.execute();
   
    AuditLog log3 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo2", log3.getDescription());
    Assert.assertEquals("mod0", log3.getModifiedDescription());

    Ebean.execute(new TxRunnable() { 
      public void run() { 
        SqlUpdate update = Ebean.createSqlUpdateupdateDml ) ;
        update.setParameter("desc", "foo3");
        update.setParameter("id", id);
        update.execute();

        SqlUpdate updateMod = Ebean.createSqlUpdateupdateModDml ) ;
        updateMod.setParameter("desc", "mod1");
        updateMod.execute();
     
    });

    AuditLog log4 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo3", log4.getDescription());
    Assert.assertEquals("mod1", log4.getModifiedDescription());

   
    Ebean.beginTransaction();
   
    SqlUpdate update = Ebean.createSqlUpdate( updateDml) ;
    update.setParameter("desc", "foo4");
    update.setParameter("id", id);
    update.execute();

    updateMod = Ebean.createSqlUpdateupdateModDml ) ;
    updateMod.setParameter("desc", "mod2");
    updateMod.execute();
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

      // OneToOne exported side with delete cascade
      BeanPropertyAssocOne<?>[] expOnes = descriptor.propertiesOneExportedDelete();
      for (int i = 0; i < expOnes.length; i++) {       
        BeanDescriptor<?> targetDesc = expOnes[i].getTargetDescriptor();
        if (targetDesc.isDeleteRecurseSkippable() && !targetDesc.isBeanCaching()) {
          SqlUpdate sqlDelete = expOnes[i].deleteByParentId(id, idList);
          executeSqlUpdate(sqlDelete, t);
        } else {
          List<Object> childIds = expOnes[i].findIdsByParentId(id, idList, t);
          deleteChildrenById(t, targetDesc, childIds);
        }
      }

      // OneToMany's with delete cascade
      BeanPropertyAssocMany<?>[] manys = descriptor.propertiesManyDelete();
      for (int i = 0; i < manys.length; i++) {
        BeanDescriptor<?> targetDesc = manys[i].getTargetDescriptor();
        if (targetDesc.isDeleteRecurseSkippable() && !targetDesc.isBeanCaching()) {
          // we can just delete children with a single statement
          SqlUpdate sqlDelete = manys[i].deleteByParentId(id, idList);
          executeSqlUpdate(sqlDelete, t);
        } else {
          // we need to fetch the Id's to delete (recurse or notify L2 cache)
          List<Object> childIds = manys[i].findIdsByParentId(id, idList, t, null);
          if (!childIds.isEmpty()) {
            delete(targetDesc, null, childIds, t);
          }
        }
      }
    }

    // ManyToMany's ... delete from intersection table
    BeanPropertyAssocMany<?>[] manys = descriptor.propertiesManyToMany();
    for (int i = 0; i < manys.length; i++) {
      SqlUpdate sqlDelete = manys[i].deleteByParentId(id, idList);
      if (t.isLogSummary()) {
        t.logSummary("-- Deleting intersection table entries: " + manys[i].getFullBeanName());
      }
      executeSqlUpdate(sqlDelete, t);
    }

    // delete the bean(s)
    SqlUpdate deleteById = descriptor.deleteById(id, idList);
    if (t.isLogSummary()) {
      t.logSummary("-- Deleting " + descriptor.getName() + " Ids" + idList);
    }

    // use Id's to update L2 cache rather than Bulk table event
    deleteById.setAutoTableMod(false);
    if (idList != null) {
      t.getEvent().addDeleteByIdList(descriptor, idList);
    } else {
      t.getEvent().addDeleteById(descriptor, id);
    }
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

            throw new PersistenceException(msg);

          } else {
            // build a intersection row for 'insert'
            IntersectionRow intRow = prop.buildManyToManyMapBean(saveManyPropRequest.getParentBean(), otherBean);
            SqlUpdate sqlInsert = intRow.createInsert(server);
            executeSqlUpdate(sqlInsert, t);
          }
        }
      }
    }
    if (deletions != null && !deletions.isEmpty()) {
      for (Object other : deletions) {
        EntityBean otherDelete = (EntityBean)other;
        // the object from the 'other' side of the ManyToMany
        // build a intersection row for 'delete'
        IntersectionRow intRow = prop.buildManyToManyMapBean(saveManyPropRequest.getParentBean(), otherDelete);
        SqlUpdate sqlDelete = intRow.createDelete(server);
        executeSqlUpdate(sqlDelete, t);
      }
    }

    // decrease the depth back to what it was
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

  private int deleteAssocManyIntersection(EntityBean bean, BeanPropertyAssocMany<?> many, Transaction t) {

    // delete all intersection rows for this bean
    IntersectionRow intRow = many.buildManyToManyDeleteChildren(bean);
    SqlUpdate sqlDelete = intRow.createDeleteChildren(server);

    return executeSqlUpdate(sqlDelete, t);
  }
View Full Code Here

Examples of com.avaje.ebean.SqlUpdate

      // cascade delete the beans in the collection
      BeanDescriptor<?> targetDesc = many.getTargetDescriptor();
      if (targetDesc.isDeleteRecurseSkippable() && !targetDesc.isBeanCaching()) {
        // Just delete all the children with one statement
        IntersectionRow intRow = many.buildManyDeleteChildren(parentBean, excludeDetailIds);
        SqlUpdate sqlDelete = intRow.createDelete(server);
        executeSqlUpdate(sqlDelete, t);

      } else {
        // Delete recurse using the Id values of the children
        Object parentId = desc.getId(parentBean);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.