Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.Transaction


          StringBuffer itb = new StringBuffer( "jiqlAutoIncrementInt_").append(sqp.getTable());

            JGNameValuePairs o = JIQLGDataUtil.getWhereEqual(itb.toString(),"tablefield",f);
   
 
        Transaction trans = null;

        try{


        //(f + " getAutoIncrementInt " + o);
        if (o != null)
        {
        ct = o.getInt("incrementvalue") + 1;
        Hashtable h = null;
        while (true){
          h = readTableValueWhereEqual(sqp,sqp.getTable(),f,new Integer(ct));
          if (h == null || h.size() < 1)
            break;
        ct = ct + 1;
   
        }
        Hashtable hash = new Hashtable();
        hash.put("tablefield",f);
        hash.put("incrementvalue",ct);
//trans = JIQLGDataUtil.getTransaction();
          JIQLGDataUtil.update(itb.toString(),hash,o.getKeyId());
//trans.commit();
        }
        else{
          ct = ct + 1;
        Hashtable hash = new Hashtable();
        hash.put("tablefield",f);
        hash.put("incrementvalue",ct);

        JIQLGDataUtil.put(itb.toString(),hash;
         
        }

        //trans.commit();
        }catch (Exception e){
          if (trans != null)
          trans.rollback();
          e.printStackTrace();
          ///(e);
          throw new SQLException(e.toString());
        }
 
View Full Code Here


        try{
          removeTableInfo(t,null);
        }
        catch (Exception rx){
       
        Transaction trans = JIQLGDataUtil.getTransaction();

        try{
       
        removeTableInfo(t,trans);
        trans.commit();
        }catch (Exception e){
          trans.rollback();
          throw new SQLException(e.toString());
        }     

        }
        StringBuffer itb = new StringBuffer( "jiqlAutoIncrementInt_").append(t);
View Full Code Here

    if (!sqp.getConnection().getAutoCommit()){
      try{
     
      //(" WRUIT TAB ROW ? " + hash);
            DatastoreService datastore = JIQLGDataUtil.getDatastoreService();
           Transaction trans = datastore.beginTransaction();
           sqp.getConnection().setTransaction(trans);
           rid = JIQLGDataUtil.put(tn,hash,pk,datastore,trans);
      }finally{
        return ;
      }
View Full Code Here

    }

    @Test
    public void shouldWorkInsideRunningTransaction() {
        update("F1", false, null, null, null);
        final Transaction txn = datastoreService.beginTransaction();
        update("F3", false, null, null, txn);
        repository.getFeatureState(TestFeature.F1);
        txn.commit();
    }
View Full Code Here

    /**
     * @param featureEntity
     */
    protected void putInsideTransaction(final Entity featureEntity) {
        final Transaction txn = this.datastoreService.beginTransaction();
        try {
            this.datastoreService.put(txn, featureEntity);
            txn.commit();
        } finally {
            if (txn.isActive()) {
                txn.rollback();
            }
        }
    }
View Full Code Here

     * @param key
     * @return
     * @throws EntityNotFoundException
     */
    protected Entity getInsideTransaction(final Key key) throws EntityNotFoundException {
        final Transaction txn = this.datastoreService.beginTransaction();
        Entity featureEntity;
        try {
            featureEntity = this.datastoreService.get(txn, key);
            txn.commit();
        } finally {
            if (txn.isActive()) {
                txn.rollback();
            }
        }
        return featureEntity;
    }
View Full Code Here

   *
   * @param regId device's registration id.
   */
  public static void register(String regId) {
    logger.info("Registering " + regId);
    Transaction txn = datastore.beginTransaction();
    try {
      Entity entity = findDeviceByRegId(regId);
      if (entity != null) {
        logger.fine(regId + " is already registered; ignoring.");
        return;
      }
      entity = new Entity(DEVICE_TYPE);
      entity.setProperty(DEVICE_REG_ID_PROPERTY, regId);
      datastore.put(entity);
      txn.commit();
    } finally {
      if (txn.isActive()) {
        txn.rollback();
      }
    }
  }
View Full Code Here

   *
   * @param regId device's registration id.
   */
  public static void unregister(String regId) {
    logger.info("Unregistering " + regId);
    Transaction txn = datastore.beginTransaction();
    try {
      Entity entity = findDeviceByRegId(regId);
      if (entity == null) {
        logger.warning("Device " + regId + " already unregistered");
      } else {
        Key key = entity.getKey();
        datastore.delete(key);
      }
      txn.commit();
    } finally {
      if (txn.isActive()) {
        txn.rollback();
      }
    }
  }
View Full Code Here

  /**
   * Updates the registration id of a device.
   */
  public static void updateRegistration(String oldId, String newId) {
    logger.info("Updating " + oldId + " to " + newId);
    Transaction txn = datastore.beginTransaction();
    try {
      Entity entity = findDeviceByRegId(oldId);
      if (entity == null) {
        logger.warning("No device for registration id " + oldId);
        return;
      }
      entity.setProperty(DEVICE_REG_ID_PROPERTY, newId);
      datastore.put(entity);
      txn.commit();
    } finally {
      if (txn.isActive()) {
        txn.rollback();
      }
    }
  }
View Full Code Here

  /**
   * Gets all registered devices.
   */
  public static List<String> getDevices() {
    List<String> devices;
    Transaction txn = datastore.beginTransaction();
    try {
      Query query = new Query(DEVICE_TYPE);
      Iterable<Entity> entities =
          datastore.prepare(query).asIterable(DEFAULT_FETCH_OPTIONS);
      devices = new ArrayList<String>();
      for (Entity entity : entities) {
        String device = (String) entity.getProperty(DEVICE_REG_ID_PROPERTY);
        devices.add(device);
      }
      txn.commit();
    } finally {
      if (txn.isActive()) {
        txn.rollback();
      }
    }
    return devices;
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.Transaction

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.