• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Am I doing fine in findCriteria()

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody please help me if I am doing the right thing. getting the values in th form of Array of bytes which matches then I might calculate the number of records I got in the search criteria. That what I am supposed to do?

Any thoughts? Help is appreciated.
Here is the code which is called from findCriteria()
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Uzma,

I'm not sure about your requirements, but my findCriteria method had to return an int array of matching records. Therefore I don't think you need to use byte arrays.

I think having a method for reading a record is a good idea, but this should be a generic method that could be used by other methods and should return a string array of each field, then in your findCriteria method you should do the comparison (Not in the readField method). This is basically the logic I implemented in my findCriteria.

Step 1: Check if all fields for search criteria are null, if so you don't need to compare as all record id's should be returned.

Step 2: Create loop which calls String[] readRecord(recNo) Within the loop compare each String in the String[] array returned by the readRecord method with search criteria. If fields match add to ArrayList.

Step 4: Once the end of file has been reach convert array list to int[] and return.

Hope it helps

Jason

[ August 24, 2007: Message edited by: Jason Moors ]
[ August 24, 2007: Message edited by: Jason Moors ]
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks so much for the guideline. Now my function has to return array of long. if now I extract the staring array and store them as long array then it would be only one record. In actual more contractor can be returned, isn't it?


Thanks for the help in advance
regards

uzma
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Uzma,
I also have to return a long [] in my B&S assignment. But I am questioning why you are not pulling the database into an internal cache ( I use an ArrayList ) and search it instead of constantly retrieving from the flat file?
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Uzma,

The findCriteria method returns an array of record numbers that match, i.e. the record index in the file, not the fields of the records.

The client then uses index via the read method to retrieve the data for each record.

Caching is a subjective topic and you will find hundreds of posts on the subject, I personally decided to keep it simple and read from the file each time as there are no performance requirements.

Regards
Jason
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jason, but I think there is no need of putting them in an arrayList. Can you see the code below and comment please, it was so simple, isn't it?

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic