This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

NX: Two questions

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Requirement: 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.
In my program, I just match the name/location by matches any field
value that begins with criteria. Such as, if with the name 'Fred', then 'Freder', 'Fred' and 'Fred123' will be matched too. Does this meet the requirement of 'exactly match values specified by the user'? Or, I just only math 'Fred', and 'Freder' and 'Fred123' will not match.
2. Requirement: Your data access class must be called "Data.java".
Now, I create another class, such as "DataAccess.java" to access the database file. And 'Data.java' will not access the database file directly but with the help of 'DataAccess.java'. Does this meet the requirement?
 
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 fei xiao:
1) Under 'exact' match, 'Fred' only match 'Fred'. In fact, from the assignment, it has two search mechanism. One is in the client GUI, and another in the DB Access layer. In the GUI search, you must support 'All search' and 'exactly search(include case sensitive)'. This is statement in the assignment:

like above


But in the DB Access layer, it require you must support flexible search mechanism--to implements find method in this reason. This is statement:

A data access system that provides record locking and a flexible search mechanism


2) You must let Data.java access the database file directly. But you can create another class do the same work as Data, so you may not use Data.java at all. But this makes any sense?
Make sense?
 
fei xiao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Leo Tien:
Hi fei xiao:
1) Under 'exact' match, 'Fred' only match 'Fred'. In fact, from the assignment, it has two search mechanism. One is in the client GUI, and another in the DB Access layer. In the GUI search, you must support 'All search' and 'exactly search(include case sensitive)'. This is statement in the assignment:

2) You must let Data.java access the database file directly. But you can create another class do the same work as Data, so you may not use Data.java at all. But this makes any sense?
Make sense?


That is to say,
1. I should match all the string (including case sensitive)
2. I have to let Data.java to access the db.db file directly. Data.java get all data directly from the db.db file.
 
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 Fei,

Originally posted by fei xiao:
1. Requirement: 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.
In my program, I just match the name/location by matches any field
value that begins with criteria. Such as, if with the name 'Fred', then 'Freder', 'Fred' and 'Fred123' will be matched too. Does this meet the requirement of 'exactly match values specified by the user'? Or, I just only math 'Fred', and 'Freder' and 'Fred123' will not match.

I think most people believe that the find method as defined by the Sun-supplied interface does not "exactly match values specified by the user", but is rather a wildcard match (specifically a starts-with match). Therefore, they implement a findExact method that filters the results returned by find, elminating any records from the result set that are not exact matches. This findExact method can exist on the server-side or client-side.
2. Requirement: Your data access class must be called "Data.java".
Now, I create another class, such as "DataAccess.java" to access the database file. And 'Data.java' will not access the database file directly but with the help of 'DataAccess.java'. Does this meet the requirement?
I think this does meet the requirement. There is no requirment that the Data class access the file directly. The only requirement about the Data class is that it must implement the methods declared in the Sun-supplied interface. What you propose is reasonable and I believe several others have done something similar.


Hope this helps,
George
[ February 16, 2004: Message edited by: George Marinkovich ]
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to add one:
To complete the "excatly match" with hotel name "and/or" city name in gui, you do not simply match two String.
This is my way to handle "and/or":
If the TextField value in "Hotel Name" is empty, it means that search criteria is not required. The same rule applies to "City Name".
This way user could easily search with "and/or".
 
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 YungSheng,

Originally posted by YungSheng Chang:
This is my way to handle "and/or":
If the TextField value in "Hotel Name" is empty, it means that search criteria is not required. The same rule applies to "City Name".


Sounds good for the "or" part. If the textfield value in "Hotel Name" is "Hilton" and the textfield value in "City Name" is "Rapids City", then you search for records containing a Hilton hotel in Rapids City, right? In other words, only records that satisfy both search criteria are returned. If that's right, then I think you're OK.
Hope this helps,
George
 
Leo Tien
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 George:
I think what YungSheng means is that use empty value of TextField instead use "*" to identify the wildcard character.
YungSheng, right??
 
YungSheng Chang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo:
I do not use wild card. It takes more to educate user, and somehow it does not fullfill the "exactly match" requirement(Notice that SUN puts a "must" before the sentence, therefore I do not want to challeng it).
1. If the textfield value in "Hotel Name" is "Hilton" and the textfield value in "City Name" is "Rapids City", then search for records containing a Hilton hotel in Rapids City --- "And"
2. If the textfield value in "Hotel Name" is "Hilton" and the textfield value is empty, then list out all records with "Hilton" hotel, no matter which city it is in. --- "Or"
3. If the textfield value in "Hotel Name" is empty and the textfield value in "City Name" is "Rapids City", then list out all records in "Rapids City" --- "Or"
This easily fullfills the "And/Or" requirement. Of course this should be documented in userguide.
 
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 YungSheng,

Originally posted by YungSheng Chang:

1. If the textfield value in "Hotel Name" is "Hilton" and the textfield value in "City Name" is "Rapids City", then search for records containing a Hilton hotel in Rapids City --- "And"
2. If the textfield value in "Hotel Name" is "Hilton" and the textfield value is empty, then list out all records with "Hilton" hotel, no matter which city it is in. --- "Or"
3. If the textfield value in "Hotel Name" is empty and the textfield value in "City Name" is "Rapids City", then list out all records in "Rapids City" --- "Or"


That's the same thing I did, so of course I think that's exactly right.
Hope this helps,
George
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by fei xiao:
2. Requirement: Your data access class must be called "Data.java".


I might point out here that this is such a chronically bad comment to come from Sun. Technically it means you need to call your class 'java' inside the package Data in a source file called 'java.java' I dont suggest you do that BTW! Even to be funny.
I had similar experiences on a website I signed up for free web space. It was a Java development kinda place and to check you were serious they asked you to fill in a textbox with the answer to a question. I cant remember 100%, but im fairly sure it asked something like what class must a servlet extend. My first and incidentally the only correct answer was Object. This failed. I then tried the generic servlet classes. And so on and so forth. Until after a few minutes and a sudden dawning of dread at the stupidity of these people ... I typed in the interface a servlet implements and got instant access. I was bloody furious. Sent them a snotty email explaining the difference between a class and an interface and didnt use them after that
[ February 16, 2004: Message edited by: Morgan Bath ]
 
Leo Tien
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 YungSheng:


1. If the textfield value in "Hotel Name" is "Hilton" and the textfield value in "City Name" is "Rapids City", then search for records containing a Hilton hotel in Rapids City --- "And"
2. If the textfield value in "Hotel Name" is "Hilton" and the textfield value is empty, then list out all records with "Hilton" hotel, no matter which city it is in. --- "Or"
3. If the textfield value in "Hotel Name" is empty and the textfield value in "City Name" is "Rapids City", then list out all records in "Rapids City" --- "Or"


This is similar to me, because in my design, I use ComboBox intead of TextField, so I use 'match all' intead empty value. Understand?


Hi George:
I think what YungSheng means is that use empty value of TextField instead use "*" to identify the wildcard character.
YungSheng, right??


Perhaps this statement don't clearly, what I mean is like YungSheng statemnt later, when one field is empty, e.g. Hotel name, then it will match all(like 3). I think someone will use '*' or 'empty value' to implement this.


I do not use wild card. It takes more to educate user, and somehow it does not fullfill the "exactly match" requirement(Notice that SUN puts a "must" before the sentence, therefore I do not want to challeng it).


I don't know whether there is this stetement in your assignment:


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.


If in, then I think in your design, in order to implement 'search all', must let name field and location field empty, right ?
Make sense?
[ February 17, 2004: Message edited by: Leo Tien ]
 
Leo Tien
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 George:
What are you think about "Your data access class must be called "Data.java". " then ??
Because Ken use Data read data from db file directly.


Persistence
=========
The Data class implements the DBMain interface specified by Sun. It uses RandomAccessFile directly to get to the file data and provides an in-memory cache (List) of contractor record data. ....


Pls comments! Thanx.
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Leo Tien:
Hi George:
What are you think about "Your data access class must be called "Data.java". " then ??
Because Ken use Data read data from db file directly.

Pls comments! Thanx.


Hey Leo, mine is URLYBird. I too have the requirement as stated

Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface: DBAccess


From the "must" requirements of Sun, I think we are supposed to do all the database file access manipulation in this class. However, as we do not want this Data.java class to be accessible to anyone, we can create an adapter class, say DataAdapter.java that implements the provided interface by Sun. In this adapter class, we can instantiate Data.java and use it, so that no one can have exclusive access to the actual database access code.
Atleast, this is what I am planning. Please correct me if I'm wrong.
Appreciate your help, thanks.
 
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 Leo,

Originally posted by Leo Tien:
What are you think about "Your data access class must be called "Data.java". " then ??
Because Ken use Data read data from db file directly.


Well, it seems that they've made a mistake in the assignment instructions. They almost certainly meant to say: Your data access class must be called "Data", not "Data.java". No one would name a class "Data.java". It's clearly a typo that didn't get caught.
The quotation you give is from Ken's recap of his design, not from the assignment instructions, right? There's nothing wrong with having the db file directly in the Data class. Ken seems to have put it there and I put it there myself. But I don't think there's an implicit requirement that it has to be present directly in the Data class itself. The only other relevant requirement I'm aware of is that the Data class must implement the Sun-supplied interface.
What does Sun mean when they say your data access class must be called "Data" (and Data must implement the Sun-supplied interface)? I think it means that if the examiner does the following it should work (assuming the Sun-supplied interface is called DBAccess):

In other words, the examiner should be able to test your Data implementation by calling any of the DBAccess declared database operations and they should work.
So whether the database file is included directly in the Data class, or in some other class that may be included by composition in the Data class, doesn't really matter.
In both cases I think the Data class can be said to provide data access.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by George Marinkovich:
So whether the database file is included directly in the Data class, or in some other class that may be included by composition in the Data class, doesn't really matter.
In both cases I think the Data class can be said to provide data access.


Hi George, can you please explain what you meant by "database file is included in the Data class"? You meant the access to database file, right? Or is it different?
Appreciate your help, thanks.
 
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 Satish,

Originally posted by Satish Avadhanam:
Hi George, can you please explain what you meant by "database file is included in the Data class"? You meant the access to database file, right? Or is it different?


Yes, you're right, my language got a little sloppy. It would have been better to say that the database file can be directly accessed from the Data class. For example, if you're using a raf then the raf could be included as a member of the Data class. The alternative is to have some other class that directly accesses the database file, and have your Data class access the database file through this other class. I would then say that the Data class indirectly provides access to the database file.
In either case, the Data class is providing access to the database. A client of Data should not be interested in whether the Data class does this directly or indirectly.
[ February 18, 2004: Message edited by: George Marinkovich ]
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it George!! Thanks.
 
Leo Tien
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 George:
Thank you for your comments.


The quotation you give is from Ken's recap of his design, not from the assignment instructions, right?


Exactly.


There's nothing wrong with having the db file directly in the Data class. Ken seems to have put it there and I put it there myself.


I want to ask you whether you use Data as singleton ? Because Ken does this, so he use Data directly access the db file. Why at singleton Data design should use Data access db file directly? I think because Data is singleton, so RAF instance in Data is singleton, so don't need other class help to ensure only one raf instance in my design. I'm right ??
But under multiple Data instance design, thing is different, see below pls.


So whether the database file is included directly in the Data class, or in some other class that may be included by composition in the Data class, doesn't really matter.


In my design, I use multiple Data instance, and now I modify my code, let one class be called DataHelper to use RAF access db file. It's singleton, and it's as static instance in Data. Before, I use static RAF in multiple Data instance, now I feel this isn't safety, so I use singleton DataHelper. This design is OK ? pls comments.
Thanx.
 
Leo Tien
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 George:

// 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".)


Let's look this statement carefully again. I think the find method will have two functions:
1) match all.(nam||location or name&&location)
2) match begins with criteria.
The problem take place 2). Because the statement above said that For example, "Fred" matches "Fred" or "Freddy"., but not For example, "Fred" matches "Fred" or "Freddy" or "freddy".. So I think in find method is case-sensitive. Because in my design, I support a case-sensitive check-box to the user, this find method doesn't fit me, therefore every method filter find method doesn't fit me too, like findExact you point out. I'm right ?? What do you think of
this ??
Thanx.
[ February 18, 2004: Message edited by: Leo Tien ]
 
Squanch that. And squanch this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic