aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to construct 'String criteria' ? Help!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to construct Watch "How to construct New topic
Author

How to construct 'String criteria' ? Help!!!

Pratibha Gayake
Greenhorn

Joined: May 08, 2001
Posts: 29
Hello everybody,
Following are the lines from requirements
/* Start here*/
public DataInfo[] criteriaFind(String criteria)
This method searches the database for entries matching the criteria supplied. Criteria take the form of a comma separated list of <field name>=<value to match> specifications. For example, the following argument string would select all records describing flights by the SpeedyAir carrier that originate in San Francisco. "Carrier='SpeedyAir',Origin='SFO'" /*Line A*/
/*ends here*/
I got stuck with construction of String criteria. As per my understanding, once I get values of Origin and destination airports from JComboBoxes, then I have to convert that values into String criteria = "Origin airport='SFO',Destination airport='Bom' ". And pass this String to public DataInfo[] criteriaFind(Strring criteria).
For costructing this String criteria in the format given by line A, I have used follwoing method
/* following is a Search class to populate the values from Database and construct the String criteria
public class Search extends JFrame implements ActionListener{
....
...
...
jlb1 = new JLabel("Origin airport");
jlb2 = new JLabel("Destination airport");
jcb1 = new JComboBox(fbn.getFlight());
jcb2 = new JComboBox(fbn.getFlight());
jb1 = new JButton("Search");
jb2 = new JButton("Clear");
/* all these components are added in a Panel using GridBgaLayout and added actionListener to "search" and "Clear" Buttons*/
public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if(source == jb1){
sb = (jlb1.getText()+"='"+jcb1.getSelectedItem() +"',"+jlb2.getText()+"='" +jcb2.getSelectedItem()+"'");...................Line B
/* String sb is then passed to criteriaFind() method.
}
Question 1: So my Line B constructs String into form "Origin airport='SFO', Destination airport='Bom'" . Is this a correct way of doing it? Or I am going in wrong direction? Any hint to construct the String is appreciated.
Question 2: I am constructing String critaria as "Origin airport='SFO', Destination airport='Bom'" and not as
[b]"Origin='SFO', Destination='Bom'"[b] given as per SUN requirements. Because my criteriaFind() methos needs complete name of fields to passed. So that it compares with database fieldnames. I will document in my Design documnet all this stuff.
Is this O.K.? Or the marks will be reduced.
Thanks
Pratibha

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Well, from my perspective, it looks good. The only thing I did differently was to use a StringBuffer, and also to create a class that makes criteria strings for me, but in the same manner as you did.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Raju, Gentle
Greenhorn

Joined: Sep 06, 2001
Posts: 28
Well Prathiba,
In short it looks fine. However some suggestions if you will consider. The origin city and destinatin city can be created as constants in the class and be used them in the creation of String.
One question : How are you passing this String to criteriaFind method ?
Raju, Gentle
Greenhorn

Joined: Sep 06, 2001
Posts: 28
Can you briefly explain how you are implementing your UI ?
Pratibha Gayake
Greenhorn

Joined: May 08, 2001
Posts: 29
I am still looking for answer for Question 2,
Question 2: I am constructing String critaria as "Origin airport='SFO', Destination airport='Bom'" and not as
[b]"Origin='SFO', Destination='Bom'"[b] given as per SUN requirements. Because my criteriaFind() methos needs complete name of fields to passed. So that it compares with database fieldnames. I will document in my Design documnet all this stuff.
Is this O.K.? Or the marks will be reduced.
Pratibha Gayake
Greenhorn

Joined: May 08, 2001
Posts: 29
Thanks Marks for your earlier reply.
Hello Raju,
I am approaching my GUI as per following,
Part 1:
1.I designed one single Panel with gridbaglayout, components like JComboBoxes, JLables and Buttons for "Search" and "Clear" are added.
2. Method getFlight() fills the Origin and Destination JComboBoxes from Database.
3. I first tried to display all above stuff. I still have not handled event handling upto this point.

Part 2:
I created a JTable by using MVC pattern.
Model - MainTable , which holds data of Databse and has getter and setter methods for columnNames and rows(rows of DataInfo)
Controller - Uses Setter method of mainTable. This class has criteriaFind("Origin airport='SFO'") method.(This criteria is not from JCoboBoxes, it is a fake criteria , just to test whether my JTable is created with this criteria.) The result of criteriaFind is used to set the values in MainTable.
FbnTableModel- This class extends AbstractTableModel and implements getRowCount(), getColumnCount,getValueAT() method. These methods basically use getter methods from MainTable.
Finally View - extends JTable and dispalys the Jtable.
My Part 1 and Part2 are not still linked. Means whatever criteria I selected in part 1 is not passed to Part 2 to display JTable. I just divided GUI in two parts so that I can write, test the code separately. Now I am sure for functinality of both.
Now I am going to combine the two parts. I have formed the String criteria from Comboboxes. And I am working to pass this String criteria, from part 1 to Part 2, to dispaly the JTable.
Hope it helps
Pratibha
Raju, Gentle
Greenhorn

Joined: Sep 06, 2001
Posts: 28
I think it is fine to proceed the way you are preceding. The reason I do not see anything like [b]"Origin='SFO', Destination='Bom'"[b] in the requirement, at least the one that I a have received.
Regarding the GUI layout, I am stuck with the event handling.
In brief I have created an Input Panel and this will consists of all the combo boxes and Search button. Also I have table and table model. Latter I will have to place these two together. The problem here is how to write an event handling for these two. I know MVC approach will help me in getting good marks as well as opportunity to learn MVC. So I am rather working to come up with model (s), views, Controller. But so far not successful. I will read your post in detail latter and post my questions or queries latter.

[This message has been edited by Raju, Gentle (edited October 12, 2001).]
jyothi ve
Ranch Hand

Joined: Aug 03, 2001
Posts: 51
Hi,
The sun requirement says
The user should be able to select the origin and destination of flights, and the display should update to show only flights that satisfy those criteria. The user must be able to describe enter the string value "any" for the origin, destination, or both, so as to implement a wildcard-like feature.
I am in bit confusion with above spec. I divided above with 2 points
1. The user should be able to select the origin and destination of flights
2. The user must be able to describe enter the string value "any" for the origin, destination, or both, so as to implement a wildcard-like feature.
From the point(1), I am thinking of using combo boxes for selecting Origination & Destination Airport locations.
If I use the JCombo boxes how can I do the point(2) i.e how can the user enter "any" or "wildcard-like feature".
Since I am thinking of filling the Jcomboboxes directly from the "db" data, I am in confusion with this requirement.
I appreciate if somebody can clarify the above requirement. Probably I may be interpreting wrong.
Thanks
Jyothi

[This message has been edited by jyothi ve (edited October 12, 2001).]


Jyothi<br /> <br />Sun Certified Business Component Developer<br />Sun Certified Web Component Developer<br />Sun Certified Java Programmer<br />Oracle Certified SQL & PL-SQL Programmer
Pratibha Gayake
Greenhorn

Joined: May 08, 2001
Posts: 29
You must be filling your JComboBox from Database using Vector or Array. Then first add "ANY" to the Vector and fill the remaining from db.db. So in GUI you will display first "ANY" then reamining "ABQ" ,"ATL" and .....stuff.
Is it clear.
Pratibha
jyothi ve
Ranch Hand

Joined: Aug 03, 2001
Posts: 51
You mean to say that need to have different implementation for finding the orig/Dest Airport match with "any" one and with "SFO, LAX etc" selection another one.
Jyothi
Anurag Mishra
Ranch Hand

Joined: Sep 27, 2001
Posts: 133
Hello All of you
According to my spec. Sun is asking for the string in the criteriaFind() method
is like this "Origin='SFO',Destination='BOM'" Which should be enter into
a single JTextField and there will be a Search Button as well as Clear Button.The
String will be seperated with the help of StringTokenizer and passed into a Vector.
This Vector will furthur used in our FlyTableModel class which extends Abstract Table
Model class.According to me there is no use of JComboBox in our GUI regarding the
Flight Search.This makes our searchCriteria() Method generic.I have done this,
If there are some other ideas plz let me Know.
Anurag Mishra
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to construct 'String criteria' ? Help!!!