public abstract class ERXConstant
extends java.lang.Object
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 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");
}
An example would be:
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.| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
static NSArray |
EmptyArray |
static java.lang.Class[] |
EmptyClassArray |
static NSDictionary |
EmptyDictionary |
static 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 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 and Description |
|---|
ERXConstant() |
| Modifier and Type | Method and Description |
|---|---|
static ERXConstant.Constant |
constantForClassNamed(java.lang.Object value,
java.lang.String clazzName)
Retrieves the constant for the given class name and value.
|
static 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)
Deprecated.
use
ERXStringUtilities#integerWithString(String) |
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 NSArray EmptyArray
public static final NSArray SingleNullValueArray
public static final 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 NSData EmptyImage
public static 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)
@Deprecated
public static java.lang.Integer integerForString(java.lang.String s)
throws java.lang.NumberFormatException
ERXStringUtilities#integerWithString(String)java.lang.NumberFormatException - forwarded from the
parseInt method off of IntegerCopyright © 2002 – 2022 Project Wonder.