summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java')
-rw-r--r--sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java b/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java
new file mode 100644
index 0000000000..26f86cb1e9
--- /dev/null
+++ b/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/DataAccessService.java
@@ -0,0 +1,83 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agfa.hap.sdo;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import com.agfa.hap.sdo.implementation.SnapshotImplementation;
+import com.agfa.hap.sdo.mapper.PartialDataObjectMapper;
+
+public class DataAccessService {
+ private final static PartialDataObjectMapper MAPPER = new PartialDataObjectMapper();
+ public static Snapshot createSnapShot(SnapshotDefinition def, PartialDataObject root) {
+ return createSnapShot(MAPPER, def, root);
+ }
+
+ public static <T> Snapshot createSnapShot(DataMapper<T> mapper, SnapshotDefinition def, T root) {
+ List<T> roots = new ArrayList<T>(1);
+ roots.add(root);
+ return new SnapshotImplementation(mapper, def, roots);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Snapshot createMultiSnapShot(SnapshotDefinition def, Collection<? extends T> root) {
+ return createMultiSnapShot((DataMapper<T>) MAPPER, def, root);
+ }
+
+ public static <T> Snapshot createMultiSnapShot(DataMapper<T> mapper, SnapshotDefinition def, Collection<? extends T> root) {
+ return new SnapshotImplementation(mapper, def, root);
+ }
+
+ public static PartialDataObject getRootObject(Snapshot s) {
+ return getRootObject(MAPPER, s);
+ }
+
+ /**
+ * @return The first and only root object of the snapshot. This is always a different
+ * instance than the object that was used to create the snapshot.
+ * @throws RuntimeException if there are no root objects or if there is more than one root object
+ */
+ public static <T> T getRootObject(DataMapper<T> mapper, Snapshot s) {
+ List<T> roots = getRootObjects(mapper, s);
+ if (roots.isEmpty()){
+ throw new RuntimeException("snapshot is empty");
+ }
+ if (roots.size() > 1){
+ throw new RuntimeException("more than 1 rootobject:" + roots.size());
+ }
+ return roots.get(0);
+ }
+
+ public static List<PartialDataObject> getRootObjects(Snapshot s) {
+ return getRootObjects(MAPPER, s);
+ }
+
+ public static <T> List<T> getRootObjects(DataMapper<T> mapper, Snapshot s) {
+ return s.extract(mapper);
+ }
+
+ public static <T> Iterator<T> rootObjectsIterator(DataMapper<T> mapper, Snapshot s) {
+ return getRootObjects(mapper, s).iterator();
+ }
+
+}