• 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

Wrap a record class

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

I want to create a record class to represent all information in each record.

I have two points difficult to understand.

1) If I use any network implementation (like RMI or socket), must I implement Serializable interface?

2) Because the program need to search all records or part of those by name AND/OR location, need I do to put the two arguments into the constructor of record class?

Many problems looks insignificant,but they are able enough to block the process of My assignment.

Thanks in advance.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard Jackson:
Hi, all

I want to create a record class to represent all information in each record.

I have two points difficult to understand.

1) If I use any network implementation (like RMI or socket), must I implement Serializable interface?



Yes, any object that is available through your exported Remote object must implement Serializable. Don't forget the serialVersionUID

I take it you are in the thin client camp then?

Got any juicy arguments for the thin client approach for your choices.txt?



2) Because the program need to search all records or part of those by name AND/OR location, need I do to put the two arguments into the constructor of record class?



You could.
Do you mean like 'find records like this record?'

Record[] results = business.find(myRecord);

Certainly a valid approach, presently I just do:

Record[] results = business.find(name, location);

but I may refactor towards the former.





Many problems looks insignificant,but they are able enough to block the process of My assignment.

Thanks in advance.



Don't I just know it!
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,

2) Because the program need to search all records or part of those by name AND/OR location, need I do to put the two arguments into the constructor of record class?


You could, however you don't have to. The only required field (fileds) should be in the constructor is your primary key. A record could exist with empty fields, however the primary key cannot be empty, hence the only field/fields you ust requir is what you consider your primary key.
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,mike and Hanna

Thanks for your reply!

mike
Yes, any object that is available through your exported Remote object must implement Serializable.


I see. Whether using RMI or socket,it is always required.

mike
Don't forget the serialVersionUID


The "serialVersionUID" must be needed? Please give me comments.

Hanna
The only required field (fileds) should be in the constructor is your primary key.


Yes, I agree. Because primary key is most important element in database.
But how can I do to add and implement the primary key?
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard Jackson:

The "serialVersionUID" must be needed? Please give me comments.



Do a google under 'serialVersionUID' it is not necessary as the compiler will give you one, but it is good practise.




Yes, I agree. Because primary key is most important element in database.
But how can I do to add and implement the primary key?



I am confused here too. This is the main reason I have not implemented a find(Record criteria) method.

I know this signature is a common approach in other frameworks (eg Hibernate)

However, I do not see how the primary key has any meaning.

If we consider that we are trying to match fields of record to the argument, what does it mean to include a primary key? the only thing I can think is it means get the record with this primary key. Okay but if we don't want that we should set it to -1 or some other value that can not exist. Is the record object being abused in this way? But I think it is a common idiom

If we mean find records like this existing record then we could say ignore the primary key in the business logic, but how to know to ignore some fields as we only want to match on name & location.

For the record My Record c'tor signature for adapting Data.find() is:

public Record(int recNo, String[] data)
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,

But how can I do to add and implement the primary key?


There are few different approaches to this. You can choose one or more fields in the record, and consider them your primary key. Of course, you have to indicate that in your choice doc.
Most people here choose the name and location fields as primary key. If a user attempts to add a record with the same name and location as an existing record, the data layer will throw duplicate key exception.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

However, I do not see how the primary key has any meaning.


In any database design, a primary key must exist to uniquly identify individual record. Imagin if you don't have a primary key, and a user attempts to create a new record with the same name and location as an exsisting record. Now you will have a duplicate entries, and most likly represents the same entity.
Primary key is one of the key principals of any database design.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hanna,

I am well aware of these principles.
My query is regarding the 'abuse' of a Record object just for look up purposes.
That record would never be one of the unique set of database records.

consider a method like:

Record myRecord = ...

Record[] records = database.find(myRecord);
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

My query is regarding the 'abuse' of a Record object just for look up purposes.
That record would never be one of the unique set of database records.


Can you elaborate a little more.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hanna,

I think there is a valid approach to retrieving records based on a a Criteria object that is of the same class as the object you are retrieving.

So yes if there is a primary key in the database then the records returned will all have a unique value for that key.

But also a Record object may be used as the criteria to find other Record objects. This makes for a flexible framework.

If we have a method such as

Record[] find(Record record);

then the argument can have any of its field as null

null signifies no filtering on that field.

So for UyB a criteria object could be set up as so:

public Record(Integer key, String[] data);

new Record(null, new String {"Hilton", "London", null, null, null, null, null})

The business logic can then do the right thing for the search.

Much better than the inflexible:

find(String name, String location)
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,
I think we are talking about two differnt things here. A record primary key, for UyB or any other projects, major benefits come when one update or add a new record. I don't see any relevant between a primary key and search methods.
A primary key ensure that no duplicates records exist, also it is used, not in SCJD, in RDBMS to establish relations between differnt tables.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hanna,

think we are talking about two differnt things here



We might well be but I was originally replying to the OP on his mention of Search & Record constructor.
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand and agree to Hanna's statement.

Primary key is exactly unique and important in database.

But I am wondering that we require some effective ways to solve wrapping record object.
According to instructions.html,we should build a record class to ensure module arrangement for all objects in URLyBird or other project.

So I attempt to create some getter and setter methods to construct the record class.

If someone have some different suggestions,please comment and share with me.
 
The only cure for that is hours of television radiation. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic