Re: Type of a generic class?

Discussion in 'Java' started by markspace, Aug 2, 2012.

  1. markspace

    markspace Guest

    On 8/2/2012 12:04 PM, Donkey Hottie wrote:

    > First problem I have is to translate the type to a lower level
    > application API call. I can not leave the cast or type conversion to
    > compiler only.



    I'm going to ignore other obvious problems and simply focus on the big
    picture here. You idea how to accomplish this looks *TERRIBLE*. Why
    aren't you using some kind of ORM? At least use a light-weight library
    for translating data base entities into objects.

    <http://commons.apache.org/dbutils/>

    Also JPA will do some kinds of automatic instantiation for you:

    <http://openjpa.apache.org/builds/1.0.4/apache-openjpa-1.0.4/docs/manual/jpa_overview_mapping_inher.html>

    I didn't check to see if those are the most recent docs (I don't use
    this sort of feature). Google for "JPA table inheritance" and check
    through the results carefully.


    > Class is a simple version containg only the important parts.



    Honestly, while we all appreciate the attempt, you example is far from
    complete. We can guess at a few things, but you should think much more
    carefully at what the real problem is and design something to illustrate
    it.
    markspace, Aug 2, 2012
    #1
    1. Advertising

  2. markspace

    Lew Guest

    Donkey Hottie wrote:
    > markspace kirjoitti:
    >> ...


    > I am trying to convert a simple { String name, String value } pair in


    How about a Map<String, Global<?>>

    Also, you should move that if-chain reflection out of your app and
    use polymorphism instead.

    > database to a Global<T>(name) so that it will convert the Java simple
    > datatypes to a string and back. This is for system parameters,
    > configuration parameters.
    >
    >> It is indeed kind of spooky and strange idea, after all what is so wrong
    >> about simple

    > String value = SystemProperties.getString("ParamName") ;
    >
    > It is OK, but I'm kind of toying with idea of strong typing of System
    > Parameters: A Date can not be stored as Long or Double etc..


    Using strings to look up types is not strong typing.

    >
    > The back end of the system parameters is simply
    >
    >
    >
    > CREATE TABLE SystemParameters
    > (
    > name varchar(64) not null primary_key,
    > value varchar(512)
    > ) ;
    >
    >
    > That's it. That is have the table is given to me. But I want to make the
    > Java code bit more pedantic on the types of the parameters it uses and
    > maintains.


    JPA does that for you, too.

    Anyway, your use of reflection is anti-pedantic.

    --
    Lew
    Lew, Aug 3, 2012
    #2
    1. Advertising

  3. markspace

    markspace Guest

    On 8/2/2012 4:27 PM, Donkey Hottie wrote:

    > It is indeed kind of spooky and strange idea, after all what is so wrong
    > about simple
    >
    > String value = SystemProperties.getString("ParamName") ;
    >
    > It is OK, but I'm kind of toying with idea of strong typing of System
    > Parameters: A Date can not be stored as Long or Double etc..



    To do something like this, I'd arrange some implementation for the
    parameter:

    class Parameter {
    public void processParam( String param ) {
    double d = Double.parse( param ); // or whatever...
    ...
    }
    }

    And then use a Map as Lew suggests or some other method of binding the
    Parameter class to the string "ParamName".

    (You could, for example use Class.forName():
    Parameter proc = Class.forName(
    "my.project.parameter."+"ParamName").newInstance();

    or you could use annotations:

    @Parameter("ParamName")
    class Parameter {...

    or any other crazy thing you like. It would probably be better than
    what you have now.)


    > The back end of the system parameters is simply
    >
    > CREATE TABLE SystemParameters
    > (
    > name varchar(64) not null primary_key,
    > value varchar(512)
    > ) ;



    I've written this table definition. In fact it was 23 odd years ago, as
    in intern while still in college. I don't know if it's good or bad
    practice, but it seems a common idea.
    markspace, Aug 3, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    502
    moongate
    Jan 18, 2005
  2. Purush
    Replies:
    4
    Views:
    1,608
    Purush Rudrakshala
    Apr 13, 2005
  3. Replies:
    2
    Views:
    424
  4. minlearn
    Replies:
    2
    Views:
    445
    red floyd
    Mar 13, 2009
  5. Daniel Thoma
    Replies:
    12
    Views:
    1,925
    markspace
    Jul 31, 2009
Loading...

Share This Page