public abstract class ERXConstant extends 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 Class[] |
EmptyClassArray |
static NSDictionary |
EmptyDictionary |
static NSData |
EmptyImage
an empty gif image
|
static Object |
EmptyObject |
static Object[] |
EmptyObjectArray |
static String |
EmptyString |
protected static Integer[] |
INTEGERS |
static int |
MAX_INT |
static Integer |
MinusOneInteger |
static Class[] |
NotificationClassArray |
static Class[] |
ObjectClassArray |
static BigDecimal |
OneBigDecimal |
static Integer |
OneInteger |
static NSArray |
SingleNullValueArray |
static Class[] |
StringClassArray |
static Integer |
ThreeInteger |
static Integer |
TwoInteger |
static BigDecimal |
ZeroBigDecimal |
static Integer |
ZeroInteger |
Constructor and Description |
---|
ERXConstant() |
Modifier and Type | Method and Description |
---|---|
static ERXConstant.Constant |
constantForClassNamed(Object value,
String clazzName)
Retrieves the constant for the given class name and value.
|
static NSArray |
constantsForClassName(String clazzName)
Retrieves all constants for the given class name ordered by value.
|
static Integer |
integerForInt(int i)
Returns an Integer for a given int
|
public static final int MAX_INT
protected static Integer[] INTEGERS
public static final Object EmptyObject
public static final String EmptyString
public static final NSArray EmptyArray
public static final NSArray SingleNullValueArray
public static final NSDictionary EmptyDictionary
public static final Integer MinusOneInteger
public static final Integer OneInteger
public static final Integer ZeroInteger
public static final Integer TwoInteger
public static final Integer ThreeInteger
public static final BigDecimal ZeroBigDecimal
public static final BigDecimal OneBigDecimal
public static final Class[] EmptyClassArray
public static final Class[] NotificationClassArray
public static final Class[] ObjectClassArray
public static final Class[] StringClassArray
public static final Object[] EmptyObjectArray
public static final NSData EmptyImage
public static NSArray constantsForClassName(String clazzName)
clazzName
- public static ERXConstant.Constant constantForClassNamed(Object value, String clazzName)
value
- clazzName
- public static Integer integerForInt(int i)
Copyright © 2002 – 2024 Project Wonder.