Mapping static constant objects.

hi all,
Briefly describe, I have the following classes :
public class Status
public final Status OPEN_STATUS = new Status("OPEN");
public final Status CLOSE_STATUS = new Status("CLOSE");
String name;
private Status(String pName)
this.name = pName;
public String getName() {....};
public boolean equals(...); /* override to compare name only */
public class Order
Status status;
/* with getter and setter and linked to either Status.OPEN_STATUS
* or Status.CLOSE_STATUS.
With the above structure, how should I map it in JDO so that it doesn't
create new instances of the Status obj in the database table whenever I
insert a new Order?
Currently, both of the class is set to use database entity. And Status in
Order class is set to be not embeded.
Does "Application entity" setting has any effect in this case?
Joseph

Abe White,
Thanks for the quick reply.
Joseph
Abe White wrote:
See my changes to your code inline. This is only one suggestion, but
this pattern shoudl work for you
// Status should be a non-persistent class in this setup, so delete
// your JDO metadata for it
public class Status
public final Status OPEN_STATUS = new Status("OPEN"); public final
Status CLOSE_STATUS = new Status("CLOSE");
String name;
public static Status forName(String pName)
if(OPEN_STATUS.getName().equals(pName))
return OPEN_STATUS;
if(CLOSED_STATUS.getName().equals(pName))
return CLOSE_STATUS;
return null;
private Status(String pName)
this.name = pName;
public String getName() ;
public boolean equals(...); /* override to compare name only */
public class Orderimplements javax.jdo.InstanceCallbacks
{// this field should now be non-persistent; put:
// persistence-modifier="none" in its JDO metadata
Status status;
// this field is persistent
private String statusName;
public void jdoPreStore()
this.statusName = (this.status == null) ? null
: this.status.getName();
public void jdoPostLoad()
this.status = Status.forName(this.statusName);
// rest of InstanceCallbacks methods implements as no-ops
// rest of class ...

Similar Messages

  • Excessive use of 'static' in Objects

    Hello all,
    I have inherited a code base which consists of around 90 objects seemingly randomly thrown together in a down and dirty effort to crank out working code as soon as possible. The original programmer has left the company and I've inherited his projects. While attempting to isolate some performance shortcomings I noticed that nearly every single class has a static method of some sort or another. My understanding is that this is clearly a bad idea as, if for no other reason, those objects, having a static method, will exist during the entire lifetime of the application and are not candidates to be GC'd. Furthermore these objects contain many String instances which, if the object that contains them isn't ever eliminated, will remain as huge memory hogs as well.
    So, in essence, what are the general thoughts of the architects and developers on this board regarding the use of the 'static' keyword and it's effect on Object design and the implications for performance and memory? Any feedback would be greatly appreciated. I have looked through numerous books on OO design but nobody seems to speak directly to the implications and "best practices" of designing with the 'static' keyword, where, when and how it's most effectively used, etc.
    Thanks!

    Hi,
    would you consider that the primary motivation for use of static, that the method in question use only class member variables?Often yes, but not always. The example given by jschell above is typical of a static method, but you can't always make methods static like this. If isDefined(String s) were specified by an interface (it couldn't be private in this case though), to implement different variants of what it means for a String to be 'defined', then you couldn't make the method static even if it did not depend on the object you are calling it on.
    However I am still looking for a good "rule of thumb" that will help me to determine what the most appropriate use of the static keyword is/should be.For methods you should ask yourself "How will the method be called?" If it only makes sense to call it on an instance of the object then DON'T make it static, even if it could be. Static methods should only be called like this:
       ClassName.staticMethod();and not like this:
       instanceOfClass.staticMethod();as this second style of invocation is very misleading (and it really winds me up when I see it!).
    As for fields - in my own code I tend to have private static final objects for constants or 'collections' that are used by many instances, or which are available through public static utility methods. Immutable static final fields I often make public. Pretty much everything else is non-static. I have no idea whether this is 'best practice' though.
    You may also want to look at the java.util.Collections and java.util.Arrays classes. These cannot be instantiated and provide only static utility methods for manipulating other objects. It can sometimes help to split off the static 'utility' functions into another class like this, especially if common functions can be applied to an interface.
    Ol.

  • C++ STL library error: Non-const function ... called for const object

    Hello,
    I'm using the Forte Developer 6 Update 2 C++ compiler and standard library on Solaris 9 SPARC. I've installed the recommended patch set for C++ (both the workshop and platform patches).
    In my code, I have a STL set with some elements that I want to modify, say:
    typedef set<SomeClass> MySet;
    typedef MySet::iterator MySetIter;
    I'm trying to look for an element, then update some of its fields:
    MySet theSet;
    SomeClass sci;
    MySetIter it = theSet.find(sci);
    if (it != theSet.end()) {
    it->update_some_fields();
    The above code fails with the following error (some details scrapped):
    Error: Non-const function SomeClass::update_some_fields() called for const object
    Which is weird, since set::find() seems to return a set<...>::iterator, not a set<...>::const_iterator!
    If I try a workaround, like this:
    if (it != theSet.end()) {
    SomeClass &tmp = *it;
    tmp->update_some_fields();
    I get this other error:
    Initializing SomeClass& requires an lvalue.
    Is there some way to convince the Forte compiler to work around this situation (most likely a compiler / library bug)?

    This was fixed, too, by replacing the set with a map. It seems that the issue was related to the fact that any change made to a set member is supposed to not modify the elements that make up the key (the elements that are used in the comparison function to determine the ordering). The Windows (dinkumware) implementation of the STL allows set modifications, though I don't know how they check that the key fields are not modified. The Solaris implementation (and the GNU implementation, too) disallows any modifications made to set members. At least that's what a person more knowledgeable of C++ in our office found out. So I don't think the issue was related to template constructors or any unimplemented features after all.

  • Selection dynamic Mapping Runtime Constant with a qualifier

    Hello all,
    i want to access a Mapping Runtime Constant out of a message mapping specified with a qualifier.
    In the Integration Directory i specified in the identifier tab the following Value Pairs:
    Agency               Scheme          Name
    http://Sap.com/xi/XI    XIParty         ABC
    R3D_310                 Partner         111
    R3T_310                 Partner         222
    R3P_310                 Partner         333
    In the message mapping i want to have the Name for the agency "R3T_310".
    I know i can access the Name with:
    constant = (String) map.get(StreamTransformationConstants.SENDER_PARTY);
    But i getting everytime the name "ABC", which i don't want.
    At this point i need your help, to find out how i can dynamically get the correct one??
    many thanks for your help
    ilka

    Ilka,
    You can also access other Mapping Runtime constants. For example, SENDER_PARTY_AGENCY.
    If needed, you can also access SENDER_PARTY_SCHEME and SENDER_SERVICE.
    The SAP Help link for all the Mapping Runtime constants accessible with StreamTransformationConstants is:
    http://help.sap.com/saphelp_nw04/helpdata/en/78/b4ea10263c404599ec6edabf59aa6c/frameset.htm
    Hope this helps,
    Bhanu

  • Core Data Services in ABAP : No URI-Mapping defined for object type DDLS

    Hi ,
    When creating a DDL source , I get the error
    " No URI-Mapping defined for object type DDLS and object name ZCDSV_01_06".
    Can you please suggest what the issue could be?
    Thanks,
    Chakram Govindarajan

    Now I am able to proceed to the next step. Not sure how this started working. However, I get the below error when I open the DDL source editor for one particular ABAP system added in the eclipse environment. I however do not get the error when I open the DDL source editor for another system ( AH4) .I am providing the log error details . I updated the ADT installation. However the issue has not been resolved. Also I tried implementing the Note: 1834948. However I cannot find the option "Team -> Share project..." in the ABAP project.
    Thanks,
    Chakram Govindarajan

  • Threaded Queries from Single static Connection object - Good approach?

    Hi,
    I need to generate a report where I need to query count(1) from over one hundred tables from oracle 10g database. I am not updating or deleting any record.
    My approach is to use a single static connection object and create one thread for each table and capture the result back into a static hashtable.
    But still, I am not getting any substantial performance improvement. Earlier, my report took 40 minutes, when it was non-threaded and now it takes 30 minutes.
    Is there anything more I can do to make my report get the counts faster? Will a connection pool help?

    Tolls wrote:
    jschell wrote:
    I was told by the DBA that count(1) works faster than count(*)....that's why....Unlikely. Certainly not true in current versions of Oracle if that is the source.Not unlikely, actually not true. Beneath the hood Oracle turns a count(1) into a count(*) in order to deal with this. Why? Because count(1) is turned into count(*) in order to avoid it being slower (Oracle 7 was the last time count(1) was different). And the reason generally given is because so many people were mistakenly using count(1) thinking it performed better that they decided to put in the "conversion" to fix the silly queries.
    I think this it the [Ask Tom|http://asktom.oracle.com/pls/asktom/f?p=100:11:109792721681931::::P11_QUESTION_ID:1156159920245] link I used last time this came up here.
    I knew all that, but I missed that the OP had specified the database vendor and version.

  • Oracle proc Pro*C, g++/c++ compile error due to static const unsigned int sqlctx

    I'm using Oracle 8.1.6 for Linux, and 7.3.4 on HP-UX. Compiler is gcc/g++ 2.95.2
    In working with the Oracle precompiler on both HPUX and Linux, I've found a problem with the way that the Linux precompiler generates the sqlctx variable.
    On linux, the following is generated when you run the precompiler:
    static const unsigned int sqlctx = 1;
    However, on HPUX, this is the corresponding code:
    static unsigned long sqlctx = 10673468;
    When you compile the Linux version with g++/c++ or aCC, you get fatal errors of this nature:
    SQLSubsystem.cpp:562: passing `const unsigned int *' as argument 2 of `sqlcxt(void **, unsigned int *, sqlexd *, const sqlcxp *)' discards qualifiers
    Is there a way to force the output of proc to leave off the const?
    If you view the binary file proc, you can find the static unsigned int string listed. So I think it may be an option. However, I can't seem to turn it on.
    Thanks-
    Matt Wright

    As for sqlctx:
    sqlctx is a module identifier variable. i.e. if your project consists of multiple modules, each sqlctx should have different value.
    I have seen this error only on Linux Pro*C starting of 8.1.5 version (have not tested 8.0.5 nor 8.1.6).
    Anyway, I really can not understand why this error is not patched already.
    As for constness:
    I can not tell if there is an option which would solve such issue. I can only advise not to use -Werror option of gcc. It generates about 4-5 warnings per module, but it works ;-))

  • No mapping exists from object type Telerik.Web.UI.RadMaskedTextBox to a known

    hi for all i got this problem when i try to update record in a database actually it's first
    time happining with me
    No mapping exists from object type Telerik.Web.UI.RadMaskedTextBox to a known
    managed provider native type
    and this is my code
    SqlCommand cmd = new SqlCommand("update RealEstate set DestinationEntity=@speechDirect,FULLName=@name,Individual_Iqama_NR=@egamhNo,Individual_Passport_NR_ID=@passport,Individual_Gender=@six,Individual_Sociall_Status=@martialstate,Individual_Passport_Issue_Date=@passportdate,Individual_Nationality_ID=@nationality,IqamaIssued_From=@egamhsource,Total_Staying_Time_KSA=@stayduration,Individual_Work_Address=@workdisc,Possess_Type=@omntype,Apartment_No=@estateno,Apartment_Floor_No=@storyno,Possess_City_ID=@city,QuarterID=@area,Deed_No=@InstrumentNo,Deed_Date_HijriAfter=@Instrumentdate,Deed_Issue_City_ID=@Instrumentsource,Request_Status=@orderstate,Real_Estate_Area=@estatespace,[notes]=@notes,Incomming_No=@waredno,Incomming_Date_HijriAfter=@wareddate,Qaied_No=@ghaidno,Qaied_Date_HijriAfter=@ghaiddate,ExportNumber=@jihtsdor, ExportDateHijriAfter=@job where Possess_ID=@id", _con);
    cmd.CommandType = CommandType.Text;
    _con.Open();
    cmd.Parameters.AddWithValue("@id", int.Parse(Request.QueryString["Serial"].ToString()));
    cmd.Parameters.AddWithValue("@speechDirect", RadComboBox1.SelectedValue);
    cmd.Parameters.AddWithValue("@name", txtname.Text);
    cmd.Parameters.AddWithValue("@egamhNo",txtegamhno.Text);
    cmd.Parameters.AddWithValue("@passport", txtpassportno.Text);
    cmd.Parameters.AddWithValue("@six",RDSix.SelectedValue);
    cmd.Parameters.AddWithValue("@martialstate", Rdstatus.SelectedValue);
    cmd.Parameters.AddWithValue("@passportdate", DateTime.Now);
    cmd.Parameters.AddWithValue("@nationality", RdNationality.SelectedValue);
    cmd.Parameters.AddWithValue("@egamhsource", txtegamhsou.Text);
    cmd.Parameters.AddWithValue("@stayduration", txtstayduration.Text);
    cmd.Parameters.AddWithValue("@workdisc", txtjobdirec.Text);
    cmd.Parameters.AddWithValue("@omntype", RdownType.SelectedValue);
    cmd.Parameters.AddWithValue("@estateno",txtflatNo.Text);
    cmd.Parameters.AddWithValue("@storyno", txtstoryNo.Text);
    cmd.Parameters.AddWithValue("@city", RDcity.SelectedValue);
    cmd.Parameters.AddWithValue("@area", RadComboBox2.SelectedValue);
    cmd.Parameters.AddWithValue("@InstrumentNo",txtskno.Text);
    cmd.Parameters.AddWithValue("@Instrumentdate", txtskdate.Text);
    cmd.Parameters.AddWithValue("@Instrumentsource", Rdsksource.SelectedValue);
    cmd.Parameters.AddWithValue("@orderstate", Rdordercase.SelectedValue);
    cmd.Parameters.AddWithValue("@estatespace",txtspace.Text);
    cmd.Parameters.AddWithValue("@notes", txtcomments.Text);
    cmd.Parameters.AddWithValue("@waredno",txtwaredno.Text);
    cmd.Parameters.AddWithValue("@wareddate", txtkitabno.Text);
    cmd.Parameters.AddWithValue("@ghaidno", txtgaidno.Text);
    cmd.Parameters.AddWithValue("@ghaiddate",txtghaiddate.Text);
    cmd.Parameters.AddWithValue("@jihtsdor",Rdsksource.SelectedValue);
    cmd.Parameters.AddWithValue("@job", txtsaderdate);
    int x =cmd.ExecuteNonQuery();
    any one could provide suggestion to solve this problem
    thanks

    Hello,
    I would like suggest you posting it to:
    http://www.telerik.com/support
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • IWeb and constant objects.

    Is this possible not changing my constant objects e.g. header or my logo or some stripes etc ( reload again on my next pages) I would like to reload only content, not the whole page again and again. Maybe someone html guru knows how. Thanks for the future help.

    Suz, I think Eugene is thinking of having all the shared assets such as PNGs, JPGs and what not to be kept in the same folder so the browser uses its cache instead of loading images page after page.
    However, I had put that idea to sleep long ago
    http://discussions.apple.com/thread.jspa?messageID=1967646&#1967646
    http://discussions.apple.com/thread.jspa?messageID=3799379&#3799379
    It could be done though.

  • Instantiation of static final objects

    Is there a problem with coding the following?:
    class A {
    public static final A static_final_a_obj = new A ( B.static_final_b_obj );
    private B b;
    public A ( B b ) {
    this.b = b;
    class B {
    public static final B static_final_b_obj = new B ( A.static_final_a_obj );
    private A a;
    public B ( A a ) {
    this.a = a;
    I put log messages in each of the constructors to see if it would cause an infinite loop, but it doesn't seem to. The question is 'why'.. :) How can either of the static final objects ever be fully instantiated?

    Exactly. It is not executed infinitely.
    class A {
    public static final A static_final_a_obj = new A ( B.static_final_b_obj );
    private B b;
    public A ( B b ) {
    System.out.println(" A Cons");
    this.b = b;
    public static void main(String args[]) {
         System.out.println("A");
    Output:
    B Cons
    A Cons
    A
    class B {
    public static final B static_final_b_obj = new B ( A.static_final_a_obj );
    private A a;
    public B ( A a ) {
    System.out.println(" B Cons");
    this.a = a;
    public static void main(String args[]) {
         System.out.println("B");
    Output:
    A Cons
    B Cons
    B
    Edited by: prajeshps on Sep 18, 2007 1:51 PM

  • Use reflection to access static constant

    I have a class with a static constant value. Can somebody show me to access the constant value using reflection.
    Thanks
    Regards,
    Stephen

    I have class
    public class one{
    public static final String TABLE_KEY = "something";
    to access the class
    one.class.getField(">>what to put here<<") it's static method don't hv any getter method???

  • Using static constants as id in FXML

    Is it possible to use a static constant as the id in FXML, and if so how ?
    For example if i have a class Person with a static constant defined, such as:
    static final String NAMEFIELD = "name";
    And then in an FXML file:
    <?import Person?>
    <TextField id=Person.NAMEFIELD />
    The above FXML code generates an error saying that an " is exspected.
    I've also tried with "$Person.NAMEFIELD" but that doesn't seem to work either.
    Any suggestions ?

    Is it possible to use a static constant as the id in FXML, and if so how ?Yes, this is supported in JavaFX 2.2:
    <TextField>
      <id><Person fx:constant="NAMEFIELD"/></id>
    </TextField>
    The above FXML code generates an error saying that an " is exspected.Quotes are required. FXML must be syntactically valid XML.

  • Deleting a pointer to a constant object

    I have code in C++ compiled under Sun WorkShop C++ Compiler 5.0 that is able to delete a pointer to a constant object e.g const int * ptr ;
    I'm able to delete it, using delete ptr;
    This just a trivial example ... but I'm able to delete a pointer to any constant object. I'm relatively new to C++ so this is very confusing that it should allow me to do so. When I compile the same code in Microsoft VC++ the compiler catches it rightfully saying that it cannot overload the delete operator with a pointer to a constant or something like that ... So my question is is this an anamoly in Sun compiler ... or does the C++ standard loosely defined as to what should happen(. I thought you couldn't overload a delete operator with pointert to a constant) or maybe my shop needs a patch that will solve this problem .... ?
    Just tried on Forte same thing happened.
    Please Help.

    Yes, it is valid to delete a const object. C++ Standard, section 5.3.5, paragraph 2:
    "Note: a pointer to a const type can be the operand of a delete-expression; it is not necessary to cast away the constness"
    The reason is that since you created the object dynamically, you can remove itdynamically as well. You are just not allowed to change its value while it exists.

  • Getting static constants of a class

    hi I have this class:
    package cl.mejorencasa.pedido.modelos
         public class Pedido implements IPedido
            public static const     ENESPERA:String   = "En Espera";
            public static const     ATENDIENDO:String   = "Atendiendo";
            public static const     ENCOCINA:String   = "En Cocina";
            public static const     FUERADECOCINA:String   = "Fuera de Cocina";
            public static const     ENCAMINO:String   = "En Camino";
            public static const     ENTREGADO:String   = "Entregado";
            public static const     PERDIDOPORREPARTIDOR:String   = "Pérdida por Repartidor";
            public static const     PERDIDOPORCOCINA:String   = "Pérdida por Cocina";
            public static const     CANCELADOPORCLIENTE:String   = "Cancelado por Cliente";
            public static const     CANCELADOPORFALTADEPRODUCTOS:String   = "Cancelado Falta Stock";               
    what I want to do is to create a method that gets all the constants of that class and return them in a ArrayCollection. I must say that I want this method to be dynamic, what I mean is that I want it to go through every constant that are in the class. I don't wan't  to add them my self into an ArrayCollection.
    The problem is that I don't know how create such a metho, can someone help me?
    Thanks a lot.
    Sebastián Toro

    To see the statics, I think you have to pass the class itself, rather than an instance of the class, to describeType(). So try
    describeType(Pedido);
    Gordon Smith
    Adobe Flex SDK Team

  • [svn:fx-trunk] 10891: Fix for ASDoc throws error when using getter methods for pseudo-inheritance of static constants

    Revision: 10891
    Author:   [email protected]
    Date:     2009-10-06 09:46:47 -0700 (Tue, 06 Oct 2009)
    Log Message:
    Fix for ASDoc throws error when using getter methods for pseudo-inheritance of static constants
    QE notes: None.
    Doc notes: None
    Bugs: SDK-22676
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22676
    Modified Paths:
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocUtil.java

    Have you tried using com.adobe.air.crypto.EncryptionKeyGenerator instead?

Maybe you are looking for