Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / August 2004

Tip: Looking for answers? Try searching our database.

EJBs & CMP with real database users

Thread view: 
Matt Hughes - 24 Aug 2004 17:16 GMT
I am in the beggining stages of designing a J2EE application.  The
current application that I am porting to J2EE maintains real users in
the database, not just a user table.  That is, every connection to the
database must be made with the individual username/password for each
user.  All the examples and literature I have read regarding CMP
entity beans only has one user for all beans.  Is it possible to let
users log in to the application using their creditials (which would in
turn connect to the database) and only let them view data they are
allowed to see?

My major problem is that there are a lot of views in my DB schema that
are based on user_id.  I have little control over the schema and do
not feel like reimplementing 20 or so views in my code.  Has anyone
run into this problem or know of a solution?
Fredrik Bertilsson - 25 Aug 2004 09:23 GMT
I am afraid that J2EE will not help you very much here. Normally J2EE
applications are using connection pooling. The datasources are defined
(url, driver, user, password, etc) in a configuration file. When the
application want a connection it makes a lookup using the datasource
name. But the database user normally has to be defined in the
configuration file.

I think that you can't use connection pooling at all. Every user has
its own database session. You have to create connections (instead of
doing lookup), using JDBC DriverManager. Because you are not using
connection pooling, you have to check with you DBA that a user session
does not allocate too much memory on the database server. Otherwise
your application will scale very bad.

I also think that you can't use J2EE transaction handling, because you
are not using connection pooling. You have to do commit and rollback
explicit in your code. Or you can use some AOP (Aspect Oriented
Programming) framwork (like spring framework) and put the transaction
code in some post-processing code.

Because you are not using the two most important features of J2EE
(transaction handling and connection pooling), maybe you should not
use J2EE at all. It is a big overhead in money and performance using
J2EE.

/Fredrik
Jon Martin Solaas - 26 Aug 2004 23:30 GMT
> I am afraid that J2EE will not help you very much here. Normally J2EE
> applications are using connection pooling. The datasources are defined
[quoted text clipped - 22 lines]
>
> /Fredrik

How do you propose database-access not using j2ee? Remember jdbc is part
of j2ee ... Why not use bean managed persistence? It's perfectly
possible to implement entity beans using any persistence scheme you
want, including per-user connections to a database. It also makes sense
to persist the per-user-connection throughout the session in a pool
instead of re-connecting each time the database needs to be accessed.
It's certainly better to let all users share all connections in a common
pool, performance-wise, but it's not mandatory.

Signature

jonmartin.solaas¤h0tm4i1

Fredrik Bertilsson - 27 Aug 2004 06:25 GMT
> How do you propose database-access not using j2ee? Remember jdbc is part
> of j2ee ...
JDBC (java.sql and javax.sql) is a part of J2SE not J2EE.

>It also makes sense
> to persist the per-user-connection throughout the session in a pool
> instead of re-connecting each time the database needs to be accessed.
Correct. I didn't say that the connection should be closed after every server call.

/Fredrik
Jon Martin Solaas - 27 Aug 2004 09:28 GMT
>>How do you propose database-access not using j2ee? Remember jdbc is part
>>of j2ee ...
>
> JDBC (java.sql and javax.sql) is a part of J2SE not J2EE.

No. JDBC is described in version 1.4 J2EE.2.6.6. Also, JNDI is
J2EE.2.6.8. Both are distributed as enterprise features in J2SE, though,
along with a couple of other J2EE features as well.

>>It also makes sense
>>to persist the per-user-connection throughout the session in a pool
>>instead of re-connecting each time the database needs to be accessed.
>
> Correct. I didn't say that the connection should be closed after every server call.

So why do you absolutely not want to use a connection pool for this
purpose? You'll have the opportunity to let each user have more than one
connection at a time, the pool will handle the connection for you
automatically, you won't have to re-connect if the connection closes for
you and so on. Sounds much better to me ... writing code to handle such
standard stuff is just a waste and opens up for nasty bugs nobody really
needs (unless those who write debuggers, ofcourse :-)

Signature

jonmartin.solaas¤h0tm4i1



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.