/src/com/google/appengine/datanucleus/BatchDeleteManager.java

http://datanucleus-appengine.googlecode.com/ · Java · 62 lines · 32 code · 10 blank · 20 comment · 3 complexity · 019d3dc853d7a92060e9eb0e541aa71c MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2009 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus;
  14. import com.google.appengine.api.datastore.Key;
  15. import java.util.List;
  16. import org.datanucleus.ExecutionContext;
  17. /**
  18. * Manages batch deletes that are initiated via standard JDO calls.
  19. *
  20. * @author Max Ross <maxr@google.com>
  21. */
  22. public class BatchDeleteManager extends BatchManager<BatchDeleteManager.BatchDeleteState> {
  23. ExecutionContext ec;
  24. static final class BatchDeleteState {
  25. private final DatastoreTransaction txn;
  26. private final Key key;
  27. BatchDeleteState(DatastoreTransaction txn, Key key) {
  28. this.txn = txn;
  29. this.key = key;
  30. }
  31. }
  32. public BatchDeleteManager(ExecutionContext ec) {
  33. this.ec = ec;
  34. }
  35. String getOperation() {
  36. return "delete";
  37. }
  38. void processBatchState(DatastorePersistenceHandler handler, List<BatchDeleteState> batchDeleteStateList) {
  39. DatastoreTransaction txn = batchDeleteStateList.get(0).txn;
  40. List<Key> keyList = Utils.newArrayList();
  41. for (BatchDeleteState bds : batchDeleteStateList) {
  42. if (bds.txn != txn) {
  43. throw new IllegalStateException("Batch delete cannot involve multiple txns.");
  44. }
  45. keyList.add(bds.key);
  46. }
  47. EntityUtils.deleteEntitiesFromDatastore(ec, keyList);
  48. }
  49. }