Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!

Song Jing Lim

Ranch Hand
+ Follow
since Feb 11, 2003
geocities.com
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Song Jing Lim

Thanks for reply...

But is that any limitation that I can only add private method to Data.java? if I add extra public method (e.g. getNumberOfRec()) for Data.pub, then I only can instantate Data object as below:

Data db = new Data(dbpath);

instead of

DBMain db = new Data(dbpath);

Is that necessary to instantate db object as DBMain?

The public method I plan to implement include retrieve record version (using timestamp) by adaptor class:

So if

Class Adaptor(){

DBMain db = new Data(dbpath);

public int updateRec(Subcontractor obj){
String objVersion = obj.getVersion();
int recNo = obj.getRecNo();
String recVersionInDb = db.getRecVersion(recNo);
if(objVersion.equalIgnoreCase(recVersionInDb)){
....
}
}

I not able call db.getRecVersion(recNo) if db is DBMain object. I can only call that method if:
Data db = new Data(dbPath);

Back to my original question:
Any one pass SCJD by instantate db in adaptor class:
Data db = new Data(dbPath);

Or every one just do like:
DBMain db = new Data(dbPath);

Please help... :roll:
Thanks for reply, make me more confidence on that.
So far as I know, beside implement methods define at DBMain.java, we can create few method at Data.java.

But can I use that method by other class?

Let say I got a DataAdaptor as below:

Public Class DataAdaptor{
DBMain data = null;
pubic DataAdaptor(String dbpath){
data = new Data(dbpath);
}
}

Can I just define data as Data type instead DBMain? E.g.
Public Class DataAdaptor{
Data data = null;
pubic DataAdaptor(String dbpath){
data = new Data(dbpath);
}
}

So I can use those extra method define at Data.java which didn't define at DBMain interface e.g.
data.newmethod()

Any help on this?
RandomAccessFile object need to be synchronize bcoz user may move the file pointer position during seek()

e.g.
User1: move the RAF seek to locaiton x and writing/reading
at the half way
User2: move the RAF seek to locaiton y for writing/reading

Problem may came out if file position had change during half way of operation.

Am I right? (personaly I also face this problem )

Hi...

To prevent 'dirty data' as show below:

User1 View RecNo1
User2 Del RecNo1
User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data)
Back to user1 he decide to edit/delete the RecNo1 after view...

Problem came as the RecNo1 expected by User1 are not the one in database now.

To prevent that problem, I will using timestamp as below:

- Read the database during system startup and build a hashtable contain recNo and assign each with a timestamp value.
- When user get the Record (will return as JavaBean object), timestamp associate with that recNo (from hashtable) will be set.
- That timestamp will be use to compare the current timestamp associate wit h that record during edit/delete.

There for:
User1 View RecNo1 (current db, RecNo1 have timestamp x)
User2 Del RecNo1 (current db, RecNo1 had remove)
User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data) (current db, RecNo1 have timestamp y)
so when User1 want to edit/delete, system will alert user that timestamp in the object are difference from database.

My approach is ok? Anyone have a better suggestion or alternative approach?

Note: I using service side locking as lock() method implement didn't return any value (it is void), so not able implement client side locking.

:roll:
The problem with server side locking is 'diry read', eg.

User A: Read Rec1
User B: Edit and Update Rec1
User A: Edit and Update Rec1

Where b4 user A update the record, the contain already change by UserB without notice.

Still got problem to solve this... Anyone can help?
I have a seek method that pass in recNo and get the record from database using below fomula.

RandomAccessFile RAF = new RandomAccessFile(dbpath, "rw");

public void seek(recNo){
long filePositionToSeek = headerLen
+ (recordLen() * (recNo - 1));
RAF.seek(filePositionToSeek);
}


So no need map recNo to anything
For me, I read everything and store to DataSchema javabean object which also store RandomFileAccess object.

I just read the magic cookie but never use it... May be can store the value to properties file then compare with the one read from data file.
I need implement below methods...

But I don' tknow those methods will be internal use by Data.java or will call from front end UI?

If use by front end (UI) that means once user select a account to modify, system will check either record had lock for by other user and return modify not allow?

Any guide on that?

// 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;
I also doing B&S assignmnet, but nothing related to cookies value (beside the magic cookies value on first 4 byte to identify it is a data file).

The locking method I need implement as instruct as below:
// 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;

So our requiremenet may be difference even both doing B&S
May be UI will only asking either is local or remote. If local then it will ask for database file location. For server, when it startup it will read the database file location from properties file.
My B&S Assignmnet requirement for find as below:
// 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;

So the criteria[n] must match with database field[n]?

E.g.
Data[0] = name
Data[1] = location
Data[2] = specialties
Data[3] = size
Data[4] = rate
Data[5] = owner

let say criteria[] value as below:
criteria[0] = My name
criteria[1] = null
criteria[2] = My specialties
criteria[3..5] = null

So I need loop through all record and match the name and specialties value in database again the value in criteria?