• 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

B&S create method

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

can I make following assumption while writing create method

1. make sure that name and location fields are not null
2. make sure that the combination of name and location fields are unique.

Is the above necessary?

or would you allow name and/or location fields to be null in argument-data array of create method.

any suggestions from some of you who have B&S assignments??
Thanks
[ April 03, 2008: Message edited by: Mary John ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not doing the B&S assignment, but in my assignment (URLyBird) when I make assumptions like yours I figure they are business logic and put them into the controller. This means that validation in the database class is just simple checks on field size, etc.
When it comes to the database, I expect the examiner will run automated tests on the interface implementation and that any deviation from the expected behaviour will break the test.

For example, in my application (a hotel room booking system) users might want to look for a hotel room in a city in a certain price range. The obvious choice is to expect that the user leaves out the price and inspects the search results for rooms in their price range.
I decided that a better choice would be to put in minimum and maximum price search fields. The controller then strips these out of the search criteria sent to the database and when it gets the results back, filters out the rooms that fall outside the entered range.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, y'all.

Originally posted by Mary John:
can I make following assumption while writing create method

1. make sure that name and location fields are not null
2. make sure that the combination of name and location fields are unique.



Well, I don't have the B&S, I have the URLyBird, but I think no field can be null. I check it in the create method. If the String array sent is null or if any of the fields is null, I throw an IllegalArgumentException.
Also, before making sure if the combination of name and location fields are unique, make sure that it doesn't make sense to have this combination. In other words, be sure that it wouldn't make sense to have 2 different records with same name and location. But if having 2 records with the same name and location makes sense, then you can't do it. By the way, I think you made this combination your primary key, right? If so, make sure to throw a DuplicateKeyException there.

Originally posted by Simon Hogg:
This means that validation in the database class is just simple checks on field size, etc.



Perfect.

Originally posted by Simon Hogg:
I decided that a better choice would be to put in minimum and maximum price search fields.



Honestly, I think your idea is great, I really do. But in my opinion, you are going too far. Remember that "you will not receive extra credit points for work beyond the requirements of the specification" (from the specifications document). This is required for your GUI:

- 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.

So you must allow the user to search only for name and location. I just put in the project exactly what was asked. For example, I did not add logging because, it wasn't asked, and also, the more code you write, the bigger are your chances of making mistakes and having points taken from your final score. So in a nutshell, your idea is really great, but I wouldn't do that.
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for the replies, Simon and Robert

I still have one thing getting me confused...

As I understand in B&S one of the fields(owner id) is recorded only when a
CSR books the record. Almost all records in the supplied db file has
owner id blank. Doesnt that mean that owner id field will be null when created???

But........
As you mentioned if you dont allow nulls( and throw Illegal argument exception) then how can we create a record with owner id null.?


Or just as it occured to me while I am typing this, are you guys allowing an empty string(I mean "") to indicate a "no value" for a field whose value need not be stored? I think I am confused a bit about nulls and empty field....

Thanks
Mary
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you are absolutely right. I was wrong when I said that no field can be null. The customer Id can be null. The others can't. I mean, I think this is a design choice. What makes more sense for you, setCustomerId(null) or setCustomerId("")? This is really up to you. And then you'll have to treat this data so it can be correctly written to the physical file (are you using null terminator to indicate the end of a record or filling everything with empty spaces?).
As far as I can tell Mary, you don't have to worry. You are in the right track
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have B&S, and with the exception of the implementation of the DB calls, I use a Contractor object rather than a String[] to manipulate and pass around my record values. Anytime a client interacts with the DB interface, it's with Contractors, which are then converted into String[]'s beneath the hood (in the DAO). It's thus very easy to ensure that all fields are defaulted to not null.

Now I suppose it's hypothetically possible that a new class could access the DB directly via my underlying DAO rather than going through my abstracted interface, and thus break my code, but I think that's overkill for this assignment. One way I mitigate this is by making the DAO have default access.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have just uploaded the assignment for B&S. I have used the name, location and the specialities field for the unique key. Name and location
is not unique enough because a customer can have more than one specialities on the same location.
In my create method i check for duplicate records by synchronizing on the database file. I have use a dummy lock to prevent other threads for creating the new record.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. make sure that name and location fields are not null
2. make sure that the combination of name and location fields are unique.

Is the above necessary?

or would you allow name and/or location fields to be null in argument-data array of create method.



Hello Mary,

1)
I would assume that those fields are required as it is no use adding a contractor with out a name and location. The whole purpose of this application is to book a contractor to a particular owner.


2)I would use the name and location together as unique.

3)Regarding the owner field,I would insert empty spaces for the owner field.

John
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John

After reading many post in this forum, I finally decided not to allow any nulls in the any of the fields. If there is a null in the data array the create method would throw Illegal argument exception.


To allow for empty owner field, I would require a ""(empty string) to be sent in.(not null)

I was not planning to validate any further as to whether there is really some name or location or is it just ""(empty)/ As long as it is not null I thought it was fine.......

Is this how everybody else do? Since you mentioned that name and location cannot be empty I am now confused again as to whether I should validate these two fields??


Thanks
 
John Mattman
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this how everybody else do? Since you mentioned that name and location cannot be empty I am now confused again as to whether I should validate these two fields??

Mary,
In my B&S project, i am validating the name and location fields when creating a new record.
[ April 09, 2008: Message edited by: John Mattman ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic