Lee Sunter

Greenhorn
+ Follow
since Mar 21, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Lee Sunter

Hi Ed Tse,
Does that mean that you have to run your jar from a directory called \SCJD as I appear to have to, because it cant find my properties file?
This is possibly an error with my coding as I just do
File f = new File("code\\suncertify.properties");
Properties properties = new Properties();
DataInputStream dis = new DataInputStream(new FileInputStream(f));
properties.load(dis);
so I supose this is wrong as its looking for my properties file under the directory stucture and not in my jar? (does that make sense) how do you fix that? ie its looking at the under the sturcture of \SCJD\code\suncertify.properties hence it will only work if that exists.
Any suggetsions on how to solve this problem?
Thanks
Lee
I have implemented my locking and all appears to work but I am trying to get WeakReferences to work.

Currently I create a weak refernec for my clients and pass that to the lock manager, a record is locked and the weakref stored with it in a Hashmap. I then havbe anothetr client attempt to lock the record, it cant and so waits. I then terminate the original client. I was expecting the second client to come out of the wait, but how can that happen. What am I doing wrong as I must still have a valid reference to the weakRef of the first client. Any Ideas, should i be using a weakHashMap? (possibly not as no one has mentioned that!)

Thanks
Lee
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?)
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?
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)
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?
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?)
Thanks, once again sorry if I am being slow but how would one mark the record as deleted is it a case of puting an Integer with a value of 1 at the front as the data file i have has no examples and the active files are all 00 at the front?
Thank
Lee
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
This is the database interface
// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;

but later its says
'Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file'

I have just been marking the records as deleted when I delete them as that is how they have been givenm to me in the data file
'2 byte flag. 00 implies valid record, 0x8000 implies deleted record'

Just thought I would ask what people thought?

Thanks
Lee
(ps whats the String value of 0x8000?)
This is my assignment requirement for Java Docs

The code itself should be as clear as possible; do not provide comments that do not add to the comprehensibility of the code. Awkward or complex code should have descriptive comments, and javadoc style comments must be used for each element of the public interface of each class. You must create a full suite of documentation for the classes of the completed project. This must be generated using the tool "javadoc" and must be in HTML format. Provide javadoc documentation for all classes you write.

does this mean I should or should not provide Java docs for my private methods, if not should they just be normal comments? or do you put them in for eveything?

Thanks
Lee
I have the file structure

SCJD
> Code
> client
client code
URLyBirdStartUp
> server
> Doc

I can use the jar command to run when there is no 'code' directory? but not when there is a code directory in the structure.

I run D:\SCJD>jar cvfm URLyBird.jar manifest.mf .

This puts in all the files and when I look at the jar I see that the URLyBirdStartUp.class is in the directory structure /code/client/

but when I try to run
D:\SCJD>java -cp .\URLyBird.jar client.URLyBirdStartUp alone
it thorws a
Exception in thread "main" java.lang.NoClassDefFoundError: client/URLyBirdStartUp

Anyone got any ideas as I have tried different combinations?
My manifest.mf contains Main-Class: client.URLyBirdStartUp

Thanks in advance
Hi,
I have a few questions if anyone can help?

1. User specifies Alone or Server etc to run the application, has everyone just created a startup class which is what gets called and this then directs the flow of control to either the loc\l client class and its main method or the server etc? As thats the simple way to implement this I think from the command line. This startup class can pass the params from the properties file.

2. The properties file is that just simply a text file that has the database name, port, host listed?

3. I cache my database and the locking etc works, after reading other posts and your replies (thanks ) I am concerned about the create method, I have implemented this within the cached database as this is not called by the client I am not concerned about the data file database being up dated. That said I have added a writeOutData method to my dataAccess file incase the user ever wanted to write out the data file, do I need to include a call to this on method exit (ie as a data back up as none of the booking results will have been saved to the data file)?

4. The 48 hour rule, since the requirments do not explicity say MUST in front of this requirment, so do we have to do it?
Thanks guys for all your help I now have the caching issue solved.