aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database Designs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Database Designs " Watch "Database Designs " New topic
Author

Database Designs

Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi reader,
I had implemented all the public methods of Data class in an interface called DataAccess and this interface is being implemented by a class DatabaseAccess. And I want to proceed my work further with the approach that my local mode will access data by straight away calling the methods of DatabaseAccess class. And for the remote mode I may extend this interface methods with another besides this it will extend Remote interface also. For remote mode RemoteDataAccess class may call upon DatabaseAccess methods.
Is this approach is acceptable ?. And if yes, what I am supposed to do with Data class. I am simply employing its public methods in another class called DatabaseAccess class. Will this approach work ?.
Thank you,
:roll:
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
A lot of people have had two different interfaces, one for local access and one for remote but in truth you only need one. If you design it right, all of your database operations will be the same for either. This really simplifies the client once the database connection is established. But as I said earlier, many have taken the two interface approach and passed. So do what you're most comfortable with.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Dear Morris,
What about Data class ?. Is it OK if I am implementing all the public methods of Data class with the class only with different name. My worry is that should I really bring Data class into operation or shall I implement its public methods on other class. I suddenly do not want to write same code more than once. That is if I had implemented criteriaFind() method in a class then I will not rewrite that code again.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
There is a requirement that you expose all the public methods of the Data class to your clients. Now if you're asking if your implementation class (the class which implements DataAccess) should bypass Data and implement its own add, modify, etc. methods, the answer is no. The implementation class should have access to the Data object probably through a private reference to it. So that when the client calls modify on the DataAccess interface, your implementation class will pass that call on to the Data object. Other than writing pass-through methods on your implementation class (or classes) there should be no need to rewrite any of Data's public methods.
Hope this clarifies it,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
In that case I think we can hit two birds with one arrow. Firstly, there would no need for an interface for the client in local mode. The user can straight away can call the Data class methods. But for Remote we can design the interface which will enable the client to call it its respective methods for desire operations. Tell me is this ok. Secondly, I wanted to how you had manipulated add, modify and delete methods as thay are in this assignment are dummy's. Mark had told me that user need not to call these methods you just have to make call backs to these methods in Data class and that's all. They are her in this assignment because of previous versions. What you have to say regarding this ?.
Thirldy, morris how long did you took to complete your assignment and upload back to sun.
Thank you,.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
I would strongly advise you not to directly call Data in local mode. Doing that creates a serious maintainence problem making extensibility very difficult. You should always make calls to Data through an interface. The point I was trying to make is that you only need one interface for both local and remote modes. But it's OK to create a separate interface for each mode it's just redundant.
For the second point, you will need modify for booking, but add and delete should never be called from your client. They still should be implemented as a requirement of the assignment. For add I just called data.add from my implementations class. For the other two, I first checked the lock manager to see if the lock on the record was owned by "this" and if it was I called the appropriate method on Data; if the lock was not owned, I threw a DatabaseException.
Question 3: Almost exactly four months to the day to upload. I changed my design several times in the beginning because of suggestions from Mark and Peter and added extra features like a ServerEventService that notified clients when the server was going down and provided heartbeats for client confidence. I spent three weeks making sure that I had complied with all coding conventions. Sometimes, I am too much of a perfectionist for my own good!
Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
I got your points over interface. But for modify do you say that I had to code but as if this I will do then it will be against specifications . Because it states "You cannot modify db.db file, but you can move it". As you say modify is for booking , I am not able to clearly unserstand your opinion because once the seats had been booked how can one reduce the seats.The user had to supply negative integers in text field which I think is ulterior. Beside this we also cannot mofify the db.db file. Please suggest me what exactly the thing is. You also write that "I simply called data.add from my implementation class ". Could you please tell me from where exactly did you made this call. I mean to say did you registered any instance with listener. Such that for demo purpose you called this data.add in Data class. Did you employed same case with modify, and delete ?.
Thank you,
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

But for modify do you say that I had to code but as if this I will do then it will be against specifications . Because it states "You cannot modify db.db file, but you can move it".

All that means is that you should include the original db.db file with your submission, that's all. Just make a copy of the file, and your program must modify the number of seats in db.db.
Eugene.
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi Eugene,
You had given me an excellent help. I thank you for this information which had been concealed from me. Now, I shall do as you had said I will straight away modify the available seats in DataInfo object, which will further reflect in db.db file. But you also let me know of design for implementation of Flight details. I would be depending upon selection of data from table. Is this OK.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
I would be depending upon selection of data from table. Is this OK.

If you mean that is it OK to use the data that you have on the client, yes. There is no requirement that the Flight data be "real time" data on the client side. But there is a requirement that booking takes into consideration that other clients may be booking the same flight at the same time your client is. So you should perform the sequence: lock, read, modify, unlock. Now when you acquire the lock and read the record, you will then verify that there are still adequate seats for the booking to continue. If not you'll never call modify but just unlock the record and notify the client that the booking failed.
Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi Morris,
I got you what you want to say. Morris there is one thing more I am using search which is provided by sun. The code is same the only difference is that in sun method (DataInfo find(String toMatch)) they had used break. I had created another method called Vector search(String toMatch) this method of mine only skips the break stmt such that matching objects can be encapsulated with the Vector object. Is this search acceptable ?. Or there is any other way out ?.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
I guess I am confused on what you are trying to accomplish here. The find() method is used to locate a record with a particular primary key. Its main purpose is to guarantee that no two records will have the same key value, which in our case is the Flight number. It is used internally by the add and modify methods just for that purpose so that you can neither flat out add a record with a key that already exists nor attempt to duplicate a key by modifying. If I had designed the Data class, I would have made find protected instead of public (don't take it on yourself to do that though!). I never called the find method. If you are going to use the Collection API (which you should) try to avoid the use of the older Vector, Enumeration etc. and use HashMap, HashSet, etc. instead.
Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
I guess I am confused on what you are trying to accomplish here.

The specification has 15 credits for the search algorithm. Morris I know two such algorithms one is sequential and other is binary. Out of these two binary is not acceptable because that require sorted records, which are further beyond the requirements of specifications. The only thing left is sequential search. I want to make you aware then sun method called DataInfo find(toMatch) also uses sequential search but has a break stmt to only gine single DataInfo. In my case I am using Vector find(toMatch) method to retrieve all the DataInfo objects which satisty the toMatch param. But, my question is that I am also using the same sequential search algorithm which sun had used. Is it alright to use same algorithm which sun had used. With only difference they had used break stmt instead I would not use break stmt such that all the records are iterated.
I hope that clears confusion.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
You can certainly use the same style of algorithm as Data.find but you should just loop through the table using Data.getRecord. The find method requires that you know the primary key (Flight number) of the record you are seeking. How can you possibly know all of the keys without first looping through the table anyway?
Of course if you wanted to implement a binary search, sorting is a cinch with a TreeSet. All you have to do is make a wrapper class for DataInfo that implements Comparable and you have sorted DataInfos.
Hope this helps
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
Is it ok to have two interfaces one for LocalDataAccess class and other for RemoteDataAccess class. LocalDataAccess would in bd pack and RemoteDataAccess in server pack. Both the interfaces define the prototypes of methods which client will directly invoke. And these methods will further invoke the methods of Data class via data class interface.Though I had implemented a single interface but the problem arrived in implementing Lock / Unlock methods. As, above said I also have another interface which has all the prototypes of public methods of Data class itself and Data class implements them all?. Is this design worth ?.
Thank you
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
There is nothing wrong with using two different interfaces and I feel responsible for confusing you on this issue. I don't know for sure, but I would guess that the vast majority of Developer candidates have used a double interface design.
The way I overcame the problem you mention was by using a Builder Pattern, which is a creational pattern similar to the Factory Pattern. My builder built three different composites: LocalDataConnection, RemoteDataConnection and ControlDataConnection. RemoteDataConnection and ControlDataConnection each had a reference to the LockManager but LocalDataConnection did not. Furthermore LocalDataConnection's lock and unlock methods were simply no-ops:

Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
Morris please confirm this thing that my Data class implements all the public methods of itself. This I say because the spec says " You should include a class that implements the same public methods as the suncertify.db.Data class" . And I would be using the references of this interface whenever I need the call to a method of Data class from LocalDataAccess and RemoteDataAccess class. I write once again LocalDataAccess is in db pack and RemoteDataAccess is in server pack.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
I think you are asking if it is necessary to implement all the public Data interface inside the Data class or a subclass of Data including lock, unlock and criteriFind. If that is what you are asking then NO. I didn't even touch lock and unlock in the Data class (I didn't subclass Data either). My DataAccess composites had lock, unlock and criteriaFind methods, but called lock and unlock on the LockManager and criteriaFind on an interface that I called DataSearch.
But, once again, just because I chose not to implement these methods in Data doesn't mean that you can't or shouldn't. Many have done just that and made high scores. You have to go with a design that you are comfortable with. One that you can clearly see start, middle and finish. The most elegant design is meaningless if you can't figure out how to implement it.
Hope this helps,
Michael Morris
 
Don't get me started about those stupid light bulbs.
 
subject: Database Designs