Package com.tll.model

Examples of com.tll.model.IEntity


    if(search == null || !search.isSet()) {
      payload.getStatus().addMsg(search == null ? "No search criteria specified" : "Unset search criteria",
          MsgLevel.ERROR, MsgAttr.STATUS.flag);
    }
    else {
      IEntity e = null;
      IEntityType et = null;
      if(search instanceof PrimaryKeySearch) {
        final PrimaryKeySearch pks = (PrimaryKeySearch) search;
        e = loadEntityByPrimaryKey(pks, payload.getStatus());
        et = pks.getKey().getEntityType();
      }
      else if(search instanceof BusinessKeySearch) {
        final BusinessKeySearch bks = (BusinessKeySearch) search;
        e = loadEntityByBusinesKey(bks, payload.getStatus());
        et = bks.getEntityType();
      }
      else if(search instanceof EntityNameSearch) {
        final EntityNameSearch ens = (EntityNameSearch) search;
        e = loadEntityByName(ens, payload.getStatus());
        et = ens.getEntityType();
      }
      else {
        // override
        loadImpl(search, payload);
        return;
      }

      if(e != null) {
        assert et != null;
        try {
          final Model m = entityToModel(et, e);
          payload.setModel(m);
          payload.getStatus().addMsg(e.descriptor() + " loaded.", MsgLevel.INFO, MsgAttr.STATUS.flag);
        }
        catch(final Exception ex) {
          RpcServlet.exceptionToStatus(ex, payload.getStatus());
        }
      }
View Full Code Here


   */
  @SuppressWarnings("unchecked")
  protected void doAdd(Model model, ModelPayload payload) throws EntityExistsException, ConstraintViolationException {
    final Class<? extends IEntity> entityClass =
      (Class<? extends IEntity>) context.getEntityTypeResolver().resolveEntityClass(model.getEntityType());
    IEntity e = context.getMarshaler().marshalModel(model, entityClass);
    final IEntityService<IEntity> svc =
      (IEntityService<IEntity>) context.getEntityServiceFactory().instanceByEntityType(entityClass);
    e = svc.persist(e);

    // marshall
    model = marshal(model.getEntityType(), e);
    payload.setModel(model);

    payload.getStatus().addMsg(e.descriptor() + " added.", MsgLevel.INFO, MsgAttr.STATUS.flag);
  }
View Full Code Here

    final IEntityService<IEntity> svc =
      (IEntityService<IEntity>) context.getEntityServiceFactory().instanceByEntityType(entityClass);
    final Class<IEntity> eclass = resolveEntityClass(modelChanges.getEntityType());

    // load current state of this entity
    IEntity e = svc.load(new PrimaryKey<IEntity>(eclass, modelChanges.getId()));

    // ensure versions match!
    if(!ObjectUtil.equals(modelChanges.getVersion(), e.getVersion())) {
      throw new VersionMismatchException(eclass, e.getVersion(), modelChanges.getVersion());
    }

    // marshal the changes only
    context.getMarshaler().marshalModel(modelChanges, e);
    final boolean isNew = e.isNew();
    e = svc.persist(e);

    // marshal
    final Model refreshedModel = marshal(modelChanges.getEntityType(), e);
    payload.setModel(refreshedModel);

    payload.getStatus().addMsg(e.descriptor() + (isNew ? " added." : " updated."), MsgLevel.INFO, MsgAttr.STATUS.flag);
  }
View Full Code Here

    try {
      final ModelKey mkey = search.getKey();
      final IEntityType et = mkey.getEntityType();
      final Class<IEntity> ec = (Class<IEntity>) context.getEntityTypeResolver().resolveEntityClass(et);
      final IEntityService<IEntity> svc = getEntityService(et);
      final IEntity e = svc.load(new PrimaryKey(ec, mkey.getId()));
      return e;
    }
    catch(final EntityNotFoundException e) {
      RpcServlet.exceptionToStatus(e, status);
      return null;
View Full Code Here

      IBusinessKey<IEntity> bk;
      bk = BusinessKeyFactory.create(ec, bkName);
      for(final IPropertyValue pv : pvs) {
        bk.setPropertyValue(pv.getPropertyName(), pv.getValue());
      }
      final IEntity e = getEntityService(et).load(bk);
      // final Model m = marshal(et, e);
      // payload.setModel(m);
      status.addMsg(e.descriptor() + " loaded.", MsgLevel.INFO, MsgAttr.STATUS.flag);
      return e;
    }
    catch(final BusinessKeyNotDefinedException e) {
      RpcServlet.exceptionToStatus(e, status);
      return null;
View Full Code Here

      final String name = search.getName();
      final IEntityService<IEntity> svc = getEntityService(et);
      if(svc instanceof INamedEntityService == false) {
        throw new RuntimeException("Entity type: " + et + "doesn't support loading by name.");
      }
      final IEntity e = ((INamedEntityService) svc).load(new NameKey(ec, name));
      // final Model m = marshal(et, e);
      // payload.setModel(m);
      status.addMsg(e.descriptor() + " loaded.", MsgLevel.INFO, MsgAttr.STATUS.flag);
      return e;
    }
    catch(final EntityNotFoundException e) {
      RpcServlet.exceptionToStatus(e, status);
      return null;
View Full Code Here

    try {
      final Class<IEntity> entityClass =
        (Class<IEntity>) context.getEntityTypeResolver().resolveEntityClass(ref.getEntityType());
      final IEntityService<IEntity> svc = context.getEntityServiceFactory().instanceByEntityType(entityClass);
      final PrimaryKey pk = new PrimaryKey(entityClass, ref.getId());
      final IEntity e = svc.load(pk);
      svc.purge(e);
      payload.setRef(ref);
      payload.getStatus().addMsg(e.descriptor() + " purged.", MsgLevel.INFO, MsgAttr.STATUS.flag);
    }
    catch(final EntityNotFoundException e) {
      RpcServlet.exceptionToStatus(e, payload.getStatus());
    }
    catch(final RuntimeException e) {
View Full Code Here

    // entity prototypes
    etitr = auxDataRequest.getEntityPrototypeRequests();
    while(etitr != null && etitr.hasNext()) {
      final IEntityType et = etitr.next();
      final IEntity e =
        context.getEntityAssembler().assembleEntity(
            (Class<IEntity>) context.getEntityTypeResolver().resolveEntityClass(et), null, false);
      final MarshalOptions mo = getMarshalOptions(context, et, MarshalOptions.NO_REFERENCES);
      final Model model = context.getMarshaler().marshalEntity(e, mo);
      if(entityPrototypes == null) {
View Full Code Here

    if(testEntityRefStack.size() > 0) {
      for(final PkAndType n : testEntityRefStack) {
        assert n.entityType == entityHandler.entityClass();
        if(globalTransactions) getDbTrans().startTrans();
        try {
          final IEntity e = dao.load(n.entityType, n.pk);
          logger.debug("Tearing down test entity: " + e + "..");
          entityHandler.teardownTestEntity(e);
          if(globalTransactions) getDbTrans().setComplete();
        }
        catch(final EntityNotFoundException e) {
View Full Code Here

  /**
   * Tests the dao impls transaction integrity.
   * @throws Exception
   */
  final void daoTransactionIntegrity() throws Exception {
    IEntity e = getTestEntity();

    e = dao.persist(e);
    getDbTrans().endTrans(); // rollback

    getDbTrans().startTrans();
    try {
      e = dao.load(e.entityClass(), e.getId());
      Assert.fail("Loaded entity that should not have been committed into the db due to trans rollback");
    }
    catch(final EntityNotFoundException ex) {
      // expected
    }
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.