wood burning stoves*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes about the data model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "about the data model" Watch "about the data model" New topic
Author

about the data model

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi
I am working on displaying data into JTable, using the DataModel extends AbstractTableModel.
In order to get table data from db file, I going to create an instance of Data class in this DataModel class, and do all the data processing in there as well.
I am wondering it is a good idea or not.
please help,

lili
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar
Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Originally posted by Ramesh kumaar:
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar

Hi Ramesh,
Can you give more details?
The way I have implemented is as follows: (not sure where design pattern can be applied !)
(a) CSR (Serice Representative) searches for a "Specialty"
(b) The Data class finds for all "Contractors" who match the specified specialty
(c) The Data class returns an array of objects - of type "DBResultSet" (I have given the definition below).
public class DBResultSet {
public int recno;
public String name;
public String location;
public String specialties;
public String size;
public String rate;
public String owner;
}
I added the following method in the Data class :
public DBResultSet[] find(String criteria) throws RecordNotFoundException {
...
}
(d) In the Swing application, read all the elements from the DBResultSet array and update the JTable model.
With the Beta almost over, I need to complete the assignment faster and start documentation !
Your advice on using design patterns in above code / functionality would be great !
Regards,
Dayanand.
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi li li
I feel creating the instance of the Data class directly in your view class is a bad design. Better u read Factory pattern, Abstract pattern, Facade pattern, which will help u design ur project well.
-rameshkumar
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi Daya,
I think there is no need of having DataResultSet class as u have, because read() method of DBMain returns String[] which can be used strightaway in DefaultTableModel without
any change.
In my case DBMain.java is the interface which has all the methods that was given by sun. I have an implementation class which is named as DBMainImpl.java. Now to access the DB i have a class DBAccess.java which extends DBMainImpl.java and implements DBAccessInterface.java which has the following methods update, lock,unlock,search. The above interface is implemented by another interface named RemoteDBAccessInterface which acts as the remote interface in our project. Here i just instantiate DataAccess.java for remote clients.
Hope this may help.
Goodluck.
rameshkumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about the data model
 
Similar Threads
JTable refreshment -- or was that 7up?
Models & Arrays
[JSF 2] Update the total of a column from a dataTable
Models & Arrays
doubts on MVC