Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting the column headings

 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec says we have to implement the inferface given for the data file,
can I implement another interface as well to get the headings for the columns, ie add a method that says getHeadings?
or have people hard coded the headings in the tableModel class?
I cant access the Accessor file in remote mode as that is not set due to the remote data file so I though just add a method hence add an interface?

Thanks
Lee
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lee Sunter:

can I implement another interface as well to get the headings for the columns, ie add a method that says getHeadings?
or have people hard coded the headings in the tableModel class?


Hi Lee,

I think you can do this. In my case, I created
a DBSchema class which contains, among others,
the columnname-columnlength pair(Hashmap).
 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,
is it best to just add methods to the interface that I have been given.
ie spec says

and must implement the following interface:

package suncertify.db;
public interface DBMain {
// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] read(int recNo) throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n].
public void update(int recNo, String [] data)
throws RecordNotFoundException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int [] find(String [] criteria)
throws RecordNotFoundException;
// 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 int create(String [] data) throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
// Releases the lock on a record.
public void unlock(int recNo) throws RecordNotFoundException;
// Determines if a record is currenly locked. Returns true if the
// record is locked, false otherwise.
public boolean isLocked(int recNo)
throws RecordNotFoundException;
}

so I just add getAll() and getHeadings() methods to this

or create a new interface 'DBMainPlus' extending this one which the data(local anmd remote) then implement I can also deal with all the different types of execptions and through generic URLyBirdExceptions (NOTE the exceptions question is another issue I need to resolve as I have only been working with my URLyBird exception, should I now create recordNotFound and DuplicateKeyRecord exceptions or can i use the javax.ejb.DuplicateKeyException and RecordNotFoundException?)
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lee,

Touching the provided DBMain interface is a big NO NO!! If you want to add methods why dont you add them to the class which implements the given interface. Hint: Data.java


regards,
Tim
 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the interface is needed for when we are dealing with the data remotly?
How do you also read all the data ie a get all method?

Is it not a good idea to extend the interface since it is the interface we are passing around?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lee,

I agree with Tim - you really should not modify the provided interface in any way.

Think about this from a business perspective (not as an academic assignment). You have already been told that the database itself is used by other programs (a report writing program?), and you have been provided with a very specific interface with which to implement your Data class. My gut feeling is that they are either planning to have another application use your Data class, or rewrite your application (possibly as a web application) just reusing your Data class and throwing out everything else. Either of these projects may already be in development as we speak - after all, the other programmers could have been given the same interface, and that is all they need to start their programming.

Either way, if you add methods to the provided interface, or change the method signatures, you risk destroying the other programmers hard work. You will not be popular.

Extending the provided interface is fine, as is creating a second interface so that your Data class implements both interfaces. In either case, Data class will still be an instanceof the provided interface.

Regards, Andrew
 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My 2 choices it seams are to
extend the DBMain interface and use my new interface that has extended this interface ie pass around the DBMainPlus interface.
or I can just use the interface as it is and call the read method for each record to get all the data, and I could pass a special value to the read such as -1 which means return the headings for the columns.

I think i favour the second option as the data class will just implement the DBMain interface.

Following on what do I do with the execptions that are thrown, I was just dealing with my own execption type but shall i just stick to those in the interface and not creat any new ones for these database interface methods. (I take it I should use the java RecordNotFoundException and the DuplicateKeyException that already exist in 1.5)
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hate to play devil's advocate but I added the methods to the interface, adding them to Data and not to the interface would mean that your client has to work with an actual class instead of the interface. Not really an option IMO.
I also feared automatic failure if the interface was changed, but it was documented, submitted and proven to be nothing to be concerned about.
[ September 21, 2005: Message edited by: Ta Ri Ki Sun ]
 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You lucky devil Ta And your right as the interface is needed.

Anyway I have gone back to the DBMain interface and made use of the find and the read method to 'find' all records and to 'read' the headings. I perform checks in the code ie if read record -1 then returns the headings. If no details passed then return all the records, (the serach option would check and error before the data find method is called so the serach still works fine), Would this be ok (Andrew?), I think so as I am reusing code which is always good!

I still have a question regarding the exceptions? any help?
 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post bumped


Also the exceptions question is another issue I need to resolve as I have only been working with my URLyBird exception, should I now create recordNotFound and DuplicateKeyRecord exceptions or can i use the javax.ejb.DuplicateKeyException and RecordNotFoundException? and after these are though to the client code do I wrap and though as a URLyBird if I cannot recover? (I think the answer is yes?)
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lee,
(the serach option would check and error before the data find method is called so the serach still works fine)
I don't understand what this means - can you explain it a bit please?
can i use the javax.ejb.DuplicateKeyException and RecordNotFoundException?
Hint: are these part of J2SE (which is all you are allowed to use)?

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic