0

I have a login page which connects to a Database, the Database has only one client, when a user logs on he/she may make certain changes to his profile and then save. A large number of frames require the current user id in order to manipulate his data

Among the possible ways of storing the user currently logged in is

1) to save the data to a temporary text file and persist it before the user logs out

2) another option would be to use variables across all the frames ,however I'm not too confident about this

3) a third way would be to have a Boolean column in the database and to persist the the data of the field with true in it

Perhaps there are better ways of storing the current user Id could somebody elucidate other possible methods and highlight the pros and cons of each implementation with reference to an "optimal" method of doing this

Edit: This is a desktop application

Ayvadia
  • 199
  • 1
  • 3
  • 18
  • 1
    What technology are you using? Is it desktop application or users login through the webpage? You can use `sessions` for this. – libik Oct 13 '13 at 18:43
  • Well you can think about this : [ http://docs.oracle.com/javaee/1.4/api/javax/jms/Session.html ](session) – libik Oct 13 '13 at 18:46

2 Answers2

2

I would suggest not to share this information in any static context for the reason it will render your project as very hard to test once it gets big enough. See this link for more info: When to use singletons, or What is so bad about singletons?

What I would do is store session objects in some map, identifying the appropriate session by an ID that will be given and sent back to you via client cookie. This is how the web has been doing it for years, and it is still doing it this way. Simply pass the session object around to any class that requires access to that data when it needs it.

If you are using a J2EE implementation, then you may already have support for sessions within that implementation, you should check out "How to Use Sessions"

This is more of a software design question, and covering the basis to complete the patterns used to support what I just suggested is unfortunately beyond the scope of the question

Community
  • 1
  • 1
Ben Barkay
  • 5,115
  • 2
  • 18
  • 29
1

The logged user is an instance of the class Person or LoggedUser.

You have to instantiate it and share its reference between Views via a Model.

Aubin
  • 13,790
  • 8
  • 55
  • 78