Package com.tll.model

Examples of com.tll.model.IEntity


   * 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);
    setComplete();
    endTransaction();
    dao.getObjectContainer().close();
    final Configuration c = injector.getInstance(Configuration.class);
    final URI db4oUri = injector.getInstance(Key.get(URI.class, Db4oFile.class));
    final ObjectContainer oc = Db4o.openFile(c, db4oUri.getPath());
    dao.setObjectContainer(oc);
    ((Db4oTrans)getDbTrans()).setObjectContainer(oc);
    startNewTransaction();
    final IEntity eloaded = dao.load(new PrimaryKey<IEntity>(e));
    entityHandler.verifyLoadedEntityState(eloaded);
    dao.purge(eloaded);
    setComplete();
    endTransaction();
  }
View Full Code Here


        // related one
        if(IEntity.class.isAssignableFrom(ptype)) {
          final RelationInfo ri = schemaInfo.getRelationInfo(entityClass, pname);
          final boolean reference = ri.isReference();
          if(shouldMarshalRelation(reference, depth, options)) {
            final IEntity e = (IEntity) obj;
            final Model m = e == null ? null : marshalEntity(e, options, visited, depth + 1);
            final IEntityType etype =
              ri.getRelatedType() == null ? null : etResolver.resolveEntityType(e == null ? ri.getRelatedType() : e
                  .entityClass());
            prop = new RelatedOneProperty(etype, m, pname, reference);
          }
        }

        // related many collection
        else if(Collection.class.isAssignableFrom(ptype)) {
          final RelationInfo ri = schemaInfo.getRelationInfo(entityClass, pname);
          final boolean reference = ri.isReference();
          if(shouldMarshalRelation(reference, depth, options)) {
            List<Model> list = null;
            if(obj != null) {
              list = new ArrayList<Model>();
              final Collection<IEntity> set = (Collection<IEntity>) obj;
              for(final IEntity e : set) {
                final Model nested = marshalEntity(e, options, visited, depth + 1);
                list.add(nested);
              }
            }
            prop = new RelatedManyProperty(etResolver.resolveEntityType(ri.getRelatedType()), pname, reference, list);
          }
        }

        // map (assume <String, String> type)
        else if(Map.class.isAssignableFrom(ptype)) {
          prop = new StringMapPropertyValue(pname, generatePropertyData(entityClass, pname), (Map) obj);
        }

        else {
          final ISchemaProperty sp = schemaInfo.getSchemaProperty(entityClass, pname);

          // nested property?
          if(sp != null && sp.getPropertyType().isNested()) {
            final BeanWrapperImpl bw2 = obj == null ? new BeanWrapperImpl(ptype) : new BeanWrapperImpl(obj);
            for(final PropertyDescriptor pd2 : bw2.getPropertyDescriptors()) {
              if(bw2.isWritableProperty(pd2.getName()) && isMarshalableProperty(pd2)) {
                try {
                  final Object oval = bw2.getPropertyValue(pd2.getName());
                  model.set(createValueProperty(pd2.getPropertyType(), (pname + "_" + pd2.getName()), oval,
                      generatePropertyData(source.entityClass(), (pname + "." + pd2.getName()))));
                }
                catch(final RuntimeException e) {
                  log.debug("Didn't set nested model prop: " + pname + " due to: " + e.getMessage());
                }
              }
            }
          }
View Full Code Here

      case RELATED_ONE: {
        final Model rltdOne = (Model) pval;
        final IEntityType rltdEntityType =
          rltdOne == null ? ((RelatedOneProperty) mprop).getRelatedType() : rltdOne.getEntityType();
          assert rltdEntityType != null;
          IEntity toOne;
          if(rltdOne == null || rltdOne.isMarkedDeleted()) {
            toOne = null;
          }
          else {
            final Class<? extends IEntity> rltdEntityClass =
              (Class<? extends IEntity>) etResolver.resolveEntityClass(rltdEntityType);
            try {
              toOne = (IEntity) bw.getPropertyValue(propName);
              if(toOne == null) toOne = instantiateEntity(rltdEntityClass);
            }
            catch(final RuntimeException re) {
              log.warn("Unable to get related one entity ref", re);
              toOne = null;
            }
            log.debug("About to marshal related one [model: " + rltdOne + "] [entity: " + toOne + "]");
            marshalModel(rltdOne, toOne, visited, depth + 1);
          }
          val = toOne;
      }
      break;

      case NESTED:
        // no-op since these are expressed as "{parent}_{nestedA}"
        break;

      case RELATED_MANY: {
        if(pval != null) { // should always be non-null (see RelatedManyProperty)
          final List<Model> rmModelList = (List<Model>) pval;
          Set<IEntity> rmEntitySet = null;
          //try {
          rmEntitySet = (Set<IEntity>) bw.getPropertyValue(propName);
          final LinkedHashSet<IEntity> newRmEntitySet = new LinkedHashSet<IEntity>(rmModelList.size());
          if(rmEntitySet != null) {
            newRmEntitySet.addAll(rmEntitySet); // fail fast so don't trap exception here
          }
          //if(rmEntitySet != null) {
          // re-build the rm entity set
          for(final Model indexedModel : rmModelList) {
            assert indexedModel != null;
            final IEntityType indexedEntityType = indexedModel.getEntityType();
            final Class<IEntity> indexedEntityClass = (Class<IEntity>) etResolver.resolveEntityClass(indexedEntityType);
            final PrimaryKey<IEntity> imodelPk = new PrimaryKey<IEntity>(indexedEntityClass, indexedModel.getId());

            IEntity indexedEntity = null;

            // existing indexed entity?
            for(final IEntity ie : newRmEntitySet) {
              final PrimaryKey<IEntity> iepk = new PrimaryKey<IEntity>(ie);
              if(imodelPk.equals(iepk)) {
View Full Code Here

   * @throws Exception Upon failure
   */
  public void testNestedEntity() throws Exception {
    final Marshaler marshaler = getMarshaler();
    Assert.assertTrue(marshaler != null);
    final IEntity e = getEntityBeanFactory().getEntityCopy(NestedEntity.class, false);
    Assert.assertNotNull(e);

    final Model model = marshaler.marshalEntity(e, MarshalOptions.UNCONSTRAINED_MARSHALING);
    Assert.assertNotNull(model);
    final IEntity e2 = marshaler.marshalModel(model, e.entityClass());
    Assert.assertNotNull(e2);
    Assert.assertEquals(e, e2);
  }
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.