Hi,all I just consider to start data access layer implementation. After looking many of posts from every professionals,I am not still able to sure a final schema. Firstly,I do data access funtions in the Data class,and its assistant class is DataSchema class. 1)I create open()/getNumOfFields()/getFieldNameLen()/getFieldName() method,etc. (*arrays are byte fieldNameLen,String fieldName,byte fieldLen)
2)I do the read/write operations in the DataSchema's constructor.
3)And then,I can invoke the public methods to get schema fields wherever I am. Secondly,I have to read and write records in the Data class. All that above are correct? Do like this is suitable to Sun' request? Please comment and discuss about it. Regards, Richard
IMO, if your data class is also going to implement all of the main functions (i.e. book, add, delete, find/search,lock..etc) you may want to move all file processing into a single class. Then place a handle to that class in the Data class so the Data class can retrieve relevant file information. Why seperate them? Well in essence a class should have on main purpose. If you place both the file handling and data operations in to the Data class you asking a lot out of your Data class. I know some who have done this and passed the SCJD, whether or not they were penalized for it we'll never know.
Thank you,Bill Considering the Data class implementation (extends from DBAccess interface),there are some doubtful points,
// Modifies the fields of a record. The new value for field n // appears in data[n]. Throws SecurityException // if the record is locked with a cookie other than lockCookie. public void updateRecord(long recNo, String data, long lockCookie) throws RecordNotFoundException, SecurityException; // Deletes a record, making the record number and associated disk // storage available for reuse. // Throws SecurityException if the record is locked with a cookie // other than lockCookie. public void deleteRecord(long recNo, long lockCookie) throws RecordNotFoundException, SecurityException; // Creates a new record in the database (possibly reusing a // deleted entry). Inserts the given data, and returns the record // number of the new record. public long createRecord(String  data) throws DuplicateKeyException;
In the DBAccess interface,I have the following estimations, 1) The createRecord() and deleteRecord() method is used to changing the database ,so they are not relational with booking a room? They don't have to exist in a remote interface ( such as 'interface RemoteDBAccess'). 2) In the update() method,what should I do to modify the value of field n to update the record? 3) "Deletes a record, making the record number and associated disk storage available for reuse. " According deleteRecord() method, how can I delete a record and make the disk space avaliable for reuse? 4) During the course of create/delete/update/find record data,is that necessary to wrap the records into a Collection (like List or Set) for easy operation? Regards, Richard
I'm not working on the same exam as you, but the data access layer sounds very much the same. My thoughts on your questions: 1) In my project the people who book things are not the same people who would be adding and deleting things which can be booked, so I think the create and delete functionality stays buried in the data access layer. This functionality does not belong in the business logic for the customer service reps. I believe the evaluation involves some sort of automated testing of your data access layer, so the low level functionality of course must be complete. 2) Perhaps I'm not understanding, but you would probably just want to write the data back out to the file. If the nuts and bolts of this are the question, then the Sun tutorials provide a good speel on File I/O. A questin I'm trying to resolve is traditional I/O or NIO. I'm leaning towards traditional, but mostly because I don't yet know enough about NIO. After some investigation I'll have some better ideas. 3) I interpreted this to mean that the space of a record marked deleted can be used in the creation of another record. Considering point 1) this means your client will never reuse this space (because the people who book can't create records.) I think the wording is a little misleading, the idea is to allow the space to be reused by the app. I didn't read this to mean that you must make the space available to the OS. Well, good luck and regards, Jay Bromley
Bill: I am not saying its wrong I am just not sure what the purpose is? Locking/Unlocking? Richard: 4) During the course of create/delete/update/find record data,is that necessary to wrap the records into a Collection (like List or Set) for easy operation?
My meaning was whether I need to cache all records into a collection(like List). I just saw many of people in the forum have done this step. Regards, Ricard
Hi,all I have two problems about modify database. 1)In my above post in this topic,there is a DiscountRoom class provide some getters/setters methods for reading/writting field data. When I have to create/delete/update records,should I add some other methods (like int getFieldNumber(),etc) to return field n? 2)Now that all fields read as a string,what should I do make a deleted record return its record number? Regards, Richard
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards