data transporting questions

R

Rizwan

For each table in my database, I have created a seperate class (java-beans
style) whose attributes matches to the columns of its table. If its a
foreign key then the datatype is actually another class.

CREATE TABLE LOCATION (
location_id int NOT NULL PRIMARY KEY,
location_name varchar(50) NOT NULL,
location_flag int NULL )

CREATE TABLE EMPLOYEE (
employee_id int NOT NULL PRIMARY KEY,
first_name varchar(25) NOT NULL,
middle_name varchar(25) NULL,
last_name varchar(25) NOT NULL,
location_id int NOT NULL REFERENCES LOCATION(location_id) )

Then my classes are :

public class Location implements java.io.Serializable {
private int locationId;
private String locationName;
private Integer locationFlag;

public Location() {}

// Setters and Getters
...
}

public class Employee implements java.io.Serializable {
private int employeeId;
private String firstName;
private String middleName;
private String lastName;
private Location location;

public Employee() {}

// Setters and Getters
...
}

The reason for creating these classes is that for each data request, the
data can be passed in the shape of these classes. For that the logic I have
in my mind is :
* data will be first retrieved in a resultset
* the concerned class's object is instantiated
* its attributes are populated through its setters
* the object is passed to the data request module

Now I have some questions:

1) Taking Employee example sometimes the data request is only concerned
about Employee data (EMPLOYEE table only) and some time it is concerned
about the corresponding Location data as well (EMPLOYEE and LOCATION table).

Should I pass Employee class in both cases?
Or Should I create another class which is same as Employee class but with no
Location class reference and pass this new class?
public class EmployeeRaw implements java.io.Serializable {
private int employeeId;
private String firstName;
private String middleName;
private String lastName;
private int locationId;

public Employee() {}

// Setters and Getters
...
}

2) Sometimes the data request cannot be represented in a class which
represents a table. Its a combination of more than one class (here class
means one which strictly represents a table). What is the solution in this
case?

3) In the above scenario Employee class has Location class which has no
other class. I will call this as 1 level deep. But there are some scenarios
where a class has another class which in turn also has some class. Its like
more than 1 level deep. In this scenario what is the recommended practice
regarding retrieval?


Thanks
 
M

MSL

From a consistency point of view, I think the class based data set should be
as complete as possible, so as to keep the handling code as straightforward
as possible. I mean, all of the references should always be resolved.
Obviously this way could quickly lead to a rather complex structure when you
have a model with several nesting levels.
In this case I think the MVC model may help: keeping to this paradigm rules,
you will have as many different presentation sets as needed (i.e. different
views), each containing just the pieces of information pertaining to it. In
other words you keep just one copy of the whole data set, breaking it into
smaller lumps depending on presentation and use needs.

Of course this is just my opinion...

Regards

MSL
 
W

Wibble

MSL said:
From a consistency point of view, I think the class based data set should be
as complete as possible, so as to keep the handling code as straightforward
as possible. I mean, all of the references should always be resolved.
Obviously this way could quickly lead to a rather complex structure when you
have a model with several nesting levels.
In this case I think the MVC model may help: keeping to this paradigm rules,
you will have as many different presentation sets as needed (i.e. different
views), each containing just the pieces of information pertaining to it. In
other words you keep just one copy of the whole data set, breaking it into
smaller lumps depending on presentation and use needs.

Of course this is just my opinion...

Regards

MSL
1. Code generate these classes. You can parse the output of:

sql> describe tableName

You can probably code generate the data mapper to this class too.

2. Dont embed the pointer to location in employee, create a composite.

class EmpLoc {
Employee employee;
Location location;
}
 
R

Rizwan

I have looked at Hibernate. But in our company third-party products are not
allowed. So I cant use it.
 
J

John Currier

You're joking, right? Does your management realize that Java is a
"third-party product"? Do you write your own operating systems, news
readers and/or web browsers? You mentioned a database in your initial
post...did your company write that?

John
 
R

Rizwan

When I said third-party products I mean the free ones which are not the part
of the product. So java is the language we are using so everything from Sun
is ok. But Hibernate is not from Sun, its free (which is good for developers
by the way but company thinks it as a negative) and also it is not a product
which implements a specification. We are not even using Struts although it
implements MVC pattern.
 
J

John Currier

I'm really dumbfounded on that one...I thought I had to deal with
bureaucracy in my job.

Is it possible that one of the JBoss products are for sale and if you
bought that product then you'd then be allowed to use any of their free
products?

I personally would be visiting dice.com and monster.com. Those rules
imply a much deeper problem in your company.

John
 
J

John Currier

I think you can "buy" Hibernate from JBoss if you bundle it with a
support aggreement.

John
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top