We are planning an application using EJB, JPA (persistence) & JSF (Primefaces) architecture on JBoss EAP 6.4. The way data is stored in the database or the nature of the application is, we need to use/implement Role Based Security from application layer as well. We are able to create multiple DB Connection pools (to the same DB instance) in JBoss container and each JNDI is associated with a specific DB role. In other words, if I use JNDI_Role1 connection then it will return rows from DB table according to Role1 vs if I use JNDI_Role2 connection then it will return rows from the same DB table according to Role2 which would be different then Role1 and so on. We have 4 different roles created in DB, so 4 different JNDI connection pools in JBoss container.
Now, can I implement this in my Persistence layer? If yes, how can I do that? Should I create multiple EntityManager instances tied to each connection pool/JNDI? Any suggestions with some sample code would be really appreciated!!
Thanks in advance!!
There are some links which describes role based security: See the links
[1]https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html-single/Security_Guide/index.html
[2]https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/6.4/html-single/how_to_configure_server_security/
[3]https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/6.4/html-single/security_architecture/#role_based_access_control
Related
I have K2 blackpearl application which have 2 databases: 1 is k2 database i.e. product database and another is the application database for keeping application data. I am not aware how the application database was configured, but I want to change the application database location to some different serer.
I have already checked smartobject tester and hostserver configuration.
Any idea where i can make connection string changes for this?
If your "Application Data" contains LOB data and is used in your custom solution, you need to perform the following to change it to different server:
Backup that database
Restore it to different server
Edit configuration of Service Instance (SQL Service Instance) corresponding for that database according to that different server
configuration. Usually, it is required to change "Server Name", "Use
Native SQL Execution" and "On Different Server" properties on that
service instance. You can perform these changes using K2 Management site or
SmartObject Service Tester Tool
If your K2 application uses SQL Server as a data source then it most likely uses SQL Server Service broker for this type of integration. If you are new to K2 you have the following logical hierarchy:
Service Type
Service Broker
Service Instance
SmartObjects
Service Broker it is something that allows you to connect to external system (SQL Server in your case) and Service Instance represents instance of this system accessible to K2 (SQL Server database) based on which you can create SmartObjects - representations of objects within external system with which K2 can interact (SQL tables, stored procedures etc. in your case).
I hope from description above it is clear that your app DB connection string lives at Service Instance level. To adjust it you have to do the following:
1) Run SmartObjects Services Tester (default location: "C:\Program Files (x86)\K2 blackpearl\Bin\SmartObject Service Tester.exe")
2) Expand SQL Server Service category and select service instance corresponding to your app database. It should be clear from name (if naming conventions were followed when it was created), but if not just edit its properties - there you will see Database and Server properties corresponding to SQL database name and SQL Server name respectively.
3) Once you located right service instance just edit its properties adjusting server and database name. Here how it looks like:
If necessary refer to #Dragan Panjkov answer or documentation I mentioned above for information about additional settings you may need to adjust.
To do this you need to run the K2 setup tool - you can access it from the start menu. You just need to run through the wizard (which will be pre-populated with your existing settings), and update the K2 database settings when you get to it.
I am trying to create a jdbc connection to a postgresql database. I would like to use a datasource. In the documentation of postgresql is stated that one should not use their own implementations of the datasource, but use the implementations of org.apache.commons.dbcp instead. The SharedPoolDatasource looks perfect to me.
The jdbc driver must be postgresql. Glassfish v3.1 offers the opportunity to create a jdbc connection pool. I would like to use that one, but do not know how to make the connection between the commons datasource implementation and the jdbc driver. When I fill in the document on the glassfish server that particular field blanks out forcing me to use the postgresql datasource implementation.
Is this impossible to achieve or do I have to enter data manually in config files? So far I did not have any luck nor feedback. Exceptions should appear in the server.log, but the server.log currently does not show anything (it did show exceptions deploying jsf and ejb applications).
Should be possible....
1. Create a new JDBC Connection Pool:
2. Choose your desired Datasource Implementation Class:
You'll have to setup the details for databasename, user and password in the additional properties tab.
3. Create a new JDBC Resource:
I have a WebSphere ESB 7.5 hosting a web service (inside a mediation module).
The data from the web service should be stored to a DB. DB access should be performed via JPA.
I would like to utilize JPA with WebSphere's container-managed transactions (so JPA just replaces plain SQL calls and that's it). I don't want to generate an EJB from this tutorial. This seems unnecessary for my case.
Is it possible? Any code example?
There is nothing in the JPA specification that mandates it be used in an application container or via EJB's. But, as to your second condition, container managed transactions are defined at the level of the container, and more specifically, they are only valid for use in entity beans. So, your options are to use:
JPA + non-entity beans + user transactions
JPA + entity beans + container managed transaction.
I want to create an entity class from database. My database would be HSQL and i use file to store the data.
I have no problem to config the connection pool to connect to this database # glassfish The name of the resource which uses the connection pool (HSQL-file) is HSQLJdbcResource:
And no problem to reach this resource from a JSP file, this code works perfectly:
But i do have a problem, when i want to create the entity class from database with the netbeans wizard, because somehow the neatbeans can't find the driver for this :
I have the driver and attached to the project and also i can manage to create the entity class trough std datasource but i want trought glassfish resource, because if dont do the way like this --- the file will be locked because of my JPA which use glassfish resource and connection pool... Vicious Circle, is there any solution for this?
Please check to see if the driver path is correct.
Add the hsql driver in your system class path.
Also, this might be helpful: http://hsqldb.org/doc/guide/ch04.html
I'm developing a web application at the moment. The web application needs to access a Patients database, which for now is a simple MySQL database but may likely be replaced by some other DB (or data source) in the future. At the moment, everything is hardcoded but I would like to have some way to configure the DB connection (that is, the database URL, user, password etc.).
What would be a simple and straightforward solution? It would be good if I could change the configuration by simple editing of a file.
I've seen there's the Properties API as well as Preferences. Or is there some idiom concerning servlets/web apps?
A servlet is part of a web app, and this web app is deployed in a Java EE container (Tomcat, WebLogic, etc.).
The standard way to get a database connection is to use JNDI to get a DataSource instance, and to ask a connection to this DataSource. The DataSource, most of the time, will pool database connections to avoid creating and closing too many connections and thus be much faster :
Context initCtx = new InitialContext();
DataSource dataSource = (DataSource) initCtx.lookup("java:comp/env/jdbc/MyDataSource");
Connection c = dataSource.getConnection();
try {
// ...
}
finally {
c.close(); // makes the connection available for a new thread
}
The DataSource will have to be declared in the web.xml file:
<resource-ref>
<description>Datasource example</description>
<res-ref-name>jdbc/MyDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
It will have to be defined (with its URL, number of connections, user, password, settings, etc.) inside your Java EE container. This is where it depends on your container.
Read the following explanations for Tomcat : http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
I think a configuration XML along with your web application is a good idea. Each time the application is initiated by a new request the configuration is loaded and the database connection information available from any internal context that you make.
On IIS this is a standard way through the Web.config file.
regards