Package com.tll.model

Examples of com.tll.model.IEntity


  /**
   * Test CRUD and find ops
   * @throws Exception
   */
  final void daoCRUDAndFind() throws Exception {
    IEntity e = getTestEntity();
    Assert.assertTrue(e.isNew(), "The created test entity is not new and should be");

    Long pk = null;

    // create
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();
    pk = e.getId();
    Assert.assertNotNull(pk, "The created entities' primary key is null");
    Assert.assertTrue(!e.isNew(), "The created entity is new and shouldn't be");

    if(e instanceof ITimeStampEntity) {
      // verify time stamp
      Assert.assertNotNull(((ITimeStampEntity) e).getDateCreated(),
          "Created time stamp entity does not have a create date");
      Assert.assertNotNull(((ITimeStampEntity) e).getDateModified(),
          "Created time stamp entity does not have a modify date");
    }

    // retrieve
    getDbTrans().startTrans();
    e = dao.load(e.entityClass(), e.getId());
    Assert.assertNotNull(e, "The loaded entity is null");
    entityHandler.verifyLoadedEntityState(e);
    getDbTrans().setComplete(); // we need to do this for JDO in order to ensure a detached copy is made
    getDbTrans().endTrans();

    // update
    getDbTrans().startTrans();
    entityHandler.alterTestEntity(e);
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    // find (update verify)
    getDbTrans().startTrans();
    e = getEntityFromDb(e.entityClass(), e.getId());
    Assert.assertNotNull(e, "The retrieved entity for update check is null");
    getDbTrans().setComplete();
    getDbTrans().endTrans();
    entityHandler.verifyEntityAlteration(e);

    if(e instanceof ITimeStampEntity) {
      // verify modify date
      final ITimeStampEntity tse = (ITimeStampEntity) e;
      Assert.assertTrue(tse.getDateModified() != null && tse.getDateCreated() != null
          && tse.getDateModified().getTime() >= tse.getDateCreated().getTime(),
          "Updated time stamp entity does not an updated modify date");
    }

    // purge (delete)
    getDbTrans().startTrans();
    dao.purge(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    // verify purge
    getDbTrans().startTrans();
    getDbTrans().setComplete();
    try {
      e = getEntityFromDb(e.entityClass(), e.getId());
      Assert.assertNull(e, "The entity was not purged");
    }
    catch(final EntityNotFoundException ex) {
      // expected
    }
View Full Code Here


  }

  @SuppressWarnings({
    "unchecked", "rawtypes" })
  final void daoFindByName() throws Exception {
    IEntity e = getTestEntity();

    // create
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();
View Full Code Here

  /**
   * Tests the find by ids method
   * @throws Exception
   */
  final void daoFindByIds() throws Exception {
    IEntity e = getTestEntity();
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    getDbTrans().startTrans();
    Assert.assertNotNull(e, "Null generated test entity");
    final ArrayList<Long> ids = new ArrayList<Long>(1);
    ids.add(e.getId());
    final List<IEntity> list = dao.findByPrimaryKeys(entityHandler.entityClass(), ids, null);
    getDbTrans().endTrans();
    Assert.assertTrue(list != null, "find by ids returned null list");
    Assert.assertTrue(list.size() == 1, "find by ids returned list of size: " + list.size());
  }
View Full Code Here

    BusinessKeyFactory bkf = new BusinessKeyFactory(new EntityMetadata());
    if(!bkf.hasBusinessKeys(entityHandler.entityClass())) {
      return;
    }

    IEntity e = getTestEntity();
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    getDbTrans().startTrans();
    final IEntity e2 = getTestEntity();
    ensureNonUnique(e, e2);
    try {
      dao.persist(e2);
      getDbTrans().setComplete();
      getDbTrans().endTrans();
View Full Code Here

      logger.debug("Expected exception: " + de.getMessage());
    }
  }

  final void daoPurgeNonExistantEntity() throws Exception {
    IEntity e = getTestEntity();
    final Long pk = e.getId();

    // save it first
    e = dao.persist(e);

    getDbTrans().setComplete();
    getDbTrans().endTrans();
    getDbTrans().startTrans();

    // delete it (with key)
    dao.purge(e.entityClass(), pk);

    getDbTrans().setComplete();
    getDbTrans().endTrans();
    getDbTrans().startTrans();
View Full Code Here

    }
  }

  final void daoFindEntityByPrimaryKeyCriteria() throws Exception {
    // persist the target test entity
    IEntity e = getTestEntity();
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    final Criteria<IEntity> c = new Criteria<IEntity>(entityHandler.entityClass());
    c.getPrimaryGroup().addCriterion(e.entityClass(), e.getId());
    getDbTrans().startTrans();
    final IEntity re = dao.findEntity(c);
    Assert.assertTrue(re != null);
    Assert.assertEquals(re, e);
  }
View Full Code Here

    try {
      BusinessKeyFactory bkf = new BusinessKeyFactory(new EntityMetadata());
      final IBusinessKeyDefinition<IEntity>[] bkdefs = bkf.definitions(entityHandler.entityClass());

      // persist the target test entity
      IEntity e = getTestEntity();
      e = dao.persist(e);
      getDbTrans().setComplete();
      getDbTrans().endTrans();

      getDbTrans().startTrans();
      final Criteria<IEntity> c = new Criteria<IEntity>(entityHandler.entityClass());
      for(final IBusinessKeyDefinition<IEntity> bkdef : bkdefs) {
        final IBusinessKey<IEntity> bk = BusinessKeyFactory.create(e, bkdef);
        c.getPrimaryGroup().addCriterion(bk, true);
      }
      final IEntity re = dao.findEntity(c);
      Assert.assertTrue(re != null);
      Assert.assertEquals(re, e);
    }
    catch(final BusinessKeyNotDefinedException e) {
      // ok skip
View Full Code Here

      getDbTrans().startTrans();
      final Criteria<IEntity> c = new Criteria<IEntity>(entityHandler.entityClass());
      c.getPrimaryGroup().addCriterion(
          new NameKey(e.entityClass(), e.getName(), entityHandler.getActualNameProperty()), true);
      final IEntity re = dao.findEntity(c);
      Assert.assertTrue(re != null);
      if(re != null) Assert.assertEquals(re, e);
    }
  }
View Full Code Here

  final void daoFindEntityByCriteria() throws Exception {
    final Criteria c = entityHandler.getTestCriteria();
    if(c == null) return; // ok

    // persist the target test entity
    IEntity e = getTestEntity();
    e = dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();

    getDbTrans().startTrans();
View Full Code Here

   * Tests the integrity of the object graph between the open/close boundary of
   * a db4o session.
   * @throws Exception
   */
  void daoDb4oTestOpenCloseLoad() throws Exception {
    final IEntity e = getTestEntity();
    dao.persist(e);
    getDbTrans().setComplete();
    getDbTrans().endTrans();
    dao.getObjectContainer().close();
    final EmbeddedConfiguration c = injector.getInstance(EmbeddedConfiguration.class);
    final URI db4oUri = injector.getInstance(Key.get(URI.class, Db4oFile.class));
    final EmbeddedObjectContainer oc = Db4oEmbedded.openFile(c, db4oUri.getPath());
    dao.setObjectContainer(oc);
    ((Db4oTrans) getDbTrans()).setObjectContainer(oc);
    ((Db4oEntityFactory) getEntityFactory()).setObjectContainer(oc);
    getDbTrans().startTrans();
    final IEntity eloaded = dao.load(e.entityClass(), e.getId());
    entityHandler.verifyLoadedEntityState(eloaded);
    dao.purge(eloaded);
    getDbTrans().setComplete();
    getDbTrans().endTrans();
  }
View Full Code Here

TOP

Related Classes of com.tll.model.IEntity

Copyright © 2018 www.massapicom. 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.