Use c3p0 with JBOSS AS 7.1.1 - mysql

I read in c3p0´s manual link that it is possible to use c3p0 library inside JBOSS as an MBean.
Once configured correctly, I would like to reference the new C3P0PooledDataSource in my Java WAR through its JNDI name. As I am using Spring
it would be something similar to:
[src/webapp/WEB-INF/applicationContext.xml]
<jee:jndi-lookup id="dataSource" jndi-name="java:PooledDS" />
However, I don´t know how to configure this library properly. I tried to place c3p0-0.9.2.1.jar and c3p0-service.xml in the folders commented in the manual
but I had no luck.
I am currently developing a project which uses a MySql database, so I have instaled the mysql connector inside the JBOSS AS 7.1.1 server.
I have to say that if I integrate c3p0 and MySql connector in my project I can deploy it correctly. So...:
Is it possible to use c3p0 connection pool inside JBOSS AS 7.1.1 as described in its manual? How should I configure it?
I started to "play" with c3p0 because of its large number of configuration properties, but I don´t know if c3p0 is better than embedded JBOSS pooling capabilities.
Does c3p0 library deserve to be used instead of JBOSS embedded connection pool (i.e. configuring a datasource with the admin console/web) ?
I appreciate any comments to these matters.
Thanks in advance.

Related

Spring MVC using Google Cloud Platform MySQL Database

I am trying to use GCP flexible environment for my Spring MVC demo app. I have created a MySQL database on GCP and my app is connected to it via pom.xml as described here Using Cloud SQL for MySQL. But I cant find info how to use Spring configuration XML file with this MySQL database. Should I use both pom.xml and spring_config.xml data source bean to connect to it or just pom.xml? BTW I am using ComboPooledDataSource:
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
Its good to maintain both. Generally pom is for maven dependencies and config file is for all configuration related tasks like db connectivity.

Eureka's hsqldb overriding MySQL

I have a Spring Boot project that currently consists of three microservices (all of them are maven children of the mentioned project), namely:
eureka-server : as the name says, it's simply a Eureka project that works as a server for registering other microservices
user-server : a project that holds a 'monolithic stack' (model, DAO, service and controller). Here is where the problem is. More on this later.
web-server : a project that contains the AngularJS application and a controller that is accessible from AngularJS and that communicates with the user-server module.
Eureka forces me to include a hsqldb dependency in the parent pom in order to launch the three mentioned applications.
The problem is that I was using MySQL in user-server and hsqldb has somehow overriden the MySQL data source.
In other words, the database engine of user-server is now hsqldb and I want to keep working with MySQL, and if I remove the dependency, the application will obviously not launch.
Is there any way to solve this and work with, maybe, two databases in user-server?
Thank you everyone!
I finally figured out how to get it working. I'll just post it here in case someone faces a similar problem.
It seems that application.properties wasn't being read when launching the application because telling Spring Boot which .yml configuration file for Eureka should be read, it was overriden.
In the .yml file of the microservice I wasn't able either to set the datasource to MySQL, so the solution was to hardcode the datasource properties when launching the microservice, as follows:
System.setProperty("spring.datasource.platform","mysql");
System.setProperty("spring.datasource.url","jdbc:mysql...");

Connection pooling with jetty server,mysql in spring boot

I have developed an application with spring boot and jetty server using mysql database. I was to creating connection pooling for the same. I am not getting any direct references as to how to do it. Kindly suggest the methods to achieve it

Do I need to use C3P0 pooling library in my (grails) web application?

I am not familiar at all with connection pooling library. I've just discovered it through this blog article) and I am not sure that I should use one in my web application based on grails/hibernate/mysql.
So my question is simple : in which situations would you suggest to integrate a connection pooling library into a grails application? Always, Never or only over some connections threshold?
P.S. : If you have ever used successfully C3P0 in your web application, I will greatly appreciate to hear your feedback (in terms of visible positive effects).
Regardless of which pooling implementation, you should use a connection pool always in your web application. Open a connection with the database is a very expensive task and being able to reuse a already existing and idle connection greatly improves your site performance.
A connection can be managed by the application server (Tomcat, JBoss, Glassfish...) or by your application. The latter is easier to setup but it's hard to customize per deployment. Configuring a connection pool on the application and setting your site to consume it makes easy to the fine tune the connection pool parameters, like: minimum connections to keep open, max idle time and so on.
My experience with this is pretty limited, but I ended up using C3P0 for the simple reason that Hibernate does not seem to handle MySQL restarts. I got a "Broken pipe" every morning because our hosting service restarted MySQL every night.
I googled it and the only advice I could find was to use... the connection pool of the app server or C3P0. For me, the latter works just fine.
I always use a connection pool for two reasons:
Because opening connections is an expensive operation
It's dead-simple to set one up to work transparently, so there's no real advantage to not using one.
If you're already using hibernate, just modify your hibernate.cfg.xml's connection.provider_class to use org.hibernate.connection.C3P0ConnectionProvider and throw the c3p0 jar file into your servlet's WEB-INF/lib folder. Done.
If you're using JNDI and a GlobalNamingResources declaration, modify the type property to point to com.mchange.v2.c3p0.ComboPooledDataSource and throw the c3p0 jar into Tomcat's /lib folder. Done.
C3P0 is a very decent pool but I would still recommend to use the connection pool of your app server or servlet engine and to configure Grails to use it via a regular DataSource. Use a stand-alone connection pool when you can't do that (in which case C3P0 is a good choice).

How can I configure JBoss JDBC data source connections outside the XML config file?

I would like to override the portion of JBoss that loads JDBC connection information from the XML config file. I would like to continue using the rest of JBoss's connection pooling/caching features. I just want to load the connection data from another source.
Which MBean should I be implementing and how do I configure the override in JBoss?
The JBoss -ds.xml descriptors actually cover a multitude of sins. If you look on the JBoss JVM console, you'll find 4 or 5 MBeans there for each data source. You could potentially do this programmatically, but I wouldn't give good odds on your chances.
My suggestion would be to use a 3rd-party connection pooling library (e.g. Commons DBCP). Define the pool using that, and then bind the resulting DataSource to JNDI. CLient application using the pool shouldn't know any difference.