Beispiel #1
0
  /** Test method for . */
  @Test
  public void testMultiVersionStorage() {
    try {
      Transaction createFirstVersion =
          new Transaction(jessy) {

            @Override
            public ExecutionHistory execute() {
              SampleEntityClass sampleEntity = new SampleEntityClass("1", "ver1");
              write(sampleEntity);
              return commitTransaction();
            }
          };

      Transaction createSecondVersion =
          new Transaction(jessy) {

            @Override
            public ExecutionHistory execute() {

              SampleEntityClass sampleEntity;
              try {
                sampleEntity = read(SampleEntityClass.class, "1");
                sampleEntity.setData("ver2");
                write(sampleEntity);
              } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              return commitTransaction();
            }
          };

      Transaction readTrans =
          new Transaction(jessy) {

            @Override
            public ExecutionHistory execute() {

              SampleEntityClass sampleEntity;
              try {
                sampleEntity = read(SampleEntityClass.class, "1");
              } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              return commitTransaction();
            }
          };

      createFirstVersion.execute();
      createSecondVersion.execute();
      readTrans.execute();

      assertTrue(true);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 @Override
 public int deleteAll(Class<?> claxx) {
   acquireReference();
   try {
     SQLiteDatabase db = mHelper.getWritableDatabase();
     SQLStatement stmt = SQLBuilder.buildDeleteAllSql(claxx);
     int num = stmt.execDelete(db);
     // 删除关系映射
     final MapInfo mapTable = SQLBuilder.buildDelAllMappingSql(claxx);
     if (mapTable != null && !mapTable.isEmpty()) {
       Transaction.execute(
           db,
           new Worker<Boolean>() {
             @Override
             public Boolean doTransaction(SQLiteDatabase db) throws Exception {
               if (mapTable.delOldRelationSQL != null) {
                 for (SQLStatement st : mapTable.delOldRelationSQL) {
                   long rowId = st.execDelete(db);
                   if (Log.isPrint) {
                     Log.i(TAG, "Exec delete mapping success, nums: " + rowId);
                   }
                 }
               }
               return true;
             }
           });
     }
     return num;
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     releaseReference();
   }
   return SQLStatement.NONE;
 }
  @Override
  public boolean process(Transaction transaction) throws SQLException {

    boolean done = false;
    int tries = 0;
    Connection conn = getConnection();

    while (!done && tries <= MAXRETRIES) {

      try {

        logger.info("Starting transaction.");

        transaction.execute(conn);

        if (ORA_14906) {
          DemoHelper.ORA_14906(conn);
        }

        logger.info("Work done. Now going to commit!");
        conn.commit();
        conn.close();
        done = true;

      } catch (SQLRecoverableException e) {

        try {
          conn.close();
        } catch (Exception ex) {
        }
        LogicalTransactionId ltxid = ((OracleConnection) conn).getLogicalTransactionId();
        logger.info("transaction failed: ltxid is: " + byteArrayToHexString(ltxid.getBytes()));
        logger.info("Exception was: " + e.getMessage());

        Connection newconn = getConnection();
        setModule(newconn, moduleName);
        done = isLTxIdCommitted(ltxid, newconn);
        if (done) {
          logger.info("Failed transaction had already been committed.");
        } else {
          logger.info("Replay of transaction neccessary.");
          tries++;
          conn = newconn;
        }
      }
    }
    return true;
  }
 @Override
 public int delete(final Collection<?> collection) {
   acquireReference();
   try {
     if (!Checker.isEmpty(collection)) {
       EntityTable table = TableManager.getTable(collection.iterator().next());
       if (table.key != null) {
         SQLStatement stmt = SQLBuilder.buildDeleteSql(collection);
         return stmt.execDeleteCollection(
             mHelper.getWritableDatabase(), collection, mTableManager);
       } else {
         Integer size =
             Transaction.execute(
                 mHelper.getWritableDatabase(),
                 new Worker<Integer>() {
                   @Override
                   public Integer doTransaction(SQLiteDatabase db) throws Exception {
                     for (Object entity : collection) {
                       SQLBuilder.buildDeleteSql(entity)
                           .execDeleteWithMapping(db, entity, mTableManager);
                     }
                     if (Log.isPrint) {
                       Log.i(TAG, "Exec delete(no primarykey) :" + collection.size());
                     }
                     return collection.size();
                   }
                 });
         return size == null ? 0 : size;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     releaseReference();
   }
   return SQLStatement.NONE;
 }
  @SuppressWarnings("unchecked")
  public Object execute(Object... params) throws Exception {
    // TODO Auto-generated method stub
    String response = (String) params[0];
    Map<String, String> patternMap = (Map<String, String>) params[1];
    String ID = (String) params[2];

    p = Pattern.compile(patternMap.get("campusPattern"));
    Matcher m = p.matcher(response);
    String campus = "";
    if (m.find()) campus = m.group(1).trim();

    p = Pattern.compile(patternMap.get("institutionPattern"));
    m = p.matcher(response);
    String institution = "";
    if (m.find()) institution = m.group(1).trim();

    p = Pattern.compile(patternMap.get("namePattern"));
    m = p.matcher(response);
    String name = "";
    if (m.find()) name = m.group(1).trim();

    p = Pattern.compile(patternMap.get("majorPattern"));
    m = p.matcher(response);
    String major = "";
    if (m.find()) major = m.group(1).trim();

    p = Pattern.compile(patternMap.get("genderPattern"));
    m = p.matcher(response);
    String gender = "";
    if (m.find()) gender = m.group(1).trim();

    p = Pattern.compile(patternMap.get("bdayPattern"));
    m = p.matcher(response);
    String year = "";
    String month = "";
    String date = "";
    if (m.find()) {
      year = m.group(1).trim();
      month = m.group(2).trim();
      date = m.group(3).trim();
    }

    p = Pattern.compile(patternMap.get("telnumPattern"));
    m = p.matcher(response);
    String telnum = "";
    if (m.find()) telnum = m.group(1).trim();

    p = Pattern.compile(patternMap.get("emailPattern"));
    m = p.matcher(response);
    String email = "";
    if (m.find()) email = m.group(1).trim();

    Map<String, String> attributes = new HashMap<String, String>();

    attributes.put("campus", campus);
    attributes.put("institution", institution);
    attributes.put("name", name);
    attributes.put("major", major);
    attributes.put("gender", gender);
    attributes.put("year", year);
    attributes.put("month", month);
    attributes.put("date", date);
    attributes.put("telnum", telnum);
    attributes.put("email", email);

    System.out.println(attributes);
    transaction.execute(ID, attributes);

    return null;
  }
  @Override
  public void execute(List<Object> resultList) {

    super.execute(resultList);

    MapperDAGVertex currentSource = (MapperDAGVertex) edge.getSource();
    MapperDAGVertex currentTarget = (MapperDAGVertex) edge.getTarget();

    if (edge instanceof PrecedenceEdge) {
      WorkflowLogger.getLogger()
          .log(Level.INFO, "no involvement vertex corresponding to a schedule edge");
      return;
    }

    String ivertexID =
        "__involvement (" + currentSource.getName() + "," + currentTarget.getName() + ")";

    if (involvementTime > 0) {
      iVertex = new InvolvementVertex(ivertexID, implementation);
      implementation.getTimings().dedicate(iVertex);
      implementation.getMappings().dedicate(iVertex);

      implementation.addVertex(iVertex);
      iVertex.getTiming().setCost(involvementTime);

      if (isSender) {
        iVertex.setEffectiveOperator(step.getSender());
        ((TransferVertex) currentTarget).setInvolvementVertex(iVertex);
      } else {
        iVertex.setEffectiveOperator(step.getReceiver());
        ((TransferVertex) currentSource).setInvolvementVertex(iVertex);
      }

      if (isSender) {
        MapperDAGEdge newInEdge = (MapperDAGEdge) implementation.addEdge(currentSource, iVertex);
        newInEdge.setInit(edge.getInit().clone());
        newInEdge.getTiming().setCost(0);

        MapperDAGVertex receiverVertex = currentTarget;
        do {
          Set<MapperDAGVertex> succs = receiverVertex.getSuccessors(false).keySet();
          if (succs.isEmpty() && receiverVertex instanceof TransferVertex) {
            WorkflowLogger.getLogger()
                .log(Level.SEVERE, "Transfer has no successor: " + receiverVertex.getName());
          }

          for (MapperDAGVertex next : receiverVertex.getSuccessors(false).keySet()) {
            if (next != null) {
              receiverVertex = next;
            }
          }
        } while (receiverVertex instanceof TransferVertex);

        MapperDAGEdge newoutEdge = (MapperDAGEdge) implementation.addEdge(iVertex, receiverVertex);
        newoutEdge.setInit(edge.getInit().clone());
        newoutEdge.getTiming().setCost(0);

        // TODO: Look at switching possibilities
        /*
         * if (false) { TaskSwitcher taskSwitcher = new TaskSwitcher();
         * taskSwitcher.setOrderManager(orderManager);
         * taskSwitcher.insertVertexBefore(currentTarget, iVertex); }
         * else
         */
        orderManager.insertBefore(currentTarget, iVertex);

      } else {
        MapperDAGEdge newOutEdge = (MapperDAGEdge) implementation.addEdge(iVertex, currentTarget);
        newOutEdge.setInit(edge.getInit().clone());
        newOutEdge.getTiming().setCost(0);

        orderManager.insertAfter(currentSource, iVertex);
      }

      // Scheduling involvement vertex
      new PrecedenceEdgeAdder(orderManager, implementation).scheduleVertex(iVertex);

      if (resultList != null) {
        resultList.add(iVertex);
      }
    }
  }