summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-05-20 17:58:16 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-05-20 17:58:16 -0400
commit40a9d99496e098562f090fb7ffce9e749011b131 (patch)
tree437df24d65470582e943e494a52db8ed65a881ae /projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java
parentff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff)
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java')
-rw-r--r--projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java131
1 files changed, 67 insertions, 64 deletions
diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java
index 46fc8d0..9c77d45 100644
--- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java
+++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java
@@ -31,18 +31,18 @@ import net.wotonomy.foundation.NSMutableDictionary;
import net.wotonomy.foundation.NSPropertyListSerialization;
/**
-* An EOModel is a set of entities and stored procedures, along with a connection
-* dictionary to connect to a database.
-*
-* @author ezamudio@nasoft.com
-* @author $Author: cgruber $
-* @version $Revision: 894 $
-*/
+ * An EOModel is a set of entities and stored procedures, along with a
+ * connection dictionary to connect to a database.
+ *
+ * @author ezamudio@nasoft.com
+ * @author $Author: cgruber $
+ * @version $Revision: 894 $
+ */
public class EOModel {
protected static final String IDX_NAME = "index.eomodeld";
- //This array contains dictionaries with "className" and "name"
+ // This array contains dictionaries with "className" and "name"
protected NSMutableArray _entities = new NSMutableArray();
protected NSMutableDictionary _entitiesByName = new NSMutableDictionary();
protected NSMutableDictionary _entitiesByClass = new NSMutableDictionary();
@@ -86,24 +86,25 @@ public class EOModel {
throw new IllegalArgumentException("Cannot read index.eomodeld");
}
NSDictionary d = NSPropertyListSerialization.dictionaryForString(x);
- String version = (String)d.objectForKey("EOModelVersion");
+ String version = (String) d.objectForKey("EOModelVersion");
if (version == null || !version.startsWith("2."))
throw new IllegalArgumentException("Invalid eomodel version: " + version);
- setAdaptorName((String)d.objectForKey("adaptorName"));
- setConnectionDictionary((NSDictionary)d.objectForKey("connectionDictionary"));
- _entities = ((NSArray)d.objectForKey("entities")).mutableClone();
+ setAdaptorName((String) d.objectForKey("adaptorName"));
+ setConnectionDictionary((NSDictionary) d.objectForKey("connectionDictionary"));
+ _entities = ((NSArray) d.objectForKey("entities")).mutableClone();
if (d.objectForKey("storedProcedures") != null)
- _storedProcedureNames.addObjectsFromArray((NSArray)d.objectForKey("storedProcedures"));
+ _storedProcedureNames.addObjectsFromArray((NSArray) d.objectForKey("storedProcedures"));
if (d.objectForKey("internalInfo") != null)
- _internalInfo = (NSDictionary)d.objectForKey("internalInfo");
+ _internalInfo = (NSDictionary) d.objectForKey("internalInfo");
if (d.objectForKey("userInfo") != null)
- _userInfo = (NSDictionary)d.objectForKey("userInfo");
+ _userInfo = (NSDictionary) d.objectForKey("userInfo");
entityNamed("EOPrototypes");
}
public void setConnectionDictionary(NSDictionary dict) {
_connectionDictionary = dict;
}
+
public NSDictionary connectionDictionary() {
return _connectionDictionary;
}
@@ -130,10 +131,10 @@ public class EOModel {
}
public EOStoredProcedure storedProcedureNamed(String name) {
- EOStoredProcedure proc = (EOStoredProcedure)_storedProcedures.objectForKey(name);
- //if we can't find it, check if we should load it
+ EOStoredProcedure proc = (EOStoredProcedure) _storedProcedures.objectForKey(name);
+ // if we can't find it, check if we should load it
if (proc == null && _path != null && _storedProcedureNames.containsObject(name)) {
- //try to read it from file
+ // try to read it from file
File f = new File(new File(_path), name + ".storedProcedure");
if (!f.exists())
return null;
@@ -149,9 +150,10 @@ public class EOModel {
}
NSDictionary plist = NSPropertyListSerialization.dictionaryForString(sdict);
if (plist == null)
- throw new IllegalArgumentException("File " + f + " does not contain a valid stored procedure property list.");
+ throw new IllegalArgumentException(
+ "File " + f + " does not contain a valid stored procedure property list.");
proc = new EOStoredProcedure(plist, this);
- //add it to our collection
+ // add it to our collection
_storedProcedures.setObjectForKey(proc, proc.name());
}
return proc;
@@ -159,8 +161,8 @@ public class EOModel {
public NSArray storedProcedures() {
if (_storedProcedures.count() < _storedProcedureNames.count()) {
- for (int i=0; i<_storedProcedureNames.count(); i++)
- storedProcedureNamed((String)_storedProcedureNames.objectAtIndex(i));
+ for (int i = 0; i < _storedProcedureNames.count(); i++)
+ storedProcedureNamed((String) _storedProcedureNames.objectAtIndex(i));
}
return _storedProcedures.allValues();
}
@@ -172,6 +174,7 @@ public class EOModel {
public void setAdaptorName(String value) {
_adaptorName = value;
}
+
public String adaptorName() {
return _adaptorName;
}
@@ -181,8 +184,8 @@ public class EOModel {
return _entitiesByName.allValues();
NSMutableArray es = new NSMutableArray();
for (int i = 0; i < _entities.count(); i++) {
- NSDictionary d = (NSDictionary)_entities.objectAtIndex(i);
- es.addObject(entityNamed((String)d.objectForKey("name")));
+ NSDictionary d = (NSDictionary) _entities.objectAtIndex(i);
+ es.addObject(entityNamed((String) d.objectForKey("name")));
}
return es;
}
@@ -192,18 +195,18 @@ public class EOModel {
return _entitiesByName.allKeys();
NSMutableArray names = new NSMutableArray();
for (int i = 0; i < _entities.count(); i++) {
- NSDictionary d = (NSDictionary)_entities.objectAtIndex(i);
+ NSDictionary d = (NSDictionary) _entities.objectAtIndex(i);
names.addObject(d.objectForKey("name"));
}
return names;
}
public EOEntity entityNamed(String name) {
- EOEntity e = (EOEntity)_entitiesByName.objectForKey(name);
+ EOEntity e = (EOEntity) _entitiesByName.objectForKey(name);
if (e == null && path() != null) {
boolean exists = false;
for (int i = 0; i < _entities.count(); i++) {
- NSDictionary d = (NSDictionary)_entities.objectAtIndex(i);
+ NSDictionary d = (NSDictionary) _entities.objectAtIndex(i);
if (d.objectForKey("name").equals(name))
exists = true;
}
@@ -242,6 +245,7 @@ public class EOModel {
public void setModelGroup(EOModelGroup group) {
_group = group;
}
+
public EOModelGroup modelGroup() {
return _group;
}
@@ -266,7 +270,8 @@ public class EOModel {
File[] kids = f.listFiles();
for (int i = 0; i < kids.length; i++) {
String fname = kids[i].getName();
- if (kids[i].isFile() && (fname.endsWith(".plist") || fname.endsWith(".eomodeld") || fname.endsWith(".fspec") || fname.endsWith(".storedProcedure")))
+ if (kids[i].isFile() && (fname.endsWith(".plist") || fname.endsWith(".eomodeld")
+ || fname.endsWith(".fspec") || fname.endsWith(".storedProcedure")))
kids[i].delete();
}
} else
@@ -275,7 +280,7 @@ public class EOModel {
f.mkdirs();
File kid = new File(f, "index.eomodeld");
- //encode the index file
+ // encode the index file
NSMutableDictionary d = new NSMutableDictionary();
d.setObjectForKey(_adaptorName, "adaptorName");
d.setObjectForKey("2.1", "EOModelVersion");
@@ -287,23 +292,24 @@ public class EOModel {
if (_storedProcedureNames.count() > 0)
d.setObjectForKey(_storedProcedureNames, "storedProcedures");
- //encode the entity list
+ // encode the entity list
entities();
storedProcedures();
NSMutableArray arr = new NSMutableArray(_entitiesByName.count());
Enumeration enumeration = _entitiesByName.keyEnumerator();
NSMutableDictionary md = new NSMutableDictionary();
while (enumeration.hasMoreElements()) {
- String key = (String)enumeration.nextElement();
- EOEntity ent = (EOEntity)_entitiesByName.objectForKey(key);
+ String key = (String) enumeration.nextElement();
+ EOEntity ent = (EOEntity) _entitiesByName.objectForKey(key);
md.removeAllObjects();
ent.encodeIntoPropertyList(md);
File plist;
- NSDictionary fetchSpecs = (NSDictionary)md.objectForKey("fetchSpecificationDictionary");
+ NSDictionary fetchSpecs = (NSDictionary) md.objectForKey("fetchSpecificationDictionary");
if (fetchSpecs != null) {
if (fetchSpecs.count() > 0) {
plist = new File(f, key + ".fspec");
- String ps = NSPropertyListSerialization.stringForPropertyList(md.objectForKey("fetchSpecificationDictionary"));
+ String ps = NSPropertyListSerialization
+ .stringForPropertyList(md.objectForKey("fetchSpecificationDictionary"));
try {
PrintStream stream = new PrintStream(new FileOutputStream(plist));
stream.println(ps);
@@ -321,14 +327,13 @@ public class EOModel {
stream.close();
} catch (IOException ex) {
}
- //add to the entity list for the index
- arr.addObject(new NSDictionary(
- new Object[]{ ent.name(), ent.className() },
- new Object[]{ "name", "className" }));
+ // add to the entity list for the index
+ arr.addObject(new NSDictionary(new Object[] { ent.name(), ent.className() },
+ new Object[] { "name", "className" }));
}
d.setObjectForKey(arr, "entities");
- //write the index file
+ // write the index file
String s = NSPropertyListSerialization.stringForPropertyList(d);
try {
PrintStream stream = new PrintStream(new FileOutputStream(kid));
@@ -338,9 +343,10 @@ public class EOModel {
throw new RuntimeException("Cannot write index.eomodeld");
}
- //write the stored procedures
+ // write the stored procedures
for (int i = 0; i < _storedProcedureNames.count(); i++) {
- EOStoredProcedure proc = (EOStoredProcedure)_storedProcedures.objectForKey(_storedProcedureNames.objectAtIndex(i));
+ EOStoredProcedure proc = (EOStoredProcedure) _storedProcedures
+ .objectForKey(_storedProcedureNames.objectAtIndex(i));
kid = new File(f, proc.name() + ".storedProcedure");
d.removeAllObjects();
proc.encodeIntoPropertyList(d);
@@ -358,39 +364,36 @@ public class EOModel {
}
/*
- * $Log$
- * Revision 1.2 2006/02/16 16:47:14 cgruber
- * Move some classes in to "internal" packages and re-work imports, etc.
+ * $Log$ Revision 1.2 2006/02/16 16:47:14 cgruber Move some classes in to
+ * "internal" packages and re-work imports, etc.
*
- * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
+ * Also use UnsupportedOperationExceptions where appropriate, instead of
+ * WotonomyExceptions.
*
- * Revision 1.1 2006/02/16 13:19:57 cgruber
- * Check in all sources in eclipse-friendly maven-enabled packages.
+ * Revision 1.1 2006/02/16 13:19:57 cgruber Check in all sources in
+ * eclipse-friendly maven-enabled packages.
*
- * Revision 1.8 2005/05/11 15:21:53 cgruber
- * Change enum to enumeration, since enum is now a keyword as of Java 5.0
+ * Revision 1.8 2005/05/11 15:21:53 cgruber Change enum to enumeration, since
+ * enum is now a keyword as of Java 5.0
*
* A few other comments in the code.
*
- * Revision 1.7 2003/08/13 20:46:12 chochos
- * entityNamed() only throws if the searched entity is in the entities array and not in a file.
+ * Revision 1.7 2003/08/13 20:46:12 chochos entityNamed() only throws if the
+ * searched entity is in the entities array and not in a file.
*
- * Revision 1.6 2003/08/12 01:45:04 chochos
- * added some code to handle prototypes
+ * Revision 1.6 2003/08/12 01:45:04 chochos added some code to handle prototypes
*
- * Revision 1.5 2003/08/11 19:38:27 chochos
- * Can now read from a file and re-write to another file.
+ * Revision 1.5 2003/08/11 19:38:27 chochos Can now read from a file and
+ * re-write to another file.
*
- * Revision 1.4 2003/08/11 18:20:08 chochos
- * saving to a file seems to work now.
+ * Revision 1.4 2003/08/11 18:20:08 chochos saving to a file seems to work now.
*
- * Revision 1.3 2003/08/08 02:16:55 chochos
- * can now read stored procedures from file.
+ * Revision 1.3 2003/08/08 02:16:55 chochos can now read stored procedures from
+ * file.
*
- * Revision 1.2 2003/08/08 00:37:00 chochos
- * add stored procedure functionality
+ * Revision 1.2 2003/08/08 00:37:00 chochos add stored procedure functionality
*
- * Revision 1.1 2003/08/07 02:42:28 chochos
- * EOModel can read an .eomodeld file. EOModelGroup doesn't do much for now.
+ * Revision 1.1 2003/08/07 02:42:28 chochos EOModel can read an .eomodeld file.
+ * EOModelGroup doesn't do much for now.
*
-*/ \ No newline at end of file
+ */ \ No newline at end of file