@Test(dataProvider = "state_and_events")
 public void testIdempotency(EntityState.STATE state, EntityState.EVENT event) throws Exception {
   Process mockEntity = new Process();
   mockEntity.setName("test");
   storeEntity(EntityType.PROCESS, "test");
   EntityState entityState = new EntityState(mockEntity).setCurrentState(state);
   entityState.nextTransition(event);
   Assert.assertEquals(entityState.getCurrentState(), state);
 }
Esempio n. 2
0
  public FieldIterator getDirtyIterator(CmpEntityBeanContext ctx) {
    int dirtyFields = 0;
    final EntityState entityState = getEntityState(ctx);
    for (int i = 0; i < tableFields.length; ++i) {
      JDBCCMPFieldBridge field = tableFields[i];
      if (entityState.isCheckDirty(i) && field.isDirty(ctx)) {
        entityState.setUpdateRequired(i);
        ++dirtyFields;
      }
    }

    return dirtyFields > 0 ? getEntityState(ctx).getDirtyIterator(ctx) : EMPTY_FIELD_ITERATOR;
  }
Esempio n. 3
0
 public boolean isStoreRequired(CmpEntityBeanContext ctx) {
   boolean modified = false;
   final EntityState entityState = getEntityState(ctx);
   if (entityState.isCreated()) {
     modified = areCmpFieldsDirty(ctx, entityState);
     if (!modified) {
       for (int i = 0; i < cmrFields.length; ++i) {
         if (cmrFields[i].isDirty(ctx)) {
           modified = true;
           break;
         }
       }
     }
   }
   return modified;
 }
Esempio n. 4
0
 /**
  * This method is used to determined whether the instance was modified. NOTE, even if the method
  * returns true the isStoreRequired for this same instance might return false, e.g. a CMR field
  * that doesn't have a foreign key was modified.
  *
  * @param ctx
  * @return
  */
 public boolean isModified(CmpEntityBeanContext ctx) {
   boolean invalidateCache = false;
   final EntityState entityState = getEntityState(ctx);
   if (entityState.isCreated()) {
     invalidateCache = areCmpFieldsDirty(ctx, entityState);
     if (!invalidateCache) {
       for (int i = 0; i < cmrFields.length; ++i) {
         if (cmrFields[i].invalidateCache(ctx)) {
           invalidateCache = true;
           break;
         }
       }
     }
   }
   return invalidateCache;
 }
Esempio n. 5
0
  public FieldIterator getLoadIterator(
      JDBCCMPFieldBridge requiredField, JDBCReadAheadMetaData readahead, CmpEntityBeanContext ctx) {
    boolean[] loadGroup;
    if (requiredField == null) {
      if (readahead != null && !readahead.isNone()) {
        if (log.isTraceEnabled()) {
          log.trace("Eager-load for entity: readahead=" + readahead);
        }
        loadGroup = getLoadGroupMask(readahead.getEagerLoadGroup());
      } else {
        if (log.isTraceEnabled()) {
          log.trace("Default eager-load for entity: readahead=" + readahead);
        }
        loadGroup = eagerLoadGroupMask;
      }
    } else {
      loadGroup = new boolean[tableFields.length];
      int requiredInd = requiredField.getTableIndex();
      loadGroup[requiredInd] = true;
      for (Iterator groups = lazyLoadGroupMasks.iterator(); groups.hasNext(); ) {
        boolean[] lazyGroup = (boolean[]) groups.next();
        if (lazyGroup[requiredInd]) {
          for (int i = 0; i < loadGroup.length; ++i) loadGroup[i] = loadGroup[i] || lazyGroup[i];
        }
      }
    }

    FieldIterator loadIter;
    if (loadGroup != null) {
      // filter
      int fieldsToLoad = 0;
      EntityState entityState = getEntityState(ctx);
      for (int i = 0; i < tableFields.length; ++i) {
        JDBCCMPFieldBridge field = tableFields[i];
        if (loadGroup[i] && !field.isPrimaryKeyMember() && !field.isLoaded(ctx)) {
          entityState.setLoadRequired(i);
          ++fieldsToLoad;
        }
      }
      loadIter = (fieldsToLoad > 0 ? entityState.getLoadIterator(ctx) : EMPTY_FIELD_ITERATOR);
    } else {
      loadIter = EMPTY_FIELD_ITERATOR;
    }
    return loadIter;
  }
Esempio n. 6
0
 private boolean areCmpFieldsDirty(final CmpEntityBeanContext ctx, final EntityState entityState) {
   for (int i = 0; i < tableFields.length; ++i) {
     final JDBCCMPFieldBridge field = tableFields[i];
     if (entityState.isCheckDirty(i) && field.isDirty(ctx)) {
       return true;
     }
   }
   return false;
 }
 // Tests a schedulable entity's lifecycle : Submit -> run -> suspend -> resume
 @Test
 public void testLifeCycle() throws Exception {
   Process mockEntity = new Process();
   mockEntity.setName("test");
   storeEntity(EntityType.PROCESS, "test");
   StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUBMIT, listener);
   EntityState entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next();
   Mockito.verify(listener).onSubmit(mockEntity);
   Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUBMITTED));
   StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SCHEDULE, listener);
   Mockito.verify(listener).onSchedule(mockEntity);
   entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next();
   Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED));
   StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUSPEND, listener);
   Mockito.verify(listener).onSuspend(mockEntity);
   entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next();
   Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUSPENDED));
   StateService.get().handleStateChange(mockEntity, EntityState.EVENT.RESUME, listener);
   Mockito.verify(listener).onResume(mockEntity);
   entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next();
   Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED));
 }