Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database key

 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that any key exist for database?

For example, my data as below

rec1 contractorA location1 ...
rec2 contractorA locaiton2
rec3 contractorB location1

Can I assume the key is combination of contractor name and location?

If so, when CSR update the fiend, if they change the rec3 or create a new record as contractorA and locaiton2, then I should give warning as record arleady exist? Or I allow record to be modify/create

Hope some one can answer my questions.

Thanks a lot.
 
Chulwoo Choi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You would define recNo so that, for example,
the recNo for the 1st record is 1
the recNo for the 2nd record is 2
...
the recNo for the Nth record is N

The location of Nth record in the database, then, can be found by the following psedu code:


Chulwoo
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.

Well, may be I just write my questions:
- Can 2 records have same subcontractor name and location?
- If can't that means if user update/create record with same subcontractor name and location, system need to prompt for it right?

So can I conclude record are unique with the key combine from subcontractor name and location?
 
Chulwoo Choi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two persons (subcontractors) are distinguished only by their keys (recNo).
There may be two different persons (subcontractors) who happen to have the same name and location.

Again, consider assigning the record number so that the recNo of the Nth record be N (see above).

Regards,
Chulwoo
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sense as we can have difference subcontractor with same name and same location.

Well, if using formula below to get retrieve record base on recno:
location = length of start of file + length of schema section + (N - 1) * record length

Can understand how to 'associated disk store for reuse':
// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) 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;

Let say:
Rec1 valid
Rec2 valid
Rec3 valid

When I delete rec2, and mark it as delete (no need physical delete right?). Now it become
Rec1 valid
Rec2 invalid
rec3 valid

When I insert new record, record number return from creation method will be Rec2 or Rec4?

Let say is Rec2, that means I need physical remove previous record instead of marking.

If rec4, then I can't achieve 'reuse deleted entry'...

Very confuse on this part... please help

Thanks
 
Chulwoo Choi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I insert new record, record number return from creation method will be Rec2 or Rec4?

It's up to you. In my implementation, the new record would be Rec4.

Chulwoo
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, that the simple way as what I doing now...

But.. then will not able meet the requirement:
delete: associated disk storage avaiable for reuse
create: reusing a deleted entry



 
Chulwoo Choi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your instruction doc requires you to reuse the deleted entry, you should do so.
But in my doc, it says,

So I didn't reuse the deleted entry when creating a new record.

Chulwoo
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, my one also is 'possible...'

However for delete method how to associated disk storage avaiable for reuse? I need permanance delete the record or just mark the with delete flag?
 
Chulwoo Choi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A record is not physically deleted but marked deleted. So the spot (i.e., associated disk space) of the record becomes available for reuse.

Chulwoo
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still can't understand...

If I mark the record flag as DELETE, then how the associated disk storage can make it available for reuse.

The term 'reuse' means make the recId available for new record?

Well if so, then when I seek the record using formula:
db.seek(headerLen + (recordLen * (recno - 1)));

I will only get back the previous delete record info...

Pls help... very blue on this point...
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally I understand now...

Here what I think, please correct me if I'm wrong.
- Delete: Mark the record as delete (leave the data)
- Create: Instead of create a new record on the end of all records, program will first find those delete record id and overwrite the deleted record with new data.

So what I need only find a way to know which record id is deleted and can be reuse to insert new reocrd. And if I don't have an deleted recId, then I just insert a new record at the end.



^_^
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic