aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Mapping Database Fields to Record Array Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Mapping Database Fields to Record Array Question" Watch "Mapping Database Fields to Record Array Question" New topic
Author

Mapping Database Fields to Record Array Question

Marcelo Ruiz
Greenhorn

Joined: Dec 19, 2007
Posts: 25
Hello Ranchers!

I have a kind-of-silly question regarding mapping the database record with the String Array that the required interface requests.

My problem is from the understanding of how mapping works, and maybe because English is not my first language.

This is from my specifications:

* (1) From the read method: "...Returns an array where each element is a record value..."

* (2) From the find method: "...Field n in the database file is described by criteria[n]..."

* (3) From the update method: "...The new value for field n appears in data[n]..."

The confusion I have is that (at least in my mother tongue) we start counting at 1. So if the database has 6 fields (like in B&S) field 1 (the first one) will be "name", and so on...

So, according to (3) the mapping should be:

Data[0] -> No mapping defined (it could be used for versioning)
Data[1] -> Db Field 1: "name"
Data[2] -> Db Field 2: "location"
Data[3] -> Db Field 3: "specialties"
Data[4] -> Db Field 4: "size"
Data[5] -> Db Field 5: "rate"
Data[6] -> Db Field 6: "owner"

The result of this approach is that my Data[] length will always be equal to the number of fields in the database PLUS ONE.

So far, all the postings that I read in this forum use this mapping:

Data[0] -> Db Field 1: "name"
Data[1] -> Db Field 2: "location"
Data[2] -> Db Field 3: "specialties"
Data[3] -> Db Field 4: "size"
Data[4] -> Db Field 5: "rate"
Data[5] -> Db Field 6: "owner

The result of this approach is that my Data[] length will always be equal to the number of fields in the database.

I would like to hear/read your thoughts about this.
Cheers,

Marcelo.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Hola Marcelo! Saludos de Brasil!

Champion, the best option is to assume that the mapping always starts from 0. And better yet, you can create a class to represent a record in the database. Therefore, the second example is the best option.

Another thing I did, I also created a class called RoomRetriever with 2 static methods, one that retrieves a Room object, given a String array, and another method that retrieves a String array, given a Room object.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Marcelo Ruiz
Greenhorn

Joined: Dec 19, 2007
Posts: 25
Oi Roberto! Muito Obrigado!

I already programmed the database assuming the mapping starting at 0. But I was wondering if the first approach adjusts better to the specifications (which will give me the extra benefit of using the first element of the array for versioning).

I was wondering about that because re-reading the specification (Bodgitt & Scarper) I realized that in the Server section it requires the data access class to be called Data.java, and I previously assumed that was the class for accessing the database locally, not the one the server should return to its clients (if I am understanding that well)... The point is that, after noticing that, I tried to find unclear points in the specification, and the mapping issue was one of them.

Thanks for you help!

Marcelo.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

You know partner, one good tip is to try to think of each component/layer isolately. The good thing of this approach is that you can increase reuse, and that eases the definition of your API.

The Data class is to be used locally and remotely. When using it locally, you can have a business/services layer which uses it directly. When using it remotely, you can either define a remote implementation that holds all the business logic and uses the Data class (thin client) or you can define a remote interface that looks like the one that was provided to you in the assignment and put the business logic on the client side (thick client). But the same implementation of the Data class is to be used locally and remotely.
Marcelo Ruiz
Greenhorn

Joined: Dec 19, 2007
Posts: 25
Hi Roberto,

Thanks again for your answer. I am designing my solution with the concept of layer isolation in mind.
I am wondering if any native English speaker could explain me why the second solution should be the one to implement. I really want to understand if I am misinterpretating the specification, or if is a lack of common sense, or whatever.
Could I fail the certification by implementing the first solution? I am concern with the initial software checks...
Thanks again Roberto for all your help,

Marcelo.
Matheus Mendes
Ranch Hand

Joined: May 15, 2007
Posts: 66
Grande Marcelo !

Roberto already saids what I think too, but your question about fail. The fail only will happens if you do not explain in your choices.txt why you use the first type of data and not the second. The second is most used because it's the natural form to work with arrays, I think.


The Death of one is a tragedy, but the Death of a million is just a statistic. Joseph Stalin

SCJP 6.0, SCJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Matheus Mendes wrote:The second is most used because it's the natural form to work with arrays, I think.


You bet!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mapping Database Fields to Record Array Question