• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of Records Bodgit and Scraper

 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a class for having the fields of Database inside it. Ofcourse it means kinda Hardcoding the database fields, but I guess it can be one of the assumptions. The simplicity here is that If I read the status of record also (which tells me whether its deleted or not) it will help me in dealing in an Object Oriented Way. My Interface for Database accepts only string array but anyway I can convert my object to string array and then to byte.....

Also I was thinking of keep a static variable no. of records in the class file. So that if the record No is greater than no of records I can automatically throw an exception. Ofcourse it means scanning the database intially till I reach the end of file and keep a count of number of records. Keepin a static varibale will ensure that many instance increment the same variable so every instance will have this count....


Anybody used a similary approach let me know....???
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a column name mapping is acceptable if you didn't do it in the database class but in an adapter class. My rule of thumbs is the database user should never know the schema of the database.

I don't quite get the part where you said you will have a static variable holding something it though. Unless your Database class is a singleton, I don't think you should have a static variable holding the column name mappings.
[ March 19, 2006: Message edited by: Ed Tse ]
 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When u say "Database user should never know the schema of the database"
Does it mean that my low level database class should not know even the fields of the database.

Its like passing a string array and this low level class just writes the data to the Database without knowing which fields are there. The problem is skipping through records and arriving at the correct position.

For that u need to know the length of record. Either we can Hard Code this length or read it from Schema at the time of insertion. Should we read the Schema and Columns names Dynamically...or use code them statically in a class? Cos they have provided the column names in the Document also and they are present inside the database also. It becomes a Desing Decision I guess?
 
Petr Hejl
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you have to iterate over all records - you can compute it from file length and record length. Of course you can not be sure that the record is valid until you read it (you would have to store some additional info about state when initializing db and changing it), but you can be sure that if the requested recNo is greater than computed record count it does not exist.
 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static variable I mentioned was for keeping Record Count.

I am keeping one DBInfo class which has two ArrayList FieldNames and FieldLengths. Other class is Data.java which implements low level fileHandling.

This is initialized when I create an instance of Data.java class. So Data class fills up DBInfo after reading the Schema. I just wanted to keep a static variable RecordCount so that many instances of my Low Level Data class will be able to keep track of the number of records added by different clients. At any time if RecordNo is greater than Number of Records stored in this static variable, I can throw RecordNotFound exception.

Correct Me If my approach is wrong???

Also if I decide to use Caching and store up all the records in an ArrayList then also I will need to keep that ArrayList static. Same technique was used in SCJD Book (Denny's DVD appln) in which the author has kept a static arrayList for Locking.!
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get the idea, your implementation is almost identical to mine, except my DBinfo class is called DBSchema. I do the a count on number of record but it isn't static. My implemenation allows multiple instances of Data.java (if they are opening different db files). Given that, having a static variable for record count is not ideal. (I meant java's static)
[ March 20, 2006: Message edited by: Ed Tse ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic