This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

Daniel Bryant

Ranch Hand
+ Follow
since Jul 15, 2006
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 Daniel Bryant

Hi Shailesh,

Many thanks for your comments - I'll definitely keep them in mind (and you make a really good point about the deletion column, which I had completely forgotten in my current implementation!!)

I was also wondering what the impacts are of altering privileges for the Hibernate framework, but I may have to ask that on a more specialized forum.

Thanks again,

Daniel
Hi all,

I'm using Hibernate in my application which is about to go into production. Can anyone provide any guidance as to the recommended privileges the user that Hibernate connects to the database should have?

At the moment we are using this script on our mysql database:



Could granting all privileges pose any unforeseen security risks, and would Hibernate work correctly with less privileges?

Many thanks,

Daniel
Hi Carol,

Many thanks - now I remember reading this page when I was first learning about DWR, but it completely escaped me!! Now I have set each of my bean creators scope attribute to session in the dwr.xml config file and everything is behaving as expected.

Your pointer to the documentation was great, and very much appreciated.

Best wishes,

Daniel
[ November 19, 2007: Message edited by: Daniel Bryant ]
Hi all,

I wonder if anyone can help with a conceptual problem I'm having with DWR? Where/how are my server-side objects which DWR calls methods on bound? Are these objects bound to a user http session?

I understand that DWR uses a main servlet that is used to route client-side method calls to appropriate server-side classes and methods, but how are the objects stored (i.e. how are they scoped, session or context etc?), and when are the server-side classes that I have programmed instantiated and when are they eligible for garbage collection?

For anyone that wants any context I am trying to include user authentication in each of my DWR server class constructors, but I need to be sure that each user will have their own instance of the server side class and not share them (because each user will have different privileges). My experiments have so far proved confusing...

Best wishes,

Daniel
Awesome! This is exactly what I was after. You won't believe how much I searched for this yesterday - I think I fell into the "Google knows all" trap

Many thanks for the guidance.

Daniel
Hi all,

I'm attempting to incorporate DWR into a struts application I have developed and I'm wondering if anyone can help me with a question. I've spent a while Googling but just can't seem to find the answer..

In Struts I can force users to log in to the application and then place a User bean in session scope that can be checked for correct login and associated credentials (this is all standard stuff). This works because in each Struts Action execute method I can gain access to the HttpRequest object and call the getSession().getAttribute(..) methods. The question is how can I replicate this in a DWR method call?

As I understand it with DWR I can specify in a declarative configuration file that the client can access certain method on my Business Objects, but obviously these methods don't have access to the HttpRequest object.

The main point of this is that I want to stop unauthorized access to my BOs via javascript/ajax

Any help or clarrification of my ideas is much appreciated!!

Daniel
Hi everyone,

Thanks to all for your input, especially Peter

TableModel does not need to have any state, if you want to have an clean cut between model and view, you should have your TableModel query the Model (of your MVC) rather than contain it�s own internal list of objects to display.



I think this is what I was after - I'm going to have a think about my design, but the TableModel querying the Model would overcome my concerns about the level of dependency between the View and the Controller.

Best wishes,

Daniel
Hi all,

In my URLyBird assignment I have attempted to use the MVC design pattern for the GUI and connection to the DB.

I have designed a JFrame based GUI (which is the View) which displays the hotel room data (using a JTable and associated subclass of AbstractTableModel) and handles button presses by calling methods on a GUIController class (which is obviously the Controller).

I've tried to design my GUIController much like the example in Andrew's SCJD book, and therefore when a user books a room the controller calls the appropriate methods on the implementation of the DBAceess interface (the Data class), i.e. lock, update, unlock, and returns appropriate results or an error message to the View. Therefore this made me believe that the implementation of the DBAccess interface is the Model (as it manipulates the database) - accordingly in standalone mode the Model would be the Data class itself, and in Network mode the implementation of the RMI Remote Interface which communicate with the server would be the Model.

However, when a client wants to search for records the GUIController calls methods on the Data class and returns an instance of a subclassed AbstractTableModel containing all the Room data matching the query, and then the view uses this model to display the search results.

1. My main question is do you think the subclass of the AbstractTableModel is part of the View (as it is displayed in the view), or part of the Model (it is created by the controller and passed to the view, but it does contain "state", i.e. the room record data, and it also has business style methods that, for example, can be called by the JTable to display the background of each column in a different color depending on if the room is bookable)

2. A second question is that when a user books a room, the original room data that was in the JTable must be passed to the GUIController to allow it to check that the room data in the database is the same. Do you think it is acceptable that my view has to extract the record from that JTable AbstractTableModel and pass this an an argument to a GUIController method? (I can't simply pass the record number into the GUIController, because apart from creating an instance of the AbstractTableModel when a search is complete the GUIContoller does not know about (or maintain a reference) to the AbstractTableModel

I'm trying to write up my choices.txt and don't want to say something silly (such as getting the Model in the MVC pattern wrong ). Any wise words would be most appreciated...

Daniel
[ August 21, 2006: Message edited by: Daniel Bryant ]
Hi Luiz,

I've done something similar to what you have suggested - I think if your database survives this many concurrent accesses you can be reasonably sure your file access is safe and you have avoided deadlocks.

In order to further analyse what was going on I have also recorded all the expected and actual successful operations (i.e. every attempt to create a record, and every sucessful create), and every exception and lock contention . I found I could tweak my lock code to reduce what was originally a shocking figure for lock contentions )

I also created seperate tests in which I created a series of artifical situations. For example, I used the sleep() method to pause a series of threads to increase lock contentions, and I also simulated threads gaining and losing CPU time at unfortunate places within the code, such as just before writing a new record or releasing a lock). I also created a few tests in which hundreds of threads attempt to repeat certain operations on a single record or take part in a series of operations that could be dangerous . For example, try and have hundreds of threads deleting a random record, and only if they succeed creating a new one - the size of your DB should remain constant (mine didn't on first try of this test) This test will also show if your code reuses deleted recNos properly and doesn't write a record to an unexpected location within the file.

I hope this helps

Daniel
[ August 17, 2006: Message edited by: Daniel Bryant ]
Hi Tony,

I'm keeping a reference to the stub - I think that doing a lookup each time would be inefficient (and I can't really see any advantages for doing this?)

Best wishes,

Daniel
Hi Oricio,

Thanks for the feedback.

Our locking methods ensure logical consistency of data and transactional behaviour even client side.
CRUD operations behind a DAO could be upgraded without change locking implementation, ensuring backwards compatibility.



This is a good point - I was thinking a RDMS would handle all the transactions etc, but I see what you mean (I'll have to give this some more thought... ). Just out of curiosity do you use a transfer object on your server-side implementation of the DAO pattern (for example returning a Room object to the client instead of an array of Strings)?

I have a question for you:
why are you using singletons?



My thoughts behind this decision is that if someone was to alter my design in the future and instead of instantiating just one Data object (which I do now), needed to instantiate multiple copies of this object (for example, each thread needed it's own copy of the Data class) then the Singleton pattern ensures there would only ever be one FileManager or LockManager object, and therefore there would be no potential for such situations as two FileManagers (in the same JVM) both updating the same record.

However, I am keen to hear if you have any thoughts or criticisms on this design.


Best wishes,

Daniel
Hi Oricio,

An interesting thought - the reason I have used a FileAccess class is that if our "customer" changed to using a RDBMS they would have to alter both the physical access and locking (which would most likely be provided by the RDBMS) which would mean a complete redesign of the class implementing the DBaccess interface anyway.

I'm not sure of this, but do you not think using DAO would be overkill for this project? Would it be ok for a junior programmer to understand?

Best wishes,

Daniel
Hi Daniel.

Welcome to the Ranch...

With regard to your question

In my assignment, i'm provided some smarts to the search functionality..for instance my search code is case in-sensitive



I agree with Jeroen - you're taking a risk here, but if you document you thoughts on the subject in the choices.txt you probably would get away with this.

and will match a value if it starts with the value entered by the user.



I think this is an auto-fail. My spec says the server MUST perform a search where a record is returned if a field String starts with the associated criteria String (what you are proposing), but my client-side spec states that only an EXACT match for the fields MUST be returned.

Many posts I've read on the Ranch believe that Sun have deliberately given you different search specs for client and server in order to see if you have read and understood the requirements.

I know it could be argued that you are helping out your users by providing better functionality, but I don't think it's worth deviating from the given specs (and if in doubt I usually think about what I do in the real world - here in a real project I wouldn't add functionality to a search algorithm/mechanism if the client had signed-off, but I probably would mention this as an possible addition)

Best wishes,

Daniel
[ August 16, 2006: Message edited by: Daniel Bryant ]
Hi Richard,

Your design sounds similar to mine, with just a few minor details changed:

Data.java is a fascade which contains (and delegate appropriately) a FileAccess and LockManager reference (both Singletons).

For the remote connection to the DB I have an adapter on the client-side that adapts my Remote Interface to the DBAccess interface and handles the RemoteExceptions appropiate (throwing an GUIException, that is caught elsewhere). I don't instantiate the appropriate class (direct or adapter) to connect to the DB using a factory, but I guess I could.

I hope this helps.

Daniel
Hi Luiz,

I would have to say no to that being ok...

But how about this?

- Client A selects a record, the update screen is showed
- Client B selects a record, the update screen is showed
- Client A update the record (lock, READ RECORD, CHECK EXPECTED VALUES, update, unlock)
- Client B update the record (lock, READ RECORD, CHECK EXPECTED VALUES, update, unlock)

where the READ RECORD, CHECK EXPECTED VALUES part of the process reads the record again (which has now been locked) and compares this read with the existing data (i.e. the data you expect). If the two don't match you know that someone has updated the record before you, and you can abort the process and inform the user accordingly.

Best wishes,

Daniel