Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Type of a generic class?

Reply
Thread Tools

Re: Type of a generic class?

 
 
markspace
Guest
Posts: n/a
 
      08-02-2012
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.



 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-02-2012
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
 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      08-03-2012
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need ideas -> generic storage of type registration with unknown type Noah Roberts C++ 1 03-15-2010 11:33 PM
Generic type cast involving wildcard type Daniel Thoma Java 12 07-31-2009 03:57 PM
not just generic type programming,but also parallism generic syntaxprogramming?? minlearn C++ 2 03-13-2009 05:17 PM
generic interfaces with generic methods Murat Tasan Java 1 02-03-2009 12:17 PM
Generic class in a non generic class nramnath@gmail.com Java 2 07-04-2006 07:24 AM



Advertisments