summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.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/EOEntity.java
parentff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff)
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java')
-rw-r--r--projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java202
1 files changed, 108 insertions, 94 deletions
diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java
index 4adc4a1..47a31c0 100644
--- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java
+++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOEntity.java
@@ -42,14 +42,14 @@ import net.wotonomy.foundation.NSMutableDictionary;
import net.wotonomy.foundation.NSPropertyListSerialization;
/**
-* An EOEntity is a mapping between a Java class and a database table or view.
-* It indicates which attributes should be fetched from the table/view, what
-* attributes are part of the primary key, what class the entity should map to.
-*
-* @author ezamudio@nasoft.com
-* @author $Author: cgruber $
-* @version $Revision: 894 $
-*/
+ * An EOEntity is a mapping between a Java class and a database table or view.
+ * It indicates which attributes should be fetched from the table/view, what
+ * attributes are part of the primary key, what class the entity should map to.
+ *
+ * @author ezamudio@nasoft.com
+ * @author $Author: cgruber $
+ * @version $Revision: 894 $
+ */
public class EOEntity implements EOPropertyListEncoding {
protected NSMutableDictionary _attributes = new NSMutableDictionary();
@@ -80,55 +80,55 @@ public class EOEntity implements EOPropertyListEncoding {
public EOEntity(NSDictionary dict, Object obj) {
super();
- _model = (EOModel)obj;
- setName((String)dict.objectForKey("name"));
- setExternalName((String)dict.objectForKey("externalName"));
- setClassName((String)dict.objectForKey("className"));
+ _model = (EOModel) obj;
+ setName((String) dict.objectForKey("name"));
+ setExternalName((String) dict.objectForKey("externalName"));
+ setClassName((String) dict.objectForKey("className"));
if (dict.objectForKey("internalInfo") != null)
- _internalInfo = (NSDictionary)dict.objectForKey("internalInfo");
+ _internalInfo = (NSDictionary) dict.objectForKey("internalInfo");
if (dict.objectForKey("userInfo") != null)
- _userInfo = (NSDictionary)dict.objectForKey("userInfo");
+ _userInfo = (NSDictionary) dict.objectForKey("userInfo");
- //Read the attributes
- NSArray atr = (NSArray)dict.objectForKey("attributes");
+ // Read the attributes
+ NSArray atr = (NSArray) dict.objectForKey("attributes");
for (int i = 0; i < atr.count(); i++) {
- NSDictionary d = (NSDictionary)atr.objectAtIndex(i);
+ NSDictionary d = (NSDictionary) atr.objectAtIndex(i);
EOAttribute atrib = new EOAttribute(d, this);
addAttribute(atrib);
}
- //Set the primary key
- atr = (NSArray)dict.objectForKey("primaryKeyAttributes");
+ // Set the primary key
+ atr = (NSArray) dict.objectForKey("primaryKeyAttributes");
NSMutableArray pka = new NSMutableArray();
for (int i = 0; i < atr.count(); i++) {
- EOAttribute a = attributeNamed((String)atr.objectAtIndex(i));
+ EOAttribute a = attributeNamed((String) atr.objectAtIndex(i));
pka.addObject(a);
}
_pkAttributes = new NSArray(pka);
_pkAttributeNames = atr;
- //attributes used for locking
+ // attributes used for locking
_lockingAttributes.removeAllObjects();
- atr = (NSArray)dict.objectForKey("attributesUsedForLocking");
+ atr = (NSArray) dict.objectForKey("attributesUsedForLocking");
for (int i = 0; i < atr.count(); i++) {
- String x = (String)atr.objectAtIndex(i);
+ String x = (String) atr.objectAtIndex(i);
EOAttribute a = attributeNamed(x);
_lockingAttributes.addObject(a);
}
- //class properties
- atr = (NSArray)dict.objectForKey("classProperties");
+ // class properties
+ atr = (NSArray) dict.objectForKey("classProperties");
if (atr != null) {
for (int i = 0; i < atr.count(); i++)
if (!_classPropertyNames.containsObject((atr.objectAtIndex(i))))
_classPropertyNames.addObject(atr.objectAtIndex(i));
}
- //Read the relationships
- atr = (NSArray)dict.objectForKey("relationships");
+ // Read the relationships
+ atr = (NSArray) dict.objectForKey("relationships");
if (atr != null) {
for (int i = 0; i < atr.count(); i++) {
- NSDictionary d = (NSDictionary)atr.objectAtIndex(i);
+ NSDictionary d = (NSDictionary) atr.objectAtIndex(i);
EORelationship rel = new EORelationship(d, this);
addRelationship(rel);
}
@@ -169,7 +169,7 @@ public class EOEntity implements EOPropertyListEncoding {
public EOFetchSpecification fetchSpecificationNamed(String name) {
loadFetchSpecifications();
- return (EOFetchSpecification)_fetchSpecs.objectForKey(name);
+ return (EOFetchSpecification) _fetchSpecs.objectForKey(name);
}
public NSArray fetchSpecificationNames() {
@@ -177,8 +177,8 @@ public class EOEntity implements EOPropertyListEncoding {
return _fetchSpecs.allKeys();
}
- /** Loads fetch specifications from the .fspec file,
- * if one exists.
+ /**
+ * Loads fetch specifications from the .fspec file, if one exists.
*/
private void loadFetchSpecifications() {
if (_loadedFetchSpecs)
@@ -187,7 +187,7 @@ public class EOEntity implements EOPropertyListEncoding {
if (model().path() == null)
return;
File f = new File(model().path());
- //Read the fetch specification file, if it exists
+ // Read the fetch specification file, if it exists
f = new File(f, name() + ".fspec");
if (!f.exists())
return;
@@ -207,11 +207,11 @@ public class EOEntity implements EOPropertyListEncoding {
throw new IllegalArgumentException("Cannot read dictionary from " + f);
NSArray keys = fdict.allKeys();
- //Unarchive the fetch specification
+ // Unarchive the fetch specification
EOKeyValueUnarchiver unarch = new EOKeyValueUnarchiver(fdict);
for (int i = 0; i < keys.count(); i++) {
- String k = (String)keys.objectAtIndex(i);
- EOFetchSpecification fs = (EOFetchSpecification)unarch.decodeObjectForKey(k);
+ String k = (String) keys.objectAtIndex(i);
+ EOFetchSpecification fs = (EOFetchSpecification) unarch.decodeObjectForKey(k);
if (fs != null)
_fetchSpecs.setObjectForKey(fs, k);
}
@@ -222,7 +222,7 @@ public class EOEntity implements EOPropertyListEncoding {
}
public EOAttribute attributeNamed(String name) {
- return (EOAttribute)_attributes.objectForKey(name);
+ return (EOAttribute) _attributes.objectForKey(name);
}
public NSArray flattenedAttributes() {
@@ -232,6 +232,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setClassName(String name) {
_className = name;
}
+
public String className() {
return _className;
}
@@ -239,6 +240,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setName(String name) {
_name = name;
}
+
public String name() {
return _name;
}
@@ -246,6 +248,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setExternalName(String name) {
_externalName = name;
}
+
public String externalName() {
return _externalName;
}
@@ -274,7 +277,9 @@ public class EOEntity implements EOPropertyListEncoding {
_classPropertyOneRelationships.removeObject(rel);
}
- /** Returns the relationships from this entity to other entities.
+ /**
+ * Returns the relationships from this entity to other entities.
+ *
* @return An array of the relationships of this entity.
*/
public NSArray relationships() {
@@ -282,8 +287,9 @@ public class EOEntity implements EOPropertyListEncoding {
}
public EORelationship relationshipNamed(String name) {
- return (EORelationship)_relations.objectForKey(name);
+ return (EORelationship) _relations.objectForKey(name);
}
+
public EOModel model() {
return _model;
}
@@ -291,6 +297,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setPrimaryKeyAtributes(NSArray pk) {
_pkAttributes = pk;
}
+
public NSArray primaryKeyAttributes() {
return _pkAttributes;
}
@@ -299,7 +306,7 @@ public class EOEntity implements EOPropertyListEncoding {
if (_pkAttributeNames.count() != _pkAttributes.count()) {
NSMutableArray arr = new NSMutableArray();
for (int i = 0; i < _pkAttributes.count(); i++) {
- EOAttribute a = (EOAttribute)_pkAttributes.objectAtIndex(i);
+ EOAttribute a = (EOAttribute) _pkAttributes.objectAtIndex(i);
arr.addObject(a.name());
}
_pkAttributeNames = new NSArray(arr);
@@ -319,6 +326,7 @@ public class EOEntity implements EOPropertyListEncoding {
_lockingAttributes.removeAllObjects();
_lockingAttributes.addObjectsFromArray(value);
}
+
public NSArray attributesUsedForLocking() {
return new NSArray(_lockingAttributes);
}
@@ -331,18 +339,19 @@ public class EOEntity implements EOPropertyListEncoding {
_classPropertyOneRelationships.removeAllObjects();
_classPropertyManyRelationships.removeAllObjects();
for (int i = 0; i < value.count(); i++) {
- EOProperty o = (EOProperty)value.objectAtIndex(i);
+ EOProperty o = (EOProperty) value.objectAtIndex(i);
_classPropertyNames.addObject(o.name());
if (o instanceof EOAttribute) {
_classPropertyAttributes.addObject(o);
} else if (o instanceof EORelationship) {
- if (((EORelationship)o).isToMany())
+ if (((EORelationship) o).isToMany())
_classPropertyManyRelationships.addObject(o);
else
_classPropertyOneRelationships.addObject(o);
}
}
}
+
public NSArray classProperties() {
if (_classProperties == null) {
if (_classPropertyNames == null)
@@ -353,7 +362,7 @@ public class EOEntity implements EOPropertyListEncoding {
NSMutableArray ones = new NSMutableArray();
NSMutableArray manies = new NSMutableArray();
for (int i = 0; i < _classPropertyNames.count(); i++) {
- String name = (String)_classPropertyNames.objectAtIndex(i);
+ String name = (String) _classPropertyNames.objectAtIndex(i);
EOAttribute a = attributeNamed(name);
EORelationship r = relationshipNamed(name);
if (a != null) {
@@ -385,8 +394,8 @@ public class EOEntity implements EOPropertyListEncoding {
if (_classPropertyAttributes == null)
return NSArray.EmptyArray;
NSMutableArray arr = new NSMutableArray(_classPropertyAttributes.count());
- for (int i = 0 ; i < _classPropertyAttributes.count(); i++) {
- EOAttribute a = (EOAttribute)_classPropertyAttributes.objectAtIndex(i);
+ for (int i = 0; i < _classPropertyAttributes.count(); i++) {
+ EOAttribute a = (EOAttribute) _classPropertyAttributes.objectAtIndex(i);
arr.addObject(a.name());
}
return arr;
@@ -396,8 +405,8 @@ public class EOEntity implements EOPropertyListEncoding {
if (_classPropertyManyRelationships == null)
return NSArray.EmptyArray;
NSMutableArray arr = new NSMutableArray(_classPropertyManyRelationships.count());
- for (int i = 0 ; i < _classPropertyManyRelationships.count(); i++) {
- EOAttribute a = (EOAttribute)_classPropertyManyRelationships.objectAtIndex(i);
+ for (int i = 0; i < _classPropertyManyRelationships.count(); i++) {
+ EOAttribute a = (EOAttribute) _classPropertyManyRelationships.objectAtIndex(i);
arr.addObject(a.name());
}
return arr;
@@ -407,8 +416,8 @@ public class EOEntity implements EOPropertyListEncoding {
if (_classPropertyOneRelationships == null)
return NSArray.EmptyArray;
NSMutableArray arr = new NSMutableArray(_classPropertyOneRelationships.count());
- for (int i = 0 ; i < _classPropertyOneRelationships.count(); i++) {
- EOAttribute a = (EOAttribute)_classPropertyOneRelationships.objectAtIndex(i);
+ for (int i = 0; i < _classPropertyOneRelationships.count(); i++) {
+ EOAttribute a = (EOAttribute) _classPropertyOneRelationships.objectAtIndex(i);
arr.addObject(a.name());
}
return arr;
@@ -417,6 +426,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setIsAbstractEntity(boolean flag) {
_isAbstract = flag;
}
+
public boolean isAbstractEntity() {
return _isAbstract;
}
@@ -424,12 +434,14 @@ public class EOEntity implements EOPropertyListEncoding {
public void setReadOnly(boolean flag) {
_isReadOnly = flag;
}
+
public boolean isReadOnly() {
return _isReadOnly;
}
public void setStoredProcedure(EOStoredProcedure proc, String operation) {
}
+
public EOStoredProcedure storedProcedureForOperation(String operation) {
return null;
}
@@ -462,8 +474,9 @@ public class EOEntity implements EOPropertyListEncoding {
}
/**
- * Creates a global ID for a row. The row must have values
- * for all the primary key attributes.
+ * Creates a global ID for a row. The row must have values for all the primary
+ * key attributes.
+ *
* @param row A raw row for this entity.
* @return A key global ID to identify this row.
*/
@@ -471,7 +484,7 @@ public class EOEntity implements EOPropertyListEncoding {
NSArray pknames = primaryKeyAttributeNames();
EOKeyGlobalID gid = null;
if (pknames.count() == 1 && row.get(pknames.objectAtIndex(0)) instanceof Number) {
- Number n = (Number)row.get(pknames.objectAtIndex(0));
+ Number n = (Number) row.get(pknames.objectAtIndex(0));
gid = new EOIntegralKeyGlobalID(name(), n);
} else {
Object[] vals = new Object[pknames.count()];
@@ -485,15 +498,15 @@ public class EOEntity implements EOPropertyListEncoding {
}
/**
- * Returns a dictionary with the primary key values contained in
- * the global id.
+ * Returns a dictionary with the primary key values contained in the global id.
+ *
* @param gid A Key global ID.
* @return A dictionary with the primary key values for gid.
*/
public NSDictionary primaryKeyForGlobalID(EOGlobalID gid) {
if (!(gid instanceof EOKeyGlobalID))
return null;
- Object[] vals = ((EOKeyGlobalID)gid).keyValues();
+ Object[] vals = ((EOKeyGlobalID) gid).keyValues();
NSArray pknames = primaryKeyAttributeNames();
return new NSDictionary(vals, pknames.toArray());
}
@@ -503,14 +516,14 @@ public class EOEntity implements EOPropertyListEncoding {
EOQualifier q = null;
NSMutableArray subq = new NSMutableArray(pknames.count());
for (int i = 0; i < pknames.count(); i++) {
- String key = (String)pknames.objectAtIndex(i);
+ String key = (String) pknames.objectAtIndex(i);
Object v = pkey.get(key);
if (v == null || v == NSKeyValueCoding.NullValue)
throw new IllegalArgumentException("Primary key with null values.");
subq.addObject(new EOKeyValueQualifier(key, EOQualifier.QualifierOperatorEqual, v));
}
if (subq.count() == 1)
- q = (EOQualifier)subq.objectAtIndex(0);
+ q = (EOQualifier) subq.objectAtIndex(0);
else
q = new EOAndQualifier(subq);
return q;
@@ -519,6 +532,7 @@ public class EOEntity implements EOPropertyListEncoding {
public void setUserInfo(NSDictionary value) {
_userInfo = value;
}
+
public NSDictionary userInfo() {
return _userInfo;
}
@@ -531,20 +545,20 @@ public class EOEntity implements EOPropertyListEncoding {
dict.setObjectForKey(externalName(), "externalName");
dict.setObjectForKey(className(), "className");
- //Encode attributes
+ // Encode attributes
NSMutableArray arr = new NSMutableArray(_attributes.allValues());
for (int i = 0; i < _attributes.count(); i++) {
- EOAttribute a = (EOAttribute)arr.objectAtIndex(i);
+ EOAttribute a = (EOAttribute) arr.objectAtIndex(i);
NSMutableDictionary d = new NSMutableDictionary();
a.encodeIntoPropertyList(d);
arr.replaceObjectAtIndex(i, d);
}
dict.setObjectForKey(arr, "attributes");
- //Encode relationships
+ // Encode relationships
if (_relations.count() > 0) {
arr = new NSMutableArray(_relations.allValues());
for (int i = 0; i < _relations.count(); i++) {
- EORelationship r = (EORelationship)arr.objectAtIndex(i);
+ EORelationship r = (EORelationship) arr.objectAtIndex(i);
NSMutableDictionary d = new NSMutableDictionary();
r.encodeIntoPropertyList(d);
arr.replaceObjectAtIndex(i, d);
@@ -552,29 +566,29 @@ public class EOEntity implements EOPropertyListEncoding {
dict.setObjectForKey(arr, "relationships");
}
- //Fetch specifications
+ // Fetch specifications
NSMutableDictionary d = new NSMutableDictionary();
loadFetchSpecifications();
java.util.Enumeration enumeration = _fetchSpecs.keyEnumerator();
while (enumeration.hasMoreElements()) {
- String k = (String)enumeration.nextElement();
- EOFetchSpecification f = (EOFetchSpecification)_fetchSpecs.objectForKey(k);
+ String k = (String) enumeration.nextElement();
+ EOFetchSpecification f = (EOFetchSpecification) _fetchSpecs.objectForKey(k);
EOKeyValueArchiver arch = new EOKeyValueArchiver();
f.encodeWithKeyValueArchiver(arch);
d.setObjectForKey(arch.dictionary(), k);
}
dict.setObjectForKey(d, "fetchSpecificationDictionary");
- //Other information
+ // Other information
dict.setObjectForKey(_classPropertyNames, "classProperties");
dict.setObjectForKey(_pkAttributeNames, "primaryKeyAttributes");
arr = new NSMutableArray(_lockingAttributes);
for (int i = 0; i < arr.count(); i++)
- arr.replaceObjectAtIndex(i, ((EOAttribute)arr.objectAtIndex(i)).name());
+ arr.replaceObjectAtIndex(i, ((EOAttribute) arr.objectAtIndex(i)).name());
dict.setObjectForKey(arr, "attributesUsedForLocking");
- if (_userInfo != null && _userInfo.count() > 0 )
+ if (_userInfo != null && _userInfo.count() > 0)
dict.setObjectForKey(_userInfo, "userInfo");
- if (_internalInfo != null && _internalInfo.count() > 0 )
+ if (_internalInfo != null && _internalInfo.count() > 0)
dict.setObjectForKey(_internalInfo, "internalInfo");
}
@@ -584,54 +598,54 @@ public class EOEntity implements EOPropertyListEncoding {
return null;
EORelationship r = null;
EOEntity e = this;
- for (int i = 0; i < comps.count()-1; i++) {
- String name = (String)comps.objectAtIndex(i);
+ for (int i = 0; i < comps.count() - 1; i++) {
+ String name = (String) comps.objectAtIndex(i);
r = e.relationshipNamed(name);
if (r == null)
return null;
e = r.destinationEntity();
}
- return e.attributeNamed((String)comps.lastObject());
+ return e.attributeNamed((String) comps.lastObject());
}
}
/*
- * $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.9 2005/05/11 15:21:53 cgruber
- * Change enum to enumeration, since enum is now a keyword as of Java 5.0
+ * Revision 1.9 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.8 2003/08/19 19:47:58 chochos
- * added some methods to handle EOGlobalIDs and primary keys.
+ * Revision 1.8 2003/08/19 19:47:58 chochos added some methods to handle
+ * EOGlobalIDs and primary keys.
*
- * Revision 1.7 2003/08/14 02:13:56 chochos
- * implement and use _attributeForPath()
+ * Revision 1.7 2003/08/14 02:13:56 chochos implement and use
+ * _attributeForPath()
*
- * Revision 1.6 2003/08/11 19:38:27 chochos
- * Can now read from a file and re-write to another file.
+ * Revision 1.6 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 18:19:33 chochos
- * encoding into property list seems to work fine now.
+ * Revision 1.5 2003/08/11 18:19:33 chochos encoding into property list seems to
+ * work fine now.
*
- * Revision 1.4 2003/08/09 01:39:04 chochos
- * better handling of class properties; use EOKeyValueArchiving to encode/decode fetch specifications; implement EOPropertyListEncoding
+ * Revision 1.4 2003/08/09 01:39:04 chochos better handling of class properties;
+ * use EOKeyValueArchiving to encode/decode fetch specifications; implement
+ * EOPropertyListEncoding
*
- * Revision 1.3 2003/08/08 05:52:21 chochos
- * gets the class description for the entity.
+ * Revision 1.3 2003/08/08 05:52:21 chochos gets the class description for the
+ * entity.
*
- * Revision 1.2 2003/08/08 02:14:20 chochos
- * now it can read stored procedures.
+ * Revision 1.2 2003/08/08 02:14:20 chochos now it can read stored procedures.
*
- * Revision 1.1 2003/08/07 02:38:33 chochos
- * implementation of EOEntity. What works for now is reading an entity from file.
+ * Revision 1.1 2003/08/07 02:38:33 chochos implementation of EOEntity. What
+ * works for now is reading an entity from file.
*
*/