• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Modifying DataInfo

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers
I have addeed a new method in DataInfo class to retrieve the value of a particular field in a record:
/**
* This method returns a String, which reflect the
* value of the field in this DataItem passed as parameter .
*
* @param fieldname The field name to match upon to find the field value.
* @return fieldname field value string
* of the fieldname passed as params.
* @throws DatabaseException Thrown if fieldname is not valid.
*/
public String getValue(String fieldname) throws DatabaseException
{
String strFieldValue = null;
for (int i = 0; i < fields.length; i++)
{
String strField = (String)fields[i].getName();

if(strField.equals(fieldname))
{
strFieldValue = values[i].trim();
break;
}
}

if(strFieldValue == null)
throw new DatabaseException("Invalid field name specified");
else
return strFieldValue;
}
i am using this method at various places. I have create a booking info panel which displays every detail of the selected flight. and has textfield for specifying the no of seats required. This panel has labels for each details e.g label for flight no selected, carrier of the flight etc
Is this correct ??
Amit
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tough question. It comes down to being able to defend you decision to change that class. Still we don't know if that by itself will not have them reduce points for your score.
I personally decided that unless they said change the class that they provided, that I wouldn't. I believe that there are other ways to get that information with very little code, and without changing the DataInfo class.
But it is always down to your decision and remembering to defend it in your design.txt file.
Mark
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark
But what are the other ways of doing it ??
Amit
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a getFieldData method in my DataAccessFacade. In it I pass it a string of the fieldname, and a DataInfo object. I then loop through the fields array and field names array returned by the getFields and getValues methods and when the field name matches the field, then I get the corresponding field value.
This is probably exactly how you did it in the DataInfo class change, I just put the method outside it to the Facade.
Mark
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark
But in this case, if in future if we need to create another facade and want to get the value on the basis of field name, the same method needs to be replicated there which is not good (duplication of code basically).
Moreover this is a basic feature of getting a columnn values depending on column name like resultset have. So better to have it in DataInfo
I may be wrong but
What u say Mark ??
Amit
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either way is fine. Yes you would do the old copy and paste with a new Facade, but if you are creating a new Facade, I see it as replacement instead of Inheritence, or Enhancement. So I wouldn't quite see there being a major problem with Cut and Paste here.
Just my 2 cents, and that is worth about 1.5 cents in Euros.
Mark
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I approach the situation in neither way.
I created a new method in the Data class
/**
* Gets the index of the given field whose field name is specified
* by <code>fieldname</code>.
* @return the index of the field. If no such field, return -1.
* @param fieldname The name of the field to be search.
*/
protected int getIndexOfField(String fieldname) {
int Index = -1;
for (int i = 0; i < description.length; i++) {
if (description[i].getName().trim().equals(fieldname)) {
Index = i;
break;
}
}
return Index;
}
When it need to get the perticular field value, the index of the given field name is retrieved first then the value could be easily got by the straightforword array[index].
The method is frequently used in the criteriaFind method (reside in the Data class also)so it could not be put in the Facade class.
And i added another new method in Data class:
public Vector getFieldItems(String fieldName) throws DatabaseException
The method is used to populate the search combobox and invokes my getIndexOfField methed also.
And, in these methods, i used readRecord() method which return a string array rather than using the getRecord(int recNum) which return a DataInfo object.

Does my design make sense? Is the Data class the right place for these methods?

Regards
James
 
pie. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic