Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Tier Design using and  RSS feed

Sudhansu Pati
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Andrew, Vlad, Philippe, Bharat, Arun, Ulrich, Marc, Peter
I have been reading your design approaches for Database Tier. The design I have chosen is kind of unique and I don't think there is a thread for that. I am looking for your opinion. Do you think someone can fail for over simplifying the design ?
I have only two classes. and inplements the sun provided interface
All methods except create(), lock(), unlock(), isLocked(), find() are synchronized. That confirms that only one client can operate on the synchronized methods of an instance of the Data object.
create method is not synchronized because I have kind of implemented the lock,create,unlock algorithm itself within the create method. So many threads can call the create method on the same object, but it still be thread safe.
update, delete methods requre lock-update-unlock, lock-delete-unlock anyway. update and delete are synchronized because 2 threads (one calling on update and one calling on delete for different records) don't operate at the same time.
Data creates a static instance of DataHelper as follows.

The looks as follows.
All methods are synchronized except the methods getting the DBSchema related information().
I have created a cache Vector() to store the entire image of the database. I update the cache everytime there is a create, update and delete. The cache is a repositary for all active and deleted recors. Because of the cache I don't have to make the read() method thread safe. read() and find() are much easier and faster.
The DBSchema related information are stored in private variables as follows.

Those variables are populated in a method called CreateCache().

Please let me know if you see any issue with my design. Is sun going to fail me for over simplifying ? Remember I am already a "guine pig" for sticking to 3-tier architecture.
I have thought about RecordModel interface and singleton DBSchema. But they don't really add any value here, unless you can explain how.

[ November 14, 2003: Message edited by: Suds Pati ]
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12100
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suds,
Do you think someone can fail for over simplifying the design ?

I don't believe there is any way you can fail for having a very simple design.

Having said that, I am very confused with your design. From the test code you posted, I understood that you had an instance of Data class for every connected client.
If that is true, then why have you synchronized any of the methods within Data class? Only one thread will ever call any of it's methods, so the synchronization gains you nothing, has a (small) performance hit, and gives you a false sense of security.
Also, your instantiation of DataHelper is wrong - every time an instance of Data is created, the existing instance of DataHelper will be discarded (and hopefully garbage collected) and a new instance of DataHelper will be created and assigned to dbHelper.
(Alternatively, if you have only one instance of Data class, then there is no need for dbHelper to be static).
With your find() method, do you repeatedly call read() for each record, or do you iterate over the members of the vector directly? If the later, then you may need to synchronize the find method to ensure that no other thread modifies the vector while you are itterating over it.
Regards, Andrew
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!