Alain Dickson

Ranch Hand
+ Follow
since Dec 08, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alain Dickson

Hello,
Please help!

I am new to ORM, I am designing access to existing data.

Example Problem: I want to get a particular customer by Id(007). I have two ways of doing it.

Assumption: I have a @Entity class Customer mapped to Database table.

1. (OO Way)
Customer cust = entityManager.find(Customer.class, Id);
String fName = cust.first_name
String lName = cust.last_name

2. (QL Way)
String querySt = "SELECT c FROM Customer c WHERE c.Id = '007'";
Query query = entityManager.createQuery(querySt);
Collection <Customers> cust = query.getResutList();
String fName = cust.first_name
String lName = cust.last_name

Q1. Am I using the correct steps in using both of them,
Q2. If I prefer to use the first one are there any disadvantages to it.

Many Thanks
Alain
Thanks Ankit...
But if JBoss 4.x is JEE5 compliant it should support Injection services...., With which server did you try injecting EJB.
Alain.
14 years ago
Hello All,

Can I use DI (@ EJB ) in servlet to access EJB methods, instead of using Naming service.
Both Servlet and EJB(Session/Entity) being on the same JEE Server.

Thanks,
Alain
Pete - try this, I used this one for myself. It allows editing.

http://www.hexedit.com/download.htm

Download version 2.5 (Free).

Alain

Second choice:
make an atomic operation of the find and multiple reads



By this Roel meant, don't send the record numbers back to the client from the server.
When server received request for a search do two things on server
1. Find the record numbers (Using the find method) which match the search criteria
2. Staying on the server put records corresponding to the record numbers found at step 1 into a string array
THEN return the array to client instead of first sending record numbers to client and then again asking for records corresponding to those recNumbers.

This will be considered as good design and will also decrease the network trafic.
This is how I did it.

Roel: correct me if you meant something different.
You might want to try your Java muscle in "Java FX coding challenge". Last date to submit your project is May 29th 2009. See the link below for details.
http://javafx.com/challenge/
Since you have inclination towards GUI, Java FX can be interesting to you. Moreover you will learn a fantastic technology and who knows, you can win $25 Grand.
If I had time I would have gone for it.
I also liked the idea of getting involved in open source project. Open Office is a great project and it needs many additions to compete with others in market.
http://contributing.openoffice.org/

Alain
Hi Bert, let me take one more chance on this....

Rajesh:

The delete flag 0x8000 == 32768 which is greater than two bytes
BUT we have to write this in two bytes(as data File schema only gives us two bytes)
THEREFORE 0x8000(32768) can only be represented as -32768 in two bytes. (I don't think there is any other way to represent this number as positive number in two bytes).
THATS what the method writeShort(int x) of RandomAccessFile does. It does some bit operations and write writeShort(0x8000) as -32768.
WHEN you read using readUnsignedShort() it reads it as 32768==0x8000

Rajesh Said:
if (readShort()==0) {
valid record;
}
else if (readUnsignedShort == 0x8000) {
deleted record;
}
else {
no idea; // can someone explain ?
}



Answer to "else" Part: Database is corrupt, the schema does not allow anything else. So when you do any operation on database check if it is valid(don't read deleted or corrupted records) EXCEPT when you are adding a new record you might want to use a space of deleted record, where you have to look for deleted record (0x8000)
Assignment: B&S-2.3.2

First of all I want to extend my Thanks to:

GOD: Who is source of all Knowledge and Virtues (Believe it or not)

Kathy Sierra & Bert Bates: For writing wonderful book for SCJP. It helped me in both SCJP and SCJD. The section for SCJD in this book is small but very valuable. The insight you people have provided by asking important questions is awesome. The light humour is also part of the book and keeps the reader from getting bored and de-motivated.

Ranches: After getting guidance from the above mentioned book, My practical problems were solved by Ranches. I found answer to almost all the uncertainties in assignment requirements here.

My Score:
General Consideration: 100/100
Documentation: 70/70
OOD: 30/30
GUI: 16/40
Locking: 80/80
Data Store: 40/40
Network Server: 40/40
Total: 376/400

Why I might have lost marks in GUI: (Some afterthoughts)
1. My GUI Window could not be resized below certain size, I put this constraint because the components totally lost their coordination below certain size, Because of time shortage I just made a quick fix and set the minimum size.
2. After typing in the search criteria the user had to click search button, Search didn't work with enter key, I kept postponing it and finally missed it.
3. When user-supplied keyword(s) did not produce any search results, JTable was cleared(old search results lost) :- In this case I guess there was nothing wrong with my choice BUT I did not explain it in my choices.txt.

DOs:
1. Try to have a project plan and check lists especially for final packaging - don't miss the RMI Stubs though you might pass without them.
2. Spend lot of time on designing/coding locking mechanism and testing it.
3. Keep things simple, it won't hurt the marks
4. I have read on this forum that assigning file header values to constants can fetch you full marks, But I read it after I had implemented dynamic file header reading, Which took lot of my time. It also added to complexity of my project. Keeping header values as constants can easily be justified in choices.txt.
5. Prepare for your essay exam carefully, Though you know everything but how you put it in writing makes lot of difference. As far as I understood it, Essay should be written from the angle that it is the first point for the examiner to start understanding your assignment and your coding style. If you give him/her clear picture through your essay(concise and clear) you will definitely favour your score.

I will be happy to answer any specific questions.
Thanks once again..!
Best of luck to all who are working on thier assignments and those who have submitted them and are waiting for results.

Alain Dickson,
SCJP 6, SCJD


14 years ago
Hi Rajesh, Sorry for delayed response man! I was too busy.

1) range of short is between -32768 to 32767
2) delete flag = 0x8000 = 32768. This is outside the range of short.



Just wirte a small code and try writeShort(0x8000): Since this method accepts "short" argument the complier will not allow anything larger than short without a cast.

I did writeShort(0x8000) for deleteting a record and writeShort(00) for marking a record as valid.

It will work, and you will not have any problems due to this...

Alain Dickson,
SCJP 6, SCJD

Rajesh - try having look at the data file in a hex editor, The empty bytes are shows as 00 00.

When you write to file using RandomAccessFile's writeShort(00)... it produces same results in data file. I just learned it by writing to file in different ways.

It is good to understand why's and how's of things, But some times Just making the things work and move forward is a good idea for this assignment.

I understand that when we are working on this assignment we tend to get into detail of everything, but trust me don't get too emotional about this assignment, Make things work right and let it go. If carefully searched, this fourm quickly tells you how to achive desired results.

I hope this helps..

The answer is as simple as your question:

Interface is a contract, If you want every class that implements this interface to have the constants, they should be in the interface else in implementing class.

"public Static final" : here, what I understand from your question is that you are concentrating on "public" part i.e. data is visible to everyone, but if you shift your attention to "final" part - no one will be able to change it. The only fundamental of having private data in a class is that no one can alter it in an inappropriate way(thats why you have getters and setters), but here it is "final"
Alecsandru is right, I mentioned one to keep it short.

Here is some Detail:
for Name:Two options are "any" and "Contractor Name"

for Location: Two Options are "any" and "Contractor Location"

When user selects second option for Name/Location it is set to blank indicating to type in Name/Location.

User can type in for both Name and Location:- which gets records where both name and location matches
User can type in name and set location to any and vice versa.
User can set both to any: in which case all records will be loaded into the Table.

Kevin - I have adopted a hybrid approach, My Combo Box is editable with two options "any" and "Contractor Name" taking example of Contractor Name(B&S assignment).

if the user select the option "contractor Name" I set it to blank space and let user type what ever he/she wants to search. Hence i don't wory about updating the list when ever database changes and also even if the database grows huge in future, I don't have to wory about it.

worrying about client crash during locking is a problem ONLY when you are calling lock/unlock from client.
Make client request the server to book a record, and let server take care of locking/unlocking: In this case it won't matter even if the client crashes.
and specifications don't stop from doing this.