I am having the following idea to investigate and find out if it possible to work. I am having a db2 server in a linux machine and two kinds of application servers, geronimo and websphere. I would like to know whether it is possible to associate a geronimo or websphere connection to a db2 agent.
In other words, I would like to know which user of a web application is running which query at the database at any given moment.
Thank you in advance,
You could create two users, one for Geronimo, and one for Websphere, both users in a same group. You give the privileges to the group, and both users will have the same privileges.
Then, when you issue a 'list applications' you could discriminate the connetions for Geronimo, and those for Websphere.
If you want to change the application name, there are two approaches depending the java connection.
Class.forName
Class.forName("com.ibm.db2.jcc.DB2Driver");
Properties props = new Properties();
props.put("user", "scott");
props.put("password", "tiger");
props.put("clientProgramName", "My Program 1");
Connection conn = DriverManager.getConnection(
"jdbc:db2://localhost:50000/sample", props);
Datasource
Connection conn = null;
DB2SimpleDataSource ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
ds.setDriverType(4);
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("sample");
ds.setUser("scott");
ds.setPassword("tiger");
ds.setClientProgramName("My Application 2");
conn = ds.getConnection();
You could assign the conneciont name dynamically, by retrieving the application server name.
I wrote a blog about that: http://angocadb2.blogspot.fr/2012/12/nombre-de-la-conexion-java-en-db2-java.html
Related
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
I configured a OrientDB Cluster with 3 nodes.
Suppose that the node names are:
leonardo.domain.ext
michelangelo.domain.ext
donatello.domain.ext
I have a configuration file to get this urls and create the proper url to pass to OrientGraphFactory (e.g. remote:leonardo.domain.ext/mydb)
I create the GraphFactory as following:
OrientGraphFactory factory = new OrientGraphFactory(url,username,password).setupPool(1, 10);
If leonardo is down when I try to create OrientGraphFactory I don't have any issues, but I get an Exception when I do.
factory.getNoTx();
Reading the documentation https://orientdb.gitbooks.io/orientdb-manual/content/orientdb.wiki/Distributed-Architecture-Lifecycle.html I understand that if leonardo go down (for any reason) the clients automatically reconnect to the other instances.
This is valid for the factory and the connection that it will try to create in the future or just for the active ones?
Do I have to manage to recreate the Factory in my application ?
You could use all those addresses separated by a semicolon:
remote:leonardo.domain.ext;michelangelo.domain.ext;donatello.domain.ext/mydb
OrientDB will try connecting to the first, but if it's unreachable, it will try the others in sequence.
It will also do load balancing at client side, if you are on 2.2.x version.
Hope it helps.
I use "Liberty for Java" app and Statica service(Proxy) on Bluemix.
We set http.proxyHost/http.proxyPort/https.proxyHost/https.proxyPort as system properties in Java code every transactions.
for example:
URL url = new URL(xxx);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
........
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port);
........
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
I have an issue that one transaction go from the app to a target server directly in spite of tens of thousands of transactions passed the proxy.
Question 1:
Do "Liberty for Java" app on Bluemix clear or update system properties, http.proxyHost/http.proxyPort/https.proxyHost/https.proxyPort?
I wonder "Liberty for Java" app updated with null to access outer servers in multi-thread environment.
Question 2:
Do "Liberty for Java" app on Bluemix communicate with outer servers?
I found the following log in Statica.
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.agents.na.apm.ibmserviceengage.com
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.gateway.prd.na.ca.ibmserviceengage.com
( I masked a part of URL.)
P.S. We will change java code with ProxySelector class or Proxy class.
Re #1: No.
Re #2: Potentially yes. In your case, it seems your app is bound with a Monitoring & Analytics service? If so, a data collector will be installed and will send collected data to remote servers.
What's the reason that you need to set the proxy system properties in your code? Is it because you want some connections to go through the proxy and others not?
If so, then the way you do this is not right because the system proxy setting is a global setting, not a thread-scoped setting. This means if one thread sets the proxy setting, all threads will then use that proxy; if one thread unsets it, all threads will then do direct connections. That may explain why you are intermittently seeing some direct connections. The right way is to use a http client lib that supports proxy as parameters, like https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/config/RequestConfig.Builder.html#setProxy%28org.apache.http.HttpHost%29
If you want all connections to go through the http proxy, then you should simply set the JAVA_OPTS environment variable to pass in those system properties, e.g., "-Dhttp.proxyHost=x.x.x.x -Dhttp.proxyPort=xx".
Iām trying to add new connection profile to Eclipses Hibernate tolls. But in configuration window I can specify only SID, but my database uses Service name. What can I do in this situation?
Oracle Thin Driver takes only SID in a New Connection Profile.
You need to select Other Driver instead of Oracle Thin Driver in New Driver Definition.
That will give you an option to give whole url in which you can give service name instead of sid.
eg) URL : jdbc:oracle:thin:#192.168.72.11:1521/serviceName
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