|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecter.extensions.eof.ERXConstant
public abstract class ERXConstant
General purpose constant class, useful when you want reference object that are not
bytes or strings in the DB like what you get with the factory classes.
If you use objects of this class, you might be able to completely remove the EOSharedEditingContext
(the google search term for "why does my app lock up").
To use the Number constants, you need to add an entry ERXConstantClassName=Test.Status
to the attribute's userInfo
in question and your EO's class description needs to be a ERXEntityClassDescription
, also
you must enable the er.extension.ERXJDBCAdaptor
.
The String and Byte based constants can be used with a custom class type:
ERCMailMessage.plist:
...
{
columnName = MAIL_STATE_ID;
name = state;
prototypeName = osType;
adaptorValueConversionMethodName = value;
factoryMethodArgumentType = EOFactoryMethodArgumentIsNSString;
valueClassName = er.corebusinesslogic.ERCMailState;
valueFactoryMethodName = mailState;
}
...
public class ERCMailMessage extends EOGenericRecord {
...
public ERCMailState state() {
return (ERCMailState) storedValueForKey("state");
}
public void setState(ERCMailState value) {
takeStoredValueForKey(value, "state");
}
...
}
public class ERCMailState extends ERXConstant.StringConstant {
public ERCMailState(String key, String name) {
super(key, name);
}
public static ERCMailState mailState(String key) {
return (ERCMailState) constantForClassNamed(key, ERCMailState.class.getName());
}
public static ERCMailState EXCEPTION_STATE = new ERCMailState ("xcpt", "Exception");
public static ERCMailState READY_TO_BE_SENT_STATE = new ERCMailState("rtbs", "Ready to be sent");
public static ERCMailState SENT_STATE = new ERCMailState("sent", "Sent");
public static ERCMailState RECEIVED_STATE = new ERCMailState("rcvd", "Received");
public static ERCMailState WAIT_STATE = new ERCMailState("wait", "Wait");
public static ERCMailState PROCESSING_STATE = new ERCMailState("proc", "Processing");
}
public class Test extends EOGenericRecord {
// your "status" attribute need a userInfo entry
// "ERXConstantClassName" = "Test.Status";
// Normally, the class name would be "Test$Status", this form is used to help you use EOGenerator
public static class Status extends ERXConstant.NumberConstant {
protected Status(int value, String name) {
super(value, name);
}
}
public Status OFF = new Status(0, "Off");
public Status ON = new Status(1, "On");
public Test() {
super();
}
public Status status() {
return (Status)storedValueForKey("status");
}
public void setStatus(Constant aValue) {
takeStoredValueForKey(aValue, "status");
}
public boolean isOn() {
return status() == ON;
}
}
Test test = (Test)EOUtilities.createAndInsertInstance(ec, "Test");
test.setTest(Test.Status.OFF);
test = (Test)EOUtilities.createAndInsertInstance(ec, "Test");
test.setStatus(Test.Status.ON);
ec.saveChanges();
NSArray objects;
NSArray all = EOUtilities.objectsForEntityNamed(ec, "Test");
EOQualifier q;
objects = EOUtilities.objectsMatchingKeyAndValue(ec, "Test", "status", Test.Status.OFF);
log.info("Test.Status.OFF: " + objects);
q = new EOKeyValueQualifier("status", EOQualifier.QualifierOperatorEqual, Test.Status.OFF);
log.info("Test.Status.OFF: " + EOQualifier.filteredArrayWithQualifier(all, q));
// this might be a problem: equal number values match in the DB, but not in memory
objects = EOUtilities.objectsMatchingKeyAndValue(ec, "Test", "status", ERXConstant.OneInteger);
log.info("Number.OFF: " + objects);
q = new EOKeyValueQualifier("status", EOQualifier.QualifierOperatorEqual, ERXConstant.OneInteger);
log.info("Number.OFF: " + EOQualifier.filteredArrayWithQualifier(all, q));
// you can compare by equality
test.getStatus() == Test.Status.ON
Note that upon class initialization 2500 Integers will be created and cached, from 0 - 2499.
Nested Class Summary | |
---|---|
static class |
ERXConstant.ByteConstant
Constant class that can be used with bytes or NSData in the DB. |
static interface |
ERXConstant.Constant
|
static class |
ERXConstant.NumberConstant
|
static class |
ERXConstant.StringConstant
Constant class that can be used with strings in the DB. |
Field Summary | |
---|---|
static com.webobjects.foundation.NSArray |
EmptyArray
|
static java.lang.Class[] |
EmptyClassArray
|
static com.webobjects.foundation.NSDictionary |
EmptyDictionary
|
static com.webobjects.foundation.NSData |
EmptyImage
an empty gif image |
static java.lang.Object |
EmptyObject
|
static java.lang.Object[] |
EmptyObjectArray
|
static java.lang.String |
EmptyString
|
protected static java.lang.Integer[] |
INTEGERS
|
static int |
MAX_INT
|
static java.lang.Integer |
MinusOneInteger
|
static java.lang.Class[] |
NotificationClassArray
|
static java.lang.Class[] |
ObjectClassArray
|
static java.math.BigDecimal |
OneBigDecimal
|
static java.lang.Integer |
OneInteger
|
static com.webobjects.foundation.NSArray |
SingleNullValueArray
|
static java.lang.Class[] |
StringClassArray
|
static java.lang.Integer |
ThreeInteger
|
static java.lang.Integer |
TwoInteger
|
static java.math.BigDecimal |
ZeroBigDecimal
|
static java.lang.Integer |
ZeroInteger
|
Constructor Summary | |
---|---|
ERXConstant()
|
Method Summary | |
---|---|
static ERXConstant.Constant |
constantForClassNamed(java.lang.Object value,
java.lang.String clazzName)
Retrieves the constant for the given class name and value. |
static com.webobjects.foundation.NSArray |
constantsForClassName(java.lang.String clazzName)
Retrieves all constants for the given class name ordered by value. |
static java.lang.Integer |
integerForInt(int i)
Returns an Integer for a given int |
static java.lang.Integer |
integerForString(java.lang.String s)
Returns an Integer for a given String |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_INT
protected static java.lang.Integer[] INTEGERS
public static final java.lang.Object EmptyObject
public static final java.lang.String EmptyString
public static final com.webobjects.foundation.NSArray EmptyArray
public static final com.webobjects.foundation.NSArray SingleNullValueArray
public static final com.webobjects.foundation.NSDictionary EmptyDictionary
public static final java.lang.Integer MinusOneInteger
public static final java.lang.Integer OneInteger
public static final java.lang.Integer ZeroInteger
public static final java.lang.Integer TwoInteger
public static final java.lang.Integer ThreeInteger
public static final java.math.BigDecimal ZeroBigDecimal
public static final java.math.BigDecimal OneBigDecimal
public static final java.lang.Class[] EmptyClassArray
public static final java.lang.Class[] NotificationClassArray
public static final java.lang.Class[] ObjectClassArray
public static final java.lang.Class[] StringClassArray
public static final java.lang.Object[] EmptyObjectArray
public static final com.webobjects.foundation.NSData EmptyImage
Constructor Detail |
---|
public ERXConstant()
Method Detail |
---|
public static com.webobjects.foundation.NSArray constantsForClassName(java.lang.String clazzName)
clazzName
- public static ERXConstant.Constant constantForClassNamed(java.lang.Object value, java.lang.String clazzName)
value
- clazzName
- public static java.lang.Integer integerForInt(int i)
public static java.lang.Integer integerForString(java.lang.String s) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- forwarded from the
parseInt method off of Integer
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |