Package org.persvr.data

Examples of org.persvr.data.Transaction$ImmediateTransaction


      }
    }
  }
  @Override
  synchronized public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    Transaction previousTransaction = Transaction.currentTransaction();
    int pathsCount = (int) pathsArray.getLength();
    File jslibFile = null;
    String filename;
    String oldJsLibPath = currentJslibPath;
    ScriptableObject exportObject;
    try {
      if(args[0] instanceof File){
        jslibFile = (File) args[0];
        filename = jslibFile.getCanonicalPath();
        filename = filename.replace(File.separatorChar, '/');
        for(int i = 0; i < pathsCount; i++){
          String path = pathsArray.get(i, pathsArray).toString();
          path = new File(path).getCanonicalPath().replace(File.separatorChar, '/');
          if(path.length() > 0 && !(path.endsWith("/") || path.endsWith(File.separator)))
            path += '/';
          if(filename.indexOf(path) > -1){
            filename = filename.substring(filename.indexOf(path) + path.length());
            break;
          }
        }
      }
      else {
        filename = args[0].toString();
        if(filename.startsWith("."))
          filename = currentJslibPath + filename;
        filename = Pattern.compile("[^\\/]*\\/\\.\\.\\/").matcher(filename).replaceAll("");
        filename = filename.replace("./", "");
        for(int i = 0; i < pathsCount; i++){
          String path = pathsArray.get(i, pathsArray).toString();
          if(path.length() > 0 && !(path.endsWith("/") || path.endsWith(File.separator)))
            path += '/';
          jslibFile = new File(path + filename);
          if(jslibFile.isFile())
            break;
          if(!filename.endsWith(".js")){
            filename += ".js";
            jslibFile = new File(path + filename);
            if(jslibFile.isFile())
              break;
          }
        }
      }
      String id = filename;
      if (filename.endsWith(".js"))
        id = filename.substring(0, filename.length() - 3);
      if(jslibFile == null || !jslibFile.isFile())
        throw ScriptRuntime.constructError("Error", "File not found " + filename);
      exportObject = exports.get(jslibFile);
      Long lastTimeStamp = lastTimeStamps.get(jslibFile);
      if(lastTimeStamp == null || lastTimeStamp < jslibFile.lastModified()){
        Transaction.startTransaction();
        lastTimeStamps.put(jslibFile, jslibFile.lastModified());
        FileInputStream inStream = new FileInputStream(jslibFile);
        exportObject = new NativeObject();
        ScriptRuntime.setObjectProtoAndParent((ScriptableObject) exportObject, global);
        ScriptableObject moduleObject = new NativeObject();
        ScriptRuntime.setObjectProtoAndParent((ScriptableObject) moduleObject, global);
        moduleObject.put("id", moduleObject, id);
        // setup the module scope
        ScriptableObject moduleScope = new NativeObject();
        moduleScope.setParentScope(global);
        int lastSlash = filename.lastIndexOf('/');
        currentJslibPath = lastSlash == -1 ? "" : filename.substring(0,lastSlash + 1);
        moduleScope.put("exports", moduleScope, exportObject);
        moduleScope.put("module", moduleScope, moduleObject);
        // memoize
        exports.put(jslibFile, exportObject);
        // evaluate the script
        try {
          cx.evaluateString(moduleScope, IOUtils.toString(inStream, "UTF-8"), filename, 1, null);
        } catch (RuntimeException e) {
          // revert
          exports.remove(jslibFile);
          throw e;
        }
        // re-retrieve it in case the library changed it
        exportObject = (ScriptableObject) moduleScope.get("exports", moduleScope);
        exports.put(jslibFile, exportObject);

        if("jsgi-app.js".equals(filename)){
          // handle jackconfig.js, setting up the app if it is there
          global.put("app", global, exportObject.get("app", exportObject));
        }
        // freeze it
        //exportObject.sealObject();
        Transaction.currentTransaction().commit();
      }
    } catch (IOException e) {
      throw ScriptRuntime.constructError("Error",e.getMessage());
    }
    finally{
      currentJslibPath = oldJsLibPath;
      previousTransaction.enterTransaction();
    }
    return exportObject;
  }
View Full Code Here


public class SampleData implements Job {

  public void execute() {
    try {
      List customers = (List) Persevere.load("Customer/");
      Transaction transaction = Transaction.startTransaction();
      if(customers.size() == 0){
        Persistable customer1 = Persevere.newObject("Customer");
        customer1.set("firstName", "John");
        customer1.set("lastName", "Doe");
        customer1.set("age", 41);
        Persistable customer2 = Persevere.newObject("Customer");
        customer2.set("firstName", "Jim");
        customer2.set("lastName", "Jones");
        customer2.set("age", 33);
      }
      transaction.commit();
    }
    catch (ObjectNotFoundException e){
     
    }
  }
View Full Code Here

      public Object call(final Context cx, final Scriptable scope,
          final Scriptable thisObj, Object[] args) {
        Capability capability = ((Capability)args[0]);
        capability.allGranted = null;
        capability.computedPermissions.clear();
        Transaction currentTransaction = Transaction.suspendTransaction();
        List<Object> oldMembers = new ArrayList(capability.getAllMembers());
        if(currentTransaction!=null) currentTransaction.enterTransaction();
        List<Object> newMembers = args.length == 1 ?
            new ArrayList(capability.getAllMembers()) :
              new ArrayList();
        oldMembers.removeAll(newMembers);
        for (Object member : oldMembers){
View Full Code Here

    transactions.remove(transactionId);
    markTransactionProcessed(transactionId);
  }
 
  public synchronized void startOrEnterTransaction(Long sequenceId, Long transactionId){
    Transaction existingTransaction = transactions.get(transactionId);
    if(existingTransaction!=null){
      existingTransaction.enterTransaction(sequenceId);
    }else{
      transactions.put(transactionId, Transaction.startTransaction(sequenceId, transactionId));
    }
  }
View Full Code Here

  }
 
 
  static Map<Transaction, Long> commitedTransactions = Collections.synchronizedMap(new WeakHashMap<Transaction, Long>());
  public void commitTransaction() throws Exception {
    Transaction currentTransaction = Transaction.currentTransaction();
    Long transactionTime = new Long(currentTransaction.getTransactionTime().getTime());
    // we just need to call database commitTransaction once for a given transaction
    if(!transactionTime.equals(commitedTransactions.get(currentTransaction))){
      commitedTransactions.put(currentTransaction, transactionTime);
      getDatabase().commitTransaction();
    }
View Full Code Here

TOP

Related Classes of org.persvr.data.Transaction$ImmediateTransaction

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.