RE: [WO45] Problem with a new EOQualifier subclass in Java
RE: [WO45] Problem with a new EOQualifier subclass in Java
- Subject: RE: [WO45] Problem with a new EOQualifier subclass in Java
- From: "Labrie, Francis (Liste de distribution)" <email@hidden>
- Date: Tue, 11 Mar 2003 13:10:13 -0500
Hi,
Chuck Hill wrote:
> Here are the docs describing how to create a sub-class in Obj-C:
> [...]
> Specifically, "Subclasses used to evaluate objects in memory
> must implement the EOQualifierEvaluation protocol. Subclasses
> used to generate SQL queries must conform to the
> EOQualifierSQLGeneration protocol."
Yes but strangely there is no Java interface for this protocol.
> EOQualifierEvaluation:
> [...]
My qualifier class implement this and Clonable interfaces.
> EOQualifierSQLGeneration:
> [...]
> Those define
> - (BOOL)evaluateWithObject:object
> - (NSString *)sqlStringForSQLExpression:
> (EOSQLExpression *)sqlExpression
> - (EOQualifier *)schemaBasedQualifierWithRootEntity:
> (EOEntity *)entity
> Have you implemented all of those methods?
Yes, my Java class define these methode like this:
public boolean evaluateWithObject(Object)
public String sqlStringForSQLExpression(EOSQLExpression)
public EOQualifier schemaBasedQualifierWithRootEntity(EOEntity)
> That is all I can think of for now, my Obj-C is getting a bit
> rusty. :-(
Just to be sure, I've adapted for WebObjects 4.5 Petite Abeille's
WebObjects 5 InQualifier sample, and it throws exacly the same
exception when use with a WODisplayGroup:
NSInvalidArgumentException: ***
-qualifierMigratedFromEntity:relationshipPath: cannot be
sent to an abstract object of class
com/genilog/webobjects/eocontrol/InQualifier: Create a
concrete instance!
Here is the InQualifier adapted code. Is there any implementation
problem in it?
package com.genilog.webobjects.eocontrol;
import com.apple.yellow.eoaccess.*;
import com.apple.yellow.eocontrol.*;
import com.apple.yellow.foundation.*;
import java.math.BigDecimal;
import java.util.Enumeration;
public class InQualifier extends EOQualifier implements
EOQualifierEvaluation, Cloneable {
private static final String Space = " ";
private static final String InStatement = Space + "IN" + Space;
private static final String OpenBracket = "(";
private static final String CloseBracket = ")";
private static final String Separator = "," + Space;
private String _key;
private NSArray _values;
public InQualifier() {
this(null, null);
} // InQualifier
public InQualifier(String key, NSArray values) {
super();
setKey(key);
setValues(values);
} // InQualifier
public void addQualifierKeysToSet(NSMutableSet set) {
if(set != null) {
String key;
key = key();
if(key != null) {
set.addObject(key);
} // if
} // if
} // addQualifierKeysToSet
public Object clone() {
InQualifier clone;
NSArray values;
String key;
key = key();
if(key != null) key = new String(key);
values = values();
if(values != null) values = new NSArray(values);
clone = new InQualifier(key, values);
return(clone);
} // clone
public boolean evaluateWithObject(Object object) {
boolean evaluation;
evaluation = false;
if((object != null) && (object instanceof NSKeyValueCoding))
{
String key;
NSArray values;
key = key();
values = values();
if((key != null) && (values != null)) {
Object value;
NSArray objectValues;
evaluation = true;
value =
((NSKeyValueCoding)object).valueForKey(key);
objectValues =
(NSArray)values.valueForKey(key);
if(!objectValues.containsObject(value)) {
evaluation = false;
} // if
} // if
} // if
return(evaluation);
} // evaluateWithObject
public String key() {
return(_key);
} // key
public void setKey(String key) {
_key = key;
} // setKey
public EOQualifier qualifierMigratedFromEntity(EOEntity entity,
String path) {
return((EOQualifier)clone());
} // qualifierMigratedFromEntity
public EOQualifier qualifierWithBindings(NSDictionary bindings,
boolean requiresAll) {
return((EOQualifier)clone());
} // qualifierWithBindings
public EOQualifier schemaBasedQualifierWithRootEntity(EOEntity
entity) {
return((EOQualifier)clone());
} // schemaBasedQualifierWithRootEntity
public String sqlStringForSQLExpression(EOSQLExpression
sqlExpression) {
String sqlString;
sqlString = null;
if((sqlExpression != null) && (sqlExpression.entity() !=
null)) {
EOEntity entity;
NSArray values;
String key;
entity = sqlExpression.entity();
values = values();
key = key();
if(((key != null) && (values != null) &&
(values.count() > 0))) {
int valueCount;
EOKeyValueQualifier qualifier;
Object object;
StringBuffer buffer;
buffer = new StringBuffer();
valueCount = values.count();
buffer.append(InQualifier.OpenBracket);
qualifier = new EOKeyValueQualifier(key,
EOQualifier.QualifierOperatorEqual, EONullValue.nullValue());
qualifier =
(EOKeyValueQualifier)entity.schemaBasedQualifier(qualifier);
buffer.append(sqlExpression.sqlStringForAttributeNamed(qualifier.key()));
buffer.append(InQualifier.CloseBracket);
buffer.append(InQualifier.InStatement);
buffer.append(InQualifier.OpenBracket);
for(int valueIndex = 0; valueIndex <
valueCount; valueIndex++) {
if(valueIndex > 0) {
buffer.append(InQualifier.Separator);
} // if
object =
values.objectAtIndex(valueIndex);
buffer.append(InQualifier.OpenBracket);
if((entity.relationshipNamed(key) !=
null) && (object instanceof EOEnterpriseObject) &&
(entity.relationshipNamed(key).destinationEntity().name().equals(((EOEnterpr
iseObject)object).entityName()))) {
qualifier = new
EOKeyValueQualifier(key, EOQualifier.QualifierOperatorEqual, object);
qualifier =
(EOKeyValueQualifier)entity.schemaBasedQualifier(qualifier);
buffer.append(sqlExpression.sqlStringForValue(qualifier.value(),
qualifier.key()));
} else {
if(object != null) {
qualifier = new
EOKeyValueQualifier(key, EOQualifier.QualifierOperatorEqual, object);
qualifier =
(EOKeyValueQualifier)entity.schemaBasedQualifier(qualifier);
buffer.append(sqlExpression.sqlStringForValue(qualifier.value(),
qualifier.key()));
} // if
} // else
buffer.append(InQualifier.CloseBracket);
} // for
buffer.append(InQualifier.CloseBracket);
sqlString = buffer.toString();
} // if
} // if
return(sqlString);
} // sqlStringForSQLExpression
public String toString() {
StringBuffer string;
string = new StringBuffer();
string.append("(");
string.append((key() != null)? key() : "nil");
string.append(InQualifier.InStatement);
string.append(InQualifier.OpenBracket);
if(values() != null) {
Enumeration values;
Object value;
values = values().objectEnumerator();
while(values.hasMoreElements()) {
value = values.nextElement();
if((value == null) ||
value.equals(EONullValue.nullValue())) {
value = "nil";
} else if(value instanceof String) {
value =
EOSQLExpression.formatStringValue((String)value);
} else if((value instanceof Number) &&
!(value instanceof BigDecimal)) {
value = value.toString();
} else if(value instanceof
EOQualifierVariable) {
value = "$" +
((EOQualifierVariable)value).key();
} else {
value = "(" +
value.getClass().getName() + ")" + value.toString();
} // else
string.append(value);
if(values.hasMoreElements())
string.append(InQualifier.Separator);
} // while
} // if
string.append(InQualifier.CloseBracket);
string.append(")");
return(string.toString());
} // toString
public Throwable
validateKeysWithRootClassDescription(EOClassDescription classDescription) {
return(null);
} // validateKeysWithRootClassDescription
public NSArray values() {
return(_values);
} // values
public void setValues(NSArray values) {
_values = values;
} // setValues
} // InQualifier
____________________________________________
Francis Labrie email@hidden
Montreal, Quebec
Canada
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.