PageRenderTime 28ms CodeModel.GetById 24ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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