summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
commitaedc34d55462a75e329bbf342251ff6504cd117e (patch)
treebcc8f1f2352582717b484df302aeea6696b8f000 /projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java
Initial import from SVN
Diffstat (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java')
-rw-r--r--projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java
new file mode 100644
index 0000000..1d36bef
--- /dev/null
+++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/TestDataSource.java
@@ -0,0 +1,115 @@
+package net.wotonomy.test;
+
+import net.wotonomy.control.EOClassDescription;
+import net.wotonomy.control.EODataSource;
+import net.wotonomy.control.EOEditingContext;
+import net.wotonomy.control.EOFetchSpecification;
+import net.wotonomy.foundation.NSArray;
+
+/**
+* A custom DataSource that works with
+* the datastore package for persistence.
+*/
+public class TestDataSource extends EODataSource
+{
+ private EOEditingContext context;
+ private Object source;
+ private String key;
+
+ public TestDataSource()
+ {
+ this( Test.editingContext );
+ }
+
+ public TestDataSource( EOEditingContext aContext )
+ {
+ context = aContext;
+ }
+
+ public EOEditingContext editingContext()
+ {
+ return context;
+ }
+
+ /**
+ * This implementation does nothing.
+ */
+ public void insertObject ( Object anObject )
+ {
+ // creates are handled by createObject().
+ }
+
+ /**
+ * Deletes the specified object from this data source.
+ */
+ public void deleteObject ( Object anObject )
+ {
+ editingContext().deleteObject( anObject );
+ }
+
+ /**
+ * Returns a List containing the objects in this
+ * data source. This implementation returns all
+ * TestObjects that have been persisted to the
+ * datastore in the data directory.
+ */
+ public NSArray fetchObjects ()
+ {
+ if ( source == null )
+ {
+ NSArray result = editingContext().objectsWithFetchSpecification(
+ new EOFetchSpecification() );
+ if ( result.size() > 0 )
+ {
+ result = new NSArray( result.objectAtIndex( 0 ) );
+//result.add( result.objectAtIndex( 0 ) );
+ }
+ return result;
+ }
+ else
+ {
+ return new NSArray(
+ ((TestObject)source).getChildList() );
+ }
+ }
+
+ /**
+ * Returns a data source that is capable of
+ * manipulating objects of the type returned by
+ * applying the specified key to objects
+ * vended by this data source.
+ * @see #qualifyWithRelationshipKey
+ */
+ public EODataSource
+ dataSourceQualifiedByKey ( String aKey )
+ {
+ return new TestDataSource( editingContext() );
+ }
+
+ /**
+ * Restricts this data source to vend those
+ * objects that are associated with the specified
+ * key on the specified object.
+ */
+ public void
+ qualifyWithRelationshipKey (
+ String aKey, Object anObject )
+ {
+ key = aKey;
+ source = anObject;
+ }
+
+ /**
+ * Returns the description of the class of the
+ * objects that is vended by this data source,
+ * or null if this cannot be determined.
+ * This implementation returns TestObject.
+ */
+ public EOClassDescription
+ classDescriptionForObjects ()
+ {
+ return EOClassDescription.classDescriptionForClass(
+ TestObject.class );
+ }
+
+}