Project Wonder 5.0

er.extensions.eof
Class ERXConstant

java.lang.Object
  extended by er.extensions.eof.ERXConstant

public abstract class ERXConstant
extends java.lang.Object

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");
 }
 

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.


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

MAX_INT

public static final int MAX_INT
See Also:
Constant Field Values

INTEGERS

protected static java.lang.Integer[] INTEGERS

EmptyObject

public static final java.lang.Object EmptyObject

EmptyString

public static final java.lang.String EmptyString
See Also:
Constant Field Values

EmptyArray

public static final com.webobjects.foundation.NSArray EmptyArray

SingleNullValueArray

public static final com.webobjects.foundation.NSArray SingleNullValueArray

EmptyDictionary

public static final com.webobjects.foundation.NSDictionary EmptyDictionary

MinusOneInteger

public static final java.lang.Integer MinusOneInteger

OneInteger

public static final java.lang.Integer OneInteger

ZeroInteger

public static final java.lang.Integer ZeroInteger

TwoInteger

public static final java.lang.Integer TwoInteger

ThreeInteger

public static final java.lang.Integer ThreeInteger

ZeroBigDecimal

public static final java.math.BigDecimal ZeroBigDecimal

OneBigDecimal

public static final java.math.BigDecimal OneBigDecimal

EmptyClassArray

public static final java.lang.Class[] EmptyClassArray

NotificationClassArray

public static final java.lang.Class[] NotificationClassArray

ObjectClassArray

public static final java.lang.Class[] ObjectClassArray

StringClassArray

public static final java.lang.Class[] StringClassArray

EmptyObjectArray

public static final java.lang.Object[] EmptyObjectArray

EmptyImage

public static final com.webobjects.foundation.NSData EmptyImage
an empty gif image

Constructor Detail

ERXConstant

public ERXConstant()
Method Detail

constantsForClassName

public static com.webobjects.foundation.NSArray constantsForClassName(java.lang.String clazzName)
Retrieves all constants for the given class name ordered by value. An empty NSArray is returned if the class isn't found.

Parameters:
clazzName -

constantForClassNamed

public static ERXConstant.Constant constantForClassNamed(java.lang.Object value,
                                                         java.lang.String clazzName)
Retrieves the constant for the given class name and value. Null is returned if either class or value isn't found.

Parameters:
value -
clazzName -

integerForInt

public static java.lang.Integer integerForInt(int i)
Returns an Integer for a given int

Returns:
potentially cache Integer for a given int

integerForString

public static java.lang.Integer integerForString(java.lang.String s)
                                          throws java.lang.NumberFormatException
Returns an Integer for a given String

Returns:
potentially cache Integer for a given String
Throws:
java.lang.NumberFormatException - forwarded from the parseInt method off of Integer

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.