• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No readAll methods provided

 
shan chen
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instruction.html provides interface DBMain to implement, but DBMain does not have method like readAll() which is needed to get all records for updating JTabel. What should I do?
1. add method readAll().
2. call read() for each record.
Thanks for any suggestions.
chen
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that what the criteriaFind method will be used for?
Mark
 
shan chen
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, thank you for reply.
Interface DBMain defines method find, which is similar with criteriaFind. Its signature is:
public int[] find(String [] criteria)
It returns an array of record ids, not an array of records. What should I do?
1. change find() signature to return Collections.
2. get all record ids with find, then read each record. This solution has at least a drawback: array of ids will be sent from server to client. This is not necessary and can be avoided if with readAll().
chen
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think at least we need a find(int rec) method which returns a dataInfo[]
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shan chen:
Mark, thank you for reply.
Interface DBMain defines method find, which is similar with criteriaFind. Its signature is:
public int[] find(String [] criteria)
It returns an array of record ids, not an array of records. What should I do?
1. change find() signature to return Collections.
2. get all record ids with find, then read each record. This solution has at least a drawback: array of ids will be sent from server to client. This is not necessary and can be avoided if with readAll().
chen


remember that you're not limited to the methods provided in the interface, you can add another method that uses your find method to get all recNo's when given empty criteria, and then it could fetch all the records matching the recNo's returned.
above metioned is a long way around when fetching all records, its just an example, and is probably more appropriate when fetching records that actually match the criteria provided, given no criteria you could simply go straight in and fetch all
 
shan chen
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ta Ri Ki Sun. So far I am going to do the implementation as you suggested. But there are some issues:
after find() returns an array of record number, and before read is performed, it is possible another thread delete/modify some record whose number is in the returned array. The read method will face a different db.

remember that you're not limited to the methods provided in the interface, you can add another method that uses your find method to get all recNo's when given empty criteria,

Could you tell me where I can add another method? In interface DBMain or another class? I thought DBMain defines the remote interface that contains all methods through which a client can call the server.
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shan chen:
Thanks Ta Ri Ki Sun. So far I am going to do the implementation as you suggested. But there are some issues:
after find() returns an array of record number, and before read is performed, it is possible another thread delete/modify some record whose number is in the returned array. The read method will face a different db.

thats where your lock and isLocked comes into play, however I've noticed that many people here have no concern for dirty reads, and some have explicit instruction to implement write lock only

Originally posted by shan chen:


Could you tell me where I can add another method? In interface DBMain or another class? I thought DBMain defines the remote interface that contains all methods through which a client can call the server.

no no thats not DBMain's job at all, so consider DBMain(or rather Data) only for really low level dog work, the class servicing the clients can rather be something which provides clients with service methods like bookRoom(recNo), and let bookRoom call on DBMain's implementing class (Data) to do the dog work, the client does need to know what else it takes to get the job done.
so add methods freely but where appropriate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic