Package org.persvr.datasource

Examples of org.persvr.datasource.WritableDataSource


        sourceValue = convertToDateJavaDate(sourceValue);
      Identification id = target.getId();
      if (id instanceof ObjectId && id.source != null) { // it should always be persisted right?
        if (change.key != null) {
          DataSource initialSource = id.source;
          WritableDataSource source;
          String subObjectId = id.subObjectId;
          if (subObjectId == null) {
            subObjectId = initialSource.getId();
            source = DataSourceManager.metaClassSource;
          }
          else {
            source = (WritableDataSource) initialSource;
          }
          Transaction.addAffectedSource(source);
          String key =change.key;

          if (hadProperty) {
            if (value == Scriptable.NOT_FOUND)
              source.recordPropertyRemoval(subObjectId, key);
            else
              source.recordPropertyChange(subObjectId, key, sourceValue, getAttributes(target, key));

          }
          else {

            source.recordPropertyAddition(subObjectId, key, sourceValue, getAttributes(target, key));
          }
        }
        else {
          Transaction.addAffectedSource((WritableDataSource)id.source);
          if (sourceValue == Scriptable.NOT_FOUND) {
View Full Code Here


        // now write all the data to the datasources
        if(writeToDataSource){
          for (WritableDataSource source : dataSourcesAffected)
            source.startTransaction();
          for (NewObject newObject : newObjects) {
            WritableDataSource source = ((WritableDataSource) DataSourceManager.getSourceByPrototype((Persistable)newObject.object.getPrototype()));
            addAffectedSource(source);
            NewObjectPersister persister = source.recordNewObject(newObject.object);
            newObject.object.getId().persistIfNeeded(persister);
            if(newObject.object instanceof PersistableObject)
              ((PersistableObject)newObject.object).lastModified = Transaction.currentTransaction().getTransactionTime();
            else
              ((PersistableArray)newObject.object).lastModified = Transaction.currentTransaction().getTransactionTime();
 
          }
          for (Entry<TransactionValue,ChangeUpdate> changeEntry : changes.entrySet()) {
            PersistableObject.commitPut(changeEntry,this);
          }
          for (WritableDataSource source : dataSourcesAffected)
            source.commitTransaction();
        }
        // now make all the changes committed in the persisted objects so will
        // be available to other threads
        // TODO: Needs to be timestamp based in order be atomic
        synchronized(commitsInProcess){
          for (Entry<TransactionValue,ChangeUpdate> changeEntry : changes.entrySet()) {
            TransactionValue transValue = changeEntry.getKey();
            ChangeUpdate change = changeEntry.getValue();
            Persistable target = change.target;
            Object sourceValue = transValue.values.get(this);
 
            if (target instanceof PersistableObject) {
              ((PersistableObject) target).lastModified = getTransactionTime();
              if (transValue.commit(this)) {
                if (change.key != null){
                  if(sourceValue instanceof Persistable && !(((Persistable)sourceValue).getId() instanceof NewObjectId))
                    sourceValue = ((Persistable)sourceValue).getId();
                  ((PersistableObject) target).noCheckSet((String) change.key, sourceValue);
                }
              }
            }
            else if (target instanceof PersistableArray) {
              ((PersistableArray) target).lastModified = getTransactionTime();
              if (change.key == null) {
                transValue.values.remove(this);
                // update the core Array with the transactional Array
                int i = 0;
                for (Object value : (PersistableArray) sourceValue){
                  if(value instanceof Persistable && !(((Persistable)value).getId() instanceof NewObjectId))
                    value = ((Persistable)value).getId();
                  ((PersistableArray) target).noCheckSet(i++,value);
                }
                ((PersistableArray) target).superPutLength(i);
              }
              //TODO: When a new value is added an array, we want to increment the other waiting transaction values indexes
            }
          }
 
          commitsInProcess.remove(this);
        }
      }
      catch (Exception e) {
        // it failed, rollback
        for (TransactionValue value : changes.keySet()) {
          value.abort(this);
        }
        for (WritableDataSource source : dataSourcesAffected)
          try {
            source.abortTransaction();
          } catch (Exception e1) {
            e1.printStackTrace();
          }
       
        observedCallSet.clear();
View Full Code Here

TOP

Related Classes of org.persvr.datasource.WritableDataSource

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.