• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

nx:All of URLy Bird 1.1.3 find and search method

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George and Andrew:i create this new thread for find and search method.
Hi George and Andrew:
instruction 1:


// 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);


instruction 2:


It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
It must present search results in a JTable.


My questions are:
1: From the instruction 2,whether i will present all of field values of a record as a row in JTable,also as follow:

name location size smoking rate date owner
name location size smoking rate date owner
name location size smoking rate date owner
Am i right for this situation?
2: From the instruction 1,the returned value is the int[] which represents the record numbers.In fact the find will be used
in the serarch() method,but the search() method is required providing more function to return search result.Am i right ?
and whether i understand the essential of the instruction?
3: please you give me the general suggestion about the find() and search() methods?
Hi George your comment:


Your understanding of the logic of requirement is technically correct. 1 and 2 are relatively easy to implement. Implementing
3 is difficult to do in a single search. Many people (maybe most people) are not supporting 3 in a single search. Instead
they are supporting 3 as two independent searches.
3a: records where the name field exactly matches values:
(criteria[] name null null null null null), and
3b: records where the location field exactly matches values:
(criteria[] null, location, null, null, null, null)


4: I will create two JTextFields for inputing the name and location for serach() method,and a button with "search" ,If user only inputs in name field and click button,then searches for records that only name matches,if user only inputs in location field and click button,the searches for records that only location matches,if user inputs in name and location fields then searches for records that name and location match,if leave two fields empty then searches all records.Am i right?I will use case sensitive for search,am i right?
[ February 21, 2004: Message edited by: liqun chang ]
[ February 22, 2004: Message edited by: Andrew Monkhouse ]
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,
As you can see, I have copied your previous post into this thread. That way it will make sense to those reading it from scratch.
As for your questions:
  • Yes
  • Yes
  • Sorry, it doesnt work like that. You need to develop the submission yourself. There is no value in me providing potential solutions to you - you will not have gone through the learning exercise yourself.
    If you would like to suggest some ideas for any topic and get feedback on whether it is workable or not, that is OK.
  • This sounds very good.
    Some people have also considered using pull down lists which contain the possible values of the database. This makes it easier for the end user, but at the expense of requiring more network traffic and becoming more unwieldy as the database grows.


  • Regards, Andrew
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George and Andrew,about the find method:
    the instruction say:


    // 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);


    From the instruction above,my general thinking about find method is:


    //synchronized(raf)
    //loop read each record in datafile
    //check recNo validity
    //check whether specified record conform to criteria[]
    //if conform to criteria[]
    //put recNo to Collection
    //end synchronized block.
    //invert Collection to int[]
    //return int[]


    1: i will not use any methods that in Data class in find method.Am i right?
    my purpose is only return the recNos which conform to criteria[].Am i right?
    2: But in this situation if i create ServicesImpl class(a business layer)and create search method in it,if i invoke find() and read() and return the
    Vectors(one for column names another for records) within the search method,the values of record will be part dated.Whehter this is in reason?Please you give me some detail suggestions?
    [ February 23, 2004: Message edited by: liqun chang ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George and Andrew and guys:
    I will create method getCriteria(String[] criteria) for find method in Data
    class.
    getCriteria() is as below:

    3: I will use switch sentence in find method for branches.i will only make criteria[] that only contains two Strings(name and location).So do,i can simply finish the find method with small codes.Is this in reason? please you give me some comments?
    4: Whether i can create any method in Data class what i want? Certainly i must be implement the method specificed in DB interface from instruction.Whether i must not change any method signature inherits from DB interface except remove throws exception?
    [ February 24, 2004: Message edited by: liqun chang ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For find method,i will create as below:
    find method:

    5: From the find method,i only use two fields of datafile(name and location) for simple reason.Am i right?
    6: From client GUI,i only create two textfields,one for name filed,another for location filed.the probable case is 4
    kinds: null null,name null,null location,name location.Am i right for this section?
    7: Because when i find in datafile,another client may be creating the new record,so i use Collection instead of directly use int[].Am i right?
    8: In the search method that i will discuss in next part,i first get the recNos from find method,and then get the Vector of records through read() method,but i am afraid if in this here,a record aleady had been modified.How could i do?
    9: The most important is:If you have more finer implementations,please you give me some genernal suggestions?
    [ February 24, 2004: Message edited by: liqun chang ]
    [ February 24, 2004: Message edited by: liqun chang ]
    [ February 24, 2004: Message edited by: liqun chang ]
     
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:

    1: i will not use any methods that in Data class in find method.Am i right?
    my purpose is only return the recNos which conform to criteria[].Am i right?

    Yes and Yes. The find method has no reason to call any public methods in Data, it may however, call private methods to help it do it's job (for example, method to check record validity, method to check whether specified record conform to criteria[], etc.)
    2: But in this situation if i create ServicesImpl class(a business layer)and create search method in it,if i invoke find() and read() and return the
    Vectors(one for column names another for records) within the search method,the values of record will be part dated.Whehter this is in reason?Please you give me some detail suggestions?
    I'm not sure I completely understand this question, but let me say this. I don't think your search method needs to return column names for the record every time it's called. What I'm suggesting is a separate method, maybe called getColumnNames, that gets the column names for the record. You do this the first time you start up your GUI. You shouldn't need to get the column names more than once, since you can safely assume that the column names (which come out of the database file) will stay the same throught any one run of the application. So, your search method would simply return the values of the records (without bothering about the column names). Now we get to the part of your question that I don't think I understand. The records that are returned (because they were returned without the benefit of locking) may not be the latest versions of the records. I think it's OK to display possibly out-of-date records to the user in your JTable, if you make sure that when a user tries to book a record you do a read on that record before doing the update (both the read and update should occur in a locked context).


    [ February 24, 2004: Message edited by: George Marinkovich ]
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:
    3: I will use switch sentence in find method for branches.i will only make criteria[] that only contains two Strings(name and location).So do,i can simply finish the find method with small codes.Is this in reason? please you give me some comments?
    I think you can make your implementation of find more general. If your find method can handle search criteria for all the fields in a database record then it will handle the fields that are of interest to your client (name and location). That is, your client could call your find method with ("Dogs With Tools", "Hobbitton", null, null, null, null). In my opinion this is better than calling your find method with ("Dogs With Tools", "Hobbitton").
    In your method that checks whether the specified record conforms to criteria[]:
    A) if the criteria is null then the record field matches by definition,
    B) if the criteria is non-null then the record field must match the crtieria field for the record field to match.
    So, I don't think your getCriteria method is really needed.

    4: Whether i can create any method in Data class what i want? Certainly i must be implement the method specificed in DB interface from instruction.Whether i must not change any method signature inherits from DB interface except remove throws exception?
    Yes and Yes. You can implement any method you want in the Data class (in addition to the methods you have to implement from the DB interface). You shouldn't change the method signatures of any of the methods specified in the DB interface (because if you did, Data would no longer implement the DB inteface).


    [ February 24, 2004: Message edited by: George Marinkovich ]
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:
    5: From the find method,i only use two fields of datafile(name and location) for simple reason.Am i right?

    As I suggested earlier I think you are better off writing the code to handle all the fields of a record (even though you may only actually every give non-null values to name and location).
    6: From client GUI,i only create two textfields,one for name filed,another for location filed.the probable case is 4
    kinds: null null,name null,null location,name location.Am i right for this section?
    My suggestion is that you use non-editable combo boxes instead of textfields. If you go with the combo boxes you guarantee that a user can only ever attempt exact-match searches and therefore you don't need to be concerned with the fact that your find method in Data does starts-with matching rather than exact-matching. Of course now you have to write methods that get all the possible values for the name and location field so that you can populate the drop-down lists associated with the combo boxes. The four cases you can get from two search combo boxes are:
    1) null , null, null, null, null, null
    2) "Name", null, null, null, null, null
    3) null , "Location", null, null, null, null
    4) "Name", "Location", null, null, null, null
    7: Because when i find in datafile,another client may be creating the new record,so i use Collection instead of directly use int[].Am i right?

    Using a collection is correct, but not because another client may be creating a new record, but because you don't know from the beginning what size to dimension the int[].
    8: In the search method that i will discuss in next part,i first get the recNos from find method,and then get the Vector of records through read() method,but i am afraid if in this here,a record aleady had been modified.How could i do?
    Yes, this is a possibility. You may return out-of-date records for display in the JTable. But as I've said before, I don't think this is a problem. It's only a problem if you allow a user to book a record without doing a read before the doing an update (both should occur in a locked context).


    [ February 24, 2004: Message edited by: George Marinkovich ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George:
    as you say:

    [ February 27, 2004: Message edited by: liqun chang ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    From above you can see,whether my thinking about the algorithm is right:
    1: I will create List object(or DataInfo class that contains List) which for storing the records that used to display to client by recNo.Am i right?
    2: I use the more general find for all fields of records.Whehter my algorithm is right?(only general thinking)?
    3: I will create public getRecord(recNo) in the Data that used for returning all records that conforms to criteria.Am i right?
    but if i use this method,then perhaps it returns the dated values.is this
    reasonable?
    4: In the find method,i already put all records that conform to criteria into List(a member variable of Data)Am i right?
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George as you say:


    Now we get to the part of your question that I don't think I understand. The records that are returned (because they were
    returned without the benefit of locking) may not be the latest versions of the records. I think it's OK to display possibly
    out-of-date records to the user in your JTable,
    if you make sure that when a user tries to book a record you do a read on
    that record before doing the update (both the read and update should occur in a locked context).


    5: Whether you agree that i can display part of dated records in client GUI as long as ensuring book a latest record?

    from instruction 1:


    It must be composed exclusively with components from the Java Foundation Classes (Swing components).
    It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match
    values specified by the user.
    It must present search results in a JTable.
    It must allow the user to book a selected record, updating the database file accordingly.


    6: From your suggestion previous,i will create two JComboBoxs,one for name another for location.because of exactly match,i
    will
    provide drop down list for specified item.Am i right?
    7: If i use JCombo boxes,whether i must be first read all of names of hotel names and display to drop down list?
    or i must be read all of locations of hotel and display to drop down list?

    from instruction2:


    // 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);


    8: From instruction1 and instruction2,i find that whether client UI require the exactly match,but find method within Data
    requires startWith() of String?
    also exactly match search is sub-set of find search?say the scope of find is bigger than exactly match?

    9: as below,whether the instrutction2 means that criteria[0] must be compared to values of name field.
    for example:
    name location ......
    Ahotel
    Bhotel
    Chotel
    the criteria[0] only be compared to Ahotel and Bhotel and Chotel?and return appropriate int[]?
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George and Andrew,sorry for so many questions.perhaps there are some repeated,i worry about a little mistakes because i am a chinese.i hope to understand downright.thanks
    regards.
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:

    1: I will create List object(or DataInfo class that contains List) which for storing the records that used to display to client by recNo.Am i right?

    This is an interesting implementation that didn't occur to me. The find method is only required to return an array of matching record numbers (not the actual records themselves). Your implementation returns the array of matching records numbers, but it also stores an array of the actual records.
    A less complicated implementation of find would simply return an array of matching record numbers. The client would then have to call read on each of those matching record numbers to get the actual records to display in the JTable.
    In your approach the client would call find and would receive an array of matching record numbers, but the client would not really have any need for this array of matching record numbers. Instead the client would call getRecords which would return the array of records created as a side-effect of the last find call.
    Assuming that the client always wants an array of records (rather than an array of record numbers) when he calls find, your implementation is probably more efficient than the typical implementation. But the cost of this increase in efficiency is that you have introduced state into the Data class. Now the Data class "remembers" the array of matching records returned by the last call of the find method. If this array of matching records is shared among all instances of the Data class, you now need to be concerned about simultaneous access to this array of matching records. You also need to be concerned about what getRecords returns before the first find method is called.
    So if you pursue this implementation (which may be more efficient and therefore arguably superior to the typical solution) it does introduce some complications that have to be addressed. The typical implementation which would have the client call find and then as many reads as necessary, is more straightforward and in keeping with the spirit of the Sun-supplied interface. I'm not saying your implementation is wrong, but that it's not typical and because of this you will have to think about how the concerns identified above are addressed in your solution.

    2: I use the more general find for all fields of records.Whehter my algorithm is right?(only general thinking)?

    Yes

    3: I will create public getRecord(recNo) in the Data that used for returning all records that conforms to criteria.Am i right?
    but if i use this method,then perhaps it returns the dated values.is this
    reasonable?

    Would this getRecord method really take a recNo argument? It seems to me that the getRecord method would take no arguments since it would return an array of all the matching records for the last find call. So your client would call find and then getRecords (neither of these calls taking a record number argument).
    I don't doubt that you could get this solution to work, but it is more complicated than the typical solution suggested by the Sun-supplied database interface. If you successfully handle the concerns I raised above then this could be a good solution (it's clearly a more efficient solution and results in less network traffic).
    I don't think you need to be more worried about the stale record problem with your implemenation than you would with the more typical implementation. Stale records are not a problem when it comes to displaying records in the JTable. Stale records are a problem when it comes to updating a record, but as discussed before, this is easily solved by locking, reading, updating, and unlocking.

    4: In the find method,i already put all records that conform to criteria into List(a member variable of Data)Am i right?

    Given your solution, this is the right thing to do. If you went with the simpler, typical solution, it would not be necessary to have this member variable. If each of your clients has it's own instance of the Data class then it is appropriate to make this List a member variable of Data. If all your clients share the same instance of the Data class, then you need to be concerned with simultaneous access to this shared variable by different clients.

     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by liqun chang:

    8: From instruction1 and instruction2,i find that whether client UI require the exactly match,but find method within Data
    requires startWith() of String?
    also exactly match search is sub-set of find search?say the scope of find is bigger than exactly match?

    The find search is not an exact match search. However, if you constrain the values the user can enter as search criteria you can effectively achieve an exact match search. For example, if you make the combo boxes non-editable and populate the drop-down lists with all the unique values for the field found in the database, then you only allow the user to ask for search criteria that are effectively exact matches. If the combo boxes were editable, then the user could enter a name of "F" which would return all the records where the contractor name starts with an "F". This would clearly not be an exact match. But if you only let the user pick from ("Fred the Contractor", "Frederick Contractors", "Freddy and Son") then you will be effectively be doing an exact match.
    The only possible problem I see is if you have contractor names like ("Fred", "Fred and Sons"). Then the user could pick "Fred" from the combo-box drop-down list, but he would get back records with the name "Fred and Sons" as well as the expected records with the name "Fred". This problem could be handled by right-padding the fields with blank spaces. So the database would have fields like:

    This would only return "Fred" records, no "Fred and Sons" records would be returned if this blank right-padding scheme were followed.

    9: as below,whether the instrutction2 means that criteria[0] must be compared to values of name field.
    for example:
    RecNo name location ......
    0 Ahotel
    1 Bhotel
    2 Chotel
    the criteria[0] only be compared to Ahotel and Bhotel and Chotel?and return appropriate int[]?

    If you did a find(criteria) where criteria[0] = {"Bhotel", null, null, null, null, null}, the the find method would return an int[], say recNos, where recNos[0] = 1.

     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    5: Whether you agree that i can display part of dated records in client GUI as long as ensuring book a latest record?

    Yes.

    6: From your suggestion previous,i will create two JComboBoxs,one for name another for location.because of exactly match,i
    will
    provide drop down list for specified item.Am i right?

    Yes.

    7: If i use JCombo boxes,whether i must be first read all of names of hotel names and display to drop down list?
    or i must be read all of locations of hotel and display to drop down list?

    Not sure I completely understand your question here.
    This is one way to get the name and location values. The first time the client wants to call the find method (to get the initial values to display in the JTable), the client doesn't actually call the find method. Instead the client calls an additional method, initialFind. initialFind does everything the find method does plus it builds a list of unique field values for the name and location field. Another method, getUniqueValues, will return these lists of unique values.
    So, for example, the client would call initialFind and then getUniqueValues. After doing this the client would have all the records in the database (from the initialFind call) and all the unique values for the name and location comboboxes (from the getUniqueValues call). From this point on it would not be necessary to call either initialFind or getUniqueValues again. From this point on the client would only call find since it is no longer necessary to get the unique values for name and location. Hope this makes sense.


    [ February 29, 2004: Message edited by: George Marinkovich ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi:George,i will try to explain what you said.I don't know whether i fully understand what you said.
    1: My find method algorithm is right,i will let it only return int[] that represents record numbers of conform to criteria.Am i right?(find method only do single work).
    2: In find method,i will use startWith() of String for non exactly match.Am i right?
    3: I will create search() method(public Vector search(String[] criteria))that return the Collection of records.This Collection for creating TableModel.Am i right?
    4: In search of Services(business tier),it will invoke find() then read() of Data class.Am right?
    5: But you suggest me to create initialFind() and getUniqueValues() for creating JComboBox's drop down list. I want to know where i place the two methods? and how should i use the two methods?
    6: My original thinking is create two fields in client UI,but you suggest me to create two JComboBoxs instead of two fields.but how can i get the items of drop down list of the JComboBoxs?
    7: If i know the items of drop down list of JComboBox,then i have already known the part(names and locations) of all records .Am i right? Whether this make sense?
    8: To me, the key of the questions is:find the items(all of unique name fields and all of unique location fields) of drop down lists.How could i do in the situation of network transmission? please you help me and give me a general suggestion?
    Sincere waiting for your reply?
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:

    1: My find method algorithm is right,i will let it only return int[] that represents record numbers of conform to criteria.Am i right?(find method only do single work).

    Yes.

    2: In find method,i will use startWith() of String for non exactly match.Am i right?

    Yes.

    3: I will create search() method(public Vector search(String[] criteria))that return the Collection of records.This Collection for creating TableModel.Am i right?

    Yes.

    4: In search of Services(business tier),it will invoke find() then read() of Data class.Am right?

    Yes.

    5: But you suggest me to create initialFind() and getUniqueValues() for creating JComboBox's drop down list. I want to know where i place the two methods? and how should i use the two methods?

    My suggestion is only one way of doing this. You may have other (better) ideas that may accomplish the same thing. I would place these methods in the GUI controller on the client side. The initialFind method makes calls on the find and read database operations. When you start your client GUI there will be a JTable displayed. You could use the initialFind to get the initial set of records to display in the JTable. Remember, that as a side-effect, the initialFind also accumulates the set of existing values for the name and location fields. Therefore, the getUniqueValues method can retrieve the set of existing values for the purpose of assigning the drop-down lists for the name and location combo boxes.

    6: My original thinking is create two fields in client UI,but you suggest me to create two JComboBoxs instead of two fields.but how can i get the items of drop down list of the JComboBoxs?

    If you create two fields, then you allow the user to type in a search criterion of "F" for the name field, which would result in returning all the records with a name starting with "F", for example "Fred and Sons", "Frederick Plumbing", "Foster Tools", etc. It seems this is hardly an exact match. On the other, if you have non-editable combo boxes the user would have to choose "Fred and Sons", or "Frederick Plumbing", or "Foster Tools" from the name combo box, and then the application would only return exact matches (since the contents of the drop-down list exactly match the contents of the database).
    In order to get the contents of the drop-down lists you could call the initialFind method (which in addition to getting the records to display in the JTable also builds the sets of unique values for name and location), and then call the getUniqueValues method to retrieve the sets of unique values for name and location which can be used to assign to the drop-down lists.

    7: If i know the items of drop down list of JComboBox,then i have already known the part(names and locations) of all records .Am i right? Whether this make sense?

    I guess this is true. I've tried to respond to this question in 5 and 6.

    8: To me, the key of the questions is:find the items(all of unique name fields and all of unique location fields) of drop down lists.How could i do in the situation of network transmission? please you help me and give me a general suggestion?

    The initialFind method I spoke of previously is my attempt to do this. The initialFind method makes use of the database operations (find and read) to access all the existing values for name and location. You can accumulate all the unique values you discover for name and location (a Set works very well for this purpose). initialFind is built from find and read database calls. Find and read database calls can be accessed over the network (if you design your system to do this). The examples I've given and the suggestions made reflect the way I approached the problem. It's possible to do this many different ways.


    [ March 01, 2004: Message edited by: George Marinkovich ]
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George,i feel that i will about to finish my subject.Thanks for your always help.From your help,i approach the right way.And thanks for you provide the site about JUnit,and i has look at the content from the doc.If
    i finished this section,I will ask you some question about Unit test.Although in this forum i see the topic about JUnit,but it is not clear and system.

    you say:


    My suggestion is only one way of doing this. You may have other (better) ideas that may accomplish the same thing. I would
    place these methods in the GUI controller on the client side. The initialFind method makes calls on the find and read
    database operations. When you start your client GUI there will be a JTable displayed. You could use the initialFind to get
    the initial set of records to display in the JTable. Remember, that as a side-effect, the initialFind also accumulates the
    set of existing values for the name and location fields. Therefore, the getUniqueValues method can retrieve the set of
    existing values for the purpose of assigning the drop-down lists for the name and location combo boxes.


    See whehter i really understand you suggestion:
    1: I will create initialFind() method in UI controller of client side.and then invoke search() method(in RemoteServices remote interface) that return Vector that contains the all of records. Am i right?
    2: The Vector that contains all of appropriate records.and it has two actions, one is for JTable display,another is for drop down list of JComboBoxs,before populate it to JComboxs i will use getUniqueValues() in UI controller to get the name fields and location fields.Am i right?
    3: I will not directly invoke the find and read in Data class,but will invoke search method in RemoteServicesImpl(remote client use) or ServicesImpl(for alone mode)this seems more reasonable.Am i right?
    4: Whether the search method in Services or RemoteServices has two actions one for JTable,another for JComboBox.Am i right?
    5: If i invoke initialFind mothod in UI controller then it will invoke search({null,null,null,null,null,null}) get all validated records ,and the second invoke find mothod in UI controller then it will invoke serarch(String[] criteria),the criteria comes from the items of JComboBoxs.Am i right?

    you say:

    Find and read database calls can be accessed over the network (if you design your system to do this). The examples I've given
    and the suggestions made reflect the way I approached the problem. It's possible to do this many different ways.


    6: Whether you suggest me the initialFind method in client side directly invokes the find and read methods of Data class.or create a new remote interface to encapsulate the two functions of Data.How did you made reflect the way and approached the problem?
    [ March 02, 2004: Message edited by: liqun chang ]
    [ March 02, 2004: Message edited by: liqun chang ]
     
    Ranch Hand
    Posts: 156
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun:

    //synchronized(raf)
    //loop read each record in datafile
    //check recNo validity
    //check whether specified record conform to criteria[]
    //if conform to criteria[]
    //put recNo to Collection
    //end synchronized block.
    //invert Collection to int[]
    //return int[]
    --------------------------------------------------------------------------------
    1: i will not use any methods that in Data class in find method.Am i right?


    Why not use read() method of the Data class in the bold line?
    By the way, I think use regular expressiont int find method is a better idea. My find method like this:
    1. Calculate the count of all records in db file.
    2. Loop in this count and read each record, every time read a record, then add the record's information to recordValues string array.
    3. Loop in criteria array, check whether current element is null, if yes, check if this element is the last one of criteria, if yes, add this record number into findRecNo Vector. If the element isn't null, then define the expression is "^ + current element".
    4. Compile this expression and check it whether match the recordValues element. If don't match, break the current loop. If match, then check whether this element is the last one of criteria array, this is like 3.
    5. Convert recordValues to int array.
    Make sense?
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:

    1: I will create initialFind() method in UI controller of client side.and then invoke search() method(in RemoteServices remote interface) that return Vector that contains the all of records. Am i right?

    Yes, it sounds like that would work.

    2: The Vector that contains all of appropriate records.and it has two actions, one is for JTable display,another is for drop down list of JComboBoxs,before populate it to JComboxs i will use getUniqueValues() in UI controller to get the name fields and location fields.Am i right?

    Yes.

    3: I will not directly invoke the find and read in Data class,but will invoke search method in RemoteServicesImpl(remote client use) or ServicesImpl(for alone mode)this seems more reasonable.Am i right?

    Yes.

    4: Whether the search method in Services or RemoteServices has two actions one for JTable,another for JComboBox.Am i right?

    Yes. To clarify you will have two search methods. The first search method returns an array of records that match the search criteria, and in addition it processes the array of records that match the search criteria in order to store the sets of unique values for the name and location fields. The second search methods returns an array of records that match the search criteria, and that's all it does. The first search method is called once when the JTable is first displayed to the user, and from that point on it is never called again. From that point on the second search method is called whenever the user executes a search. The first search method is basically the same as the "initialFind" method I was talking about.

    5: If i invoke initialFind mothod in UI controller then it will invoke search({null,null,null,null,null,null}) get all validated records ,and the second invoke find mothod in UI controller then it will invoke serarch(String[] criteria),the criteria comes from the items of JComboBoxs.Am i right?

    Yes, that's right.

    you say:
    quote:
    Find and read database calls can be accessed over the network (if you design your system to do this). The examples I've given
    and the suggestions made reflect the way I approached the problem. It's possible to do this many different ways.
    6: Whether you suggest me the initialFind method in client side directly invokes the find and read methods of Data class.or create a new remote interface to encapsulate the two functions of Data.How did you made reflect the way and approached the problem?

    We have slightly different architectures: I implemented a 2-tier solution that makes the database operations directly available to the client, you are implementing a 3-tier solution that hides the database operations but instead makes business methods like search and book available directly to the client. You can continue with your 3-tier solution by making search and book available to the client GUI controller. The GUI controller can implement the two search methods we were just discussing above. One of these search methods just calls your search business method. The other search method calls your search business method, but also does the work of storing the sets of unique values for the name and location fields. Your solution is fine.

     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George:
    you say:


    Yes. To clarify you will have two search methods. The first search method returns an array of records that match the search
    criteria, and in addition it processes the array of records that match the search criteria in order to store the sets of
    unique values for the name and location fields. The second search methods returns an array of records that match the search
    criteria, and that's all it does. The first search method is called once when the JTable is first displayed to the user, and
    from that point on it is never called again. From that point on the second search method is called whenever the user executes
    a search. The first search method is basically the same as the "initialFind" method I was talking about.


    Whether you suggest me create initialFind and find method in client UI controller.initialFind pass string array({null,null,null,null,null,null}) to search method(Service),and find method pass string[] array(String[]criteria) to
    search method(Service).Am i right?
    This week,i will look at the content about the Junit and code my Data class.If have any questions,I will ask you.
     
    George Marinkovich
    Ranch Hand
    Posts: 619
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Liqun,

    Originally posted by liqun chang:
    Whether you suggest me create initialFind and find method in client UI controller.initialFind pass string array({null,null,null,null,null,null}) to search method(Service),and find method pass string[] array(String[]criteria) to
    search method(Service).Am i right?


    Yes.
     
    liqun chang
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi George.For your help.I will finish the key part of my design.
    I will open two threads ne for JTable another for unit test.Hope you help me?
    nx:All of URLy Bird 1.1.3 about JTable
    nx:All of URLy Bird 1.1.3 about JUnit test
     
    Those are the largest trousers in the world! Especially when next to this ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic