For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > August 2004 > pattern for representing read-only data in app-tier









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author pattern for representing read-only data in app-tier
Grzegorz Trafny

2004-08-25, 9:00 am

Hi,

Problem:
I think how I should represent into "model tier"
data from "dictionary [read-only] table" from
"database tier".

Example of situation:
I have 2 tables:
1) t_accounts
2) t_roles

Inside 't_accounts' table I store data about persons
registered in my application. In "model tier" I represent
this data as CMP beans.

Inside 't_roles' table I store data about 'security roles'
used in my appliaction (every account can have many
roles). This table is "read-only" (or as you wish
"dictionary table" :)

Question:
How (better) I should represent data from 't_roles'
inside "model-tier"? As CMP, POJO bean, or better
manualy read contents of rows by JDBC?

Thanks && Greetings
Grzegorz Trafny








Grzegorz Trafny

2004-08-26, 8:56 am

> I think how I should represent into "model tier"
> data from "dictionary [read-only] table" from
> "database tier".


In Hibernate documentation (Reference, chapter 5.2.3)
I saw interesting construction which let to model persistent
(small) enum types. It's can be helpful during mapping
"dictionary tables" [from database tier] on objects [from
model tier]
It'a part of their example (without dd etc)

<code>
import net.sf.hibernate.PersistentEnum;

public class Color implements PersistentEnum {

private final int code;

private Color(int code) {
this.code = code;
}

public static final Color TABBY = new Color(0);
public static final Color GINGER = new Color(1);
public static final Color BLACK = new Color(2);

public int toInt() { ... }

public static Color fromInt(int code) { ... }

}
</code>


But how I can build such "persistence enurerator" in
CMP techmnology. To get code like:
<code>
public class Color implements EntityBean {
... ??? ...
}
</code>

Currently I use ordinary CMP bean without
'create' methods but this looks strange for me.

Any idea?

Greetings






Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com