当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.isActive方法代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.Transaction.isActive方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.isActive方法的具体用法?Java Transaction.isActive怎么用?Java Transaction.isActive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.datastore.Transaction的用法示例。


在下文中一共展示了Transaction.isActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteSessionVariables

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Delete a value stored in the project's datastore.
 * @param sessionId Request from which the session is extracted.
 */
protected void deleteSessionVariables(String sessionId, String... varNames) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = KeyFactory.createKey(SESSION_KIND, sessionId);
  Transaction transaction = datastore.beginTransaction();
  try {
    Entity stateEntity = datastore.get(transaction, key);
    for (String varName : varNames) {
      stateEntity.removeProperty(varName);
    }
    datastore.put(transaction, stateEntity);
    transaction.commit();
  } catch (EntityNotFoundException e) {
    // Ignore - if there's no session, there's nothing to delete.
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:DatastoreSessionFilter.java

示例2: deleteSessionWithValue

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
protected void deleteSessionWithValue(String varName, String varValue) {
  Transaction transaction = datastore.beginTransaction();
  try {
    Query query = new Query(SESSION_KIND)
        .setFilter(new FilterPredicate(varName, FilterOperator.EQUAL, varValue));
    Iterator<Entity> results = datastore.prepare(transaction, query).asIterator();
    while (results.hasNext()) {
      Entity stateEntity = results.next();
      datastore.delete(transaction, stateEntity.getKey());
    }
    transaction.commit();
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:18,代码来源:DatastoreSessionFilter.java

示例3: storeTask

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
@ApiMethod(name = "storeTask")
public void storeTask(TaskBean taskBean) {
    DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
    Transaction txn = datastoreService.beginTransaction();
    try {
        Key taskBeanParentKey = KeyFactory.createKey("TaskBeanParent", "todo.txt");
        Entity taskEntity = new Entity("TaskBean", taskBean.getId(), taskBeanParentKey);
        taskEntity.setProperty("data", taskBean.getData());
        datastoreService.put(taskEntity);
        txn.commit();
    } finally {
        if (txn.isActive()) {
            txn.rollback();
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:17,代码来源:MyEndpoint.java

示例4: clearTasks

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
@ApiMethod(name = "clearTasks")
public void clearTasks() {
    DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
    Transaction txn = datastoreService.beginTransaction();
    try {
        Key taskBeanParentKey = KeyFactory.createKey("TaskBeanParent", "todo.txt");
        Query query = new Query(taskBeanParentKey);
        List<Entity> results = datastoreService.prepare(query).asList(FetchOptions.Builder.withDefaults());
        for (Entity result : results) {
            datastoreService.delete(result.getKey());
        }
        txn.commit();
    } finally {
        if (txn.isActive()) {
            txn.rollback();
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:19,代码来源:MyEndpoint.java

示例5: deleteObject

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
@Override
public boolean deleteObject(GcsFilename filename, long timeoutMillis) throws IOException {
  ensureInitialized();
  Transaction tx = datastore.beginTransaction();
  Key key = makeKey(filename);
  try {
    datastore.get(tx, key);
    datastore.delete(tx, key);
    blobstoreService.delete(getBlobKeyForFilename(filename));
  } catch (EntityNotFoundException ex) {
    return false;
  } finally {
    if (tx.isActive()) {
      tx.commit();
    }
  }

  return true;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:20,代码来源:LocalRawGcsService.java

示例6: getDevices

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Gets all registered devices.
 */
public static List<String> getDevices() {
    List<String> devices;
    Transaction txn = ds.beginTransaction();
    try {
        Query query = new Query(DEVICE_TYPE);
        Iterable<Entity> entities =
                ds.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;
}
 
开发者ID:amardeshbd,项目名称:google-iosched,代码行数:24,代码来源:Datastore.java

示例7: updateRegistration

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * 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();
    }
  }
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:22,代码来源:Datastore.java

示例8: getTotalDevices

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Gets the number of total devices.
 */
public static int getTotalDevices() {
  Transaction txn = datastore.beginTransaction();
  try {
    Query query = new Query(DEVICE_TYPE).setKeysOnly();
    List<Entity> allKeys =
        datastore.prepare(query).asList(DEFAULT_FETCH_OPTIONS);
    int total = allKeys.size();
    logger.fine("Total number of devices: " + total);
    txn.commit();
    return total;
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:20,代码来源:Datastore.java

示例9: createMulticast

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Creates a persistent record with the devices to be notified using a
 * multicast message.
 *
 * @param devices registration ids of the devices.
 * @return encoded key for the persistent record.
 */
public static String createMulticast(List<String> devices) {
  logger.info("Storing multicast for " + devices.size() + " devices");
  String encodedKey;
  Transaction txn = datastore.beginTransaction();
  try {
    Entity entity = new Entity(MULTICAST_TYPE);
    entity.setProperty(MULTICAST_REG_IDS_PROPERTY, devices);
    datastore.put(entity);
    Key key = entity.getKey();
    encodedKey = KeyFactory.keyToString(key);
    logger.fine("multicast key: " + encodedKey);
    txn.commit();
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
  return encodedKey;
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:27,代码来源:Datastore.java

示例10: getMulticast

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Gets a persistent record with the devices to be notified using a
 * multicast message.
 *
 * @param encodedKey encoded key for the persistent record.
 */
public static List<String> getMulticast(String encodedKey) {
  Key key = KeyFactory.stringToKey(encodedKey);
  Entity entity;
  Transaction txn = datastore.beginTransaction();
  try {
    entity = datastore.get(key);
    @SuppressWarnings("unchecked")
    List<String> devices =
        (List<String>) entity.getProperty(MULTICAST_REG_IDS_PROPERTY);
    txn.commit();
    return devices;
  } catch (EntityNotFoundException e) {
    logger.severe("No entity for key " + key);
    return Collections.emptyList();
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:27,代码来源:Datastore.java

示例11: getMulticast

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Gets a persistent record with the devices to be notified using a multicast message.
 *
 * @param encodedKey encoded key for the persistent record.
 */
public static Entity getMulticast(String encodedKey) {
    Key key = KeyFactory.stringToKey(encodedKey);
    Entity entity;
    Transaction txn = ds.beginTransaction();
    try {
        entity = ds.get(key);
        txn.commit();
        return entity;
    } catch (EntityNotFoundException e) {
        logger.severe("No entity for key " + key);
        return null;
    } finally {
        if (txn.isActive()) {
            txn.rollback();
        }
    }
}
 
开发者ID:amardeshbd,项目名称:google-iosched,代码行数:23,代码来源:Datastore.java

示例12: unregister

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Unregisters a device.
 */
public static void unregister(String regId) {
    logger.info("Unregistering " + regId);
    Transaction txn = ds.beginTransaction();
    try {
        Entity entity = findDeviceByRegId(regId);
        if (entity == null) {
            logger.warning("Device " + regId + " already unregistered");
        } else {
            Key key = entity.getKey();
            ds.delete(key);
        }
        txn.commit();
    } finally {
        if (txn.isActive()) {
            txn.rollback();
        }
    }
}
 
开发者ID:amardeshbd,项目名称:google-iosched,代码行数:22,代码来源:Datastore.java

示例13: deleteEntity

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
@Override
public T deleteEntity(T demoEntity) {
  Utils.assertTrue(demoEntity != null, "entity cannot be null");
  DemoEntityNoSql entityNoSql = downCastEntity(demoEntity);
  DatastoreService ds = getDatastoreService();
  Transaction txn = ds.beginTransaction();
  try {
    if (checkEntityForDelete(ds, entityNoSql)) {
      ds.delete(entityNoSql.getEntity().getKey());
      txn.commit();
      logger.info("entity deleted.");
      return demoEntity;
    }
  } catch (Exception e) {
    logger.severe("Failed to delete entity from datastore:" + e.getMessage());
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
  return null;
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-photo-sharing-demo-java,代码行数:23,代码来源:DemoEntityManagerNoSql.java

示例14: unregister

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
/**
 * Unregisters a device.
 *
 * @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();
    }
  }
}
 
开发者ID:narusemotoki,项目名称:mbfix-gcm,代码行数:24,代码来源:Datastore.java

示例15: run

import com.google.appengine.api.datastore.Transaction; //导入方法依赖的package包/类
@Override
public void run() {

    DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
    Transaction transaction = datastoreService.beginTransaction();

    Key attendeeKey = KeyFactory.createKey("Attendee", event.getAttendeeId().toString());
    Entity attendee = null;

    try {
        attendee = datastoreService.get(attendeeKey);
        attendee.setProperty("FirstName", event.getFirstName());
        attendee.setProperty("LastName", event.getLastName());
        datastoreService.put(attendee);
        transaction.commit();

    } catch (EntityNotFoundException e) {
        MessageLog.log(e);
    } finally {
        if(transaction != null && transaction.isActive())
            transaction.rollback();
    }
}
 
开发者ID:dannormington,项目名称:appengine-cqrs,代码行数:24,代码来源:AttendeeNameChangedEventHandler.java


注:本文中的com.google.appengine.api.datastore.Transaction.isActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。