mysql clustering connection is failed through hibernate and spring - spring

Using MySQL workbench I can connect to the cluster db without any issue. but when I use it as the connection string jdbc:mysql:loadbalance://node_ip1,node_ip2,node_ip3/cluster_db_name?loadBalanceBlacklistTimeout=5000&loadBalanceStrategy=bestResponseTime from the app it will give me an error saying connection timeout. After that I use one cluster node and try to connect to it as we connect to localhost jdbc:mysql://cluster_node1/cluster_db_name?relaxAutoCommit=true&autoReconnect=true&useUnicode=true&connectionCollation=utf8_general_ci&characterEncoding=utf8&characterSetResults=utf8 but it also gives me the same error.
Below is the applicationContext.xml code.
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${bluesky.jdbc.driver}"/>
<property name="jdbcUrl" value="${bluesky.jdbc.url}"/>
<property name="user" value="${bluesky.jdbc.username}"/>
<property name="password" value="${bluesky.jdbc.password}"/>
<property name="minPoolSize" value="${bluesky.c3p0.pool.min.size}"/>
<property name="maxPoolSize" value="${bluesky.c3p0.pool.max.size}"/>
<property name="numHelperThreads" value="${bluesky.c3p0.numHelperThreads}"/>
<property name="acquireIncrement" value="${bluesky.c3p0.acquireIncrement}"/>
<property name="acquireRetryAttempts" value="${bluesky.c3p0.acquireRetryAttempts}"/>
<property name="idleConnectionTestPeriod" value="${bluesky.c3p0.idleConnectionTestPeriod}"/>
<property name="maxIdleTime" value="${bluesky.c3p0.maxIdleTime}"/>
<property name="preferredTestQuery" value="${bluesky.c3p0.preferred.test.query}"/>
<property name="testConnectionOnCheckout" value="${bluesky.c3p0.test.connection.on.checkout}"/>
<property name="testConnectionOnCheckin" value="${bluesky.c3p0.test.connection.on.checkin}"/>
<property name="checkoutTimeout" value="${bluesky.c3p0.checkout.timeout}"/>
<property name="debugUnreturnedConnectionStackTraces" value="${bluesky.c3p0.debug.unreturned.connection.stackTraces}"/>
<property name="unreturnedConnectionTimeout" value="${bluesky.c3p0.unreturned.connection.timeout}"/>
</bean>

Related

Spring integration jdbc message store performance

I was using the SimpleMessageStore ( memory ) as the default Store for an Aggregator, but as i need
persistent store, i started using a jdbc solution backed up by Mysql 5.5
But i'm really concerned about its performance, as using a PerfTest ( databene's contiperf ), memory store achieved up to 6000 messages/sec, whereas using mysql ( or redis, or mongo ), i can't achieve more than 15-20 messages/sec.
<int:aggregator id="XDRAggegator"
input-channel="mqChannel"
output-channel="publishChannel"
message-store="jdbc-messageStore"
....
<bean id="reaper" class="org.springframework.integration.store.MessageGroupStoreReaper">
<property name="messageGroupStore" ref="jdbc-messageStore"/>
<property name="timeout" value="${msg.timeout}"/>
</bean>
<task:scheduler id="taskScheduler"/>
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="reaper" method="run" fixed-rate="${reaper.rate}"/>
</task:scheduled-tasks>
<task:executor id="taskExecutor" pool-size="1"/>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
<int-jdbc:message-store id="jdbc-messageStore" data-source="dataSource" />
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" >
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://${database.host}:3306/XDR?autoReconnect=true&cachePrepStmts=true&prepStmtCacheSize=50" />
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="idleConnectionTestPeriodInMinutes" value="1"/>
<property name="idleMaxAgeInMinutes" value="2"/>
<property name="connectionTimeoutInMs" value="1000" />
<property name="maxConnectionsPerPartition" value="10"/>
<property name="minConnectionsPerPartition" value="4"/>
<property name="partitionCount" value="4"/>
<property name="acquireIncrement" value="2"/>
<property name="statementsCacheSize" value="10"/>
<property name="closeConnectionWatch" value="false"/>
</bean>
Am i missing something ?
I'm using default schema that comes into spring-integration-jdbc library.

Mule to JPA compatibility

I using Mule Studio version: 1.3.1 .
buildDate: 201209061215
I am not able to get JPA end point. I also downloaded jpa-connector-1.0-20120925-2201.jar
But I dont know to to integrate with mule studio.
So I decided to use a simple Java transformer and write my processing logic which will be internally using JPA/Hibernate.
I came to know that i have to use a JPA vendor adapter for spring, else none of my service, DAO classes will be instantiated.
I have declared a datasource and entityManager as beans of spring inside mule flow xml as shown.
<spring:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<spring:property name="url" value="jdbc:mysql://localhost:3306/eigDB" />
<spring:property name="username" value="root" />
<spring:property name="password" value="tiger" />
</spring:bean>
<spring:bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<spring:property name="dataSource" ref="dataSource" />
<spring:property name="persistenceUnitName" value="autoRebateSystem" />
<spring:property name="jpaVendorAdapter">
<spring:bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<spring:property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
<spring:property name="showSql" value="true" />
</spring:bean>
But mule flow xml is not able to recognize any class of spring framework.
Finding very difficult to replace those class names.
Plez provide the solution for my problem,
By letting me know the PROPER replacements for mule studio.
1) org.springframework.jdbc.datasource.DriverManagerDataSource
2) org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
3) org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
Are you missing to use HibernateJpaDialect and JpaTransactionManager;
I hope the following configuration will be useful.
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/yourdatabase"/>
<property name="username" value="your- username"/>
<property name="password" value="your- password"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--<property name="dataSource" ref="dataSource"/>-->
<property name="persistenceUnitName" value="<your-persistunit-name>"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect/>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver">
</bean>
</property>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<!-- <property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" />-->
<property name="generateDdl" value="false"/>
<property name="showSql" value="false"/>
</bean>
To integrate it within MuleStudio, please add this update site within MuleStudio:
http://tecnologia.2020mobile.es/jpa-cloud-connector/update-site/

Can I use multiple C3P0 datasources for DB instance?

I was wondering if I can run multiple c3p0 datasources for one DB, something like:
<bean id="dataSource1" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${db.driverClassName}"/>
<property name="jdbcUrl" value="${db.url}/schema1"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="acquireIncrement" value="1" />
<property name="idleConnectionTestPeriod" value="100"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="1800" />
</bean>
<bean id="dataSource2" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${db.driverClassName}"/>
<property name="jdbcUrl" value="${db.url}/schema2"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="acquireIncrement" value="1" />
<property name="idleConnectionTestPeriod" value="100"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="1800" />
</bean>
They will be used by difference persistence services.
Thanks.
That's absolutely fine. You'll run into some configuration issues like:
autowiring DataSource by type won't work
#Transactional/declarative transactions will work only against one, selected DataSource. Alternatively you'll have to manually tell which transaction manager you want to use (thus you'll need two transaction managers as well: transactionManager1 and transactionManager2):
#Transactional("transactionalManager2")
Besides, there's nothing wrong with this configuration. Actually it's a pretty good idea (+1): if some layers/components of your application saturate the pool, others can still operate.
The only thing I recommend is to use lesser known abstract/parent bean declarations to avoid repetition:
<bean id="dataSource" abstract="true" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${db.driverClassName}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="acquireIncrement" value="1" />
<property name="idleConnectionTestPeriod" value="100"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="1800" />
</bean>
<bean id="dataSource1" parent="dataSource">
<property name="jdbcUrl" value="${db.url}/schema1"/>
</bean>
<bean id="dataSource2" parent="dataSource">
<property name="jdbcUrl" value="${db.url}/schema2"/>
</bean>
See also:
What is meant by abstract="true" in spring?

Updating a row by rowid in oracle using spring-jdbc

I have a weird problem updating a row by rowid in oracle using spring-jdbc.
The problem is that everything is ok but for some rowids the update will never be done and
application is frozen.
I changed spring log level to DEBUG to see what's happening but nothing's strange and spring log is exactly as successful updates.
I tried to execute the same sql in plsql and the update was executed successfully.
spring version is 3.1.1.RELEASE
oracle version is 11.1.0.6.0
body of update method in dao is:
String sql=
"UPDATE "+schema+".MSG m SET m.STATE="+state+" WHERE ROWID='"+msg.getRowId()+"'";
getJdbcTemplate().update(sql);
dao bean:
<bean id="messageDao" class="com.foo.dao.springjdbc.MessageDaoSpringJdbcImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
jdbcTemplate:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
data source:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#${db.ip}:${db.port}:${db.sid}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="validationQuery" value="select 1 from dual"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="maxActive" value="1"/>
<property name="maxIdle" value="3"/>
</bean>
any idea?

How to set program name in ibatis config XML?

I am attempting to set the program name to something other than "jdbc thin client" using the iBatis dao config.
From my dao XML config file:
<transactionManager type="JDBC">
<dataSource type="DBCP">
<property name="JDBC.Driver" value="com.foo.bar.jdbc.MyOracleDriver"/>
<property name="JDBC.ConnectionURL" value="oracle.jdbc.OracleDriver&jdbc:oracle:thin:#${host}:1521:${database}"/>
<property name="JDBC.Username" value="${userName}"/>
<property name="JDBC.Password" value="${password}"/>
<property name="Pool.DefaultAutoCommit" value="false"/>
<property name="Pool.MaximumActiveConnections" value="63"/>
<property name="Pool.MaximumIdleConnections" value="10"/>
<property name="Pool.MaximumWait" value="2000"/>
<property name="Pool.ValidationQuery" value="select 1 from dual"/>
<property name="Pool.testWhileIdle" value="true"/>
<property name="Pool.TestOnBorrow" value="true"/>
<property name="Pool.LogAbandoned" value="true"/>
<property name="Pool.RemoveAbandoned" value="true"/>
<property name="Pool.RemoveAbandonedTimeout" value="300"/>
</dataSource>
</transactionManager>
I would assume this is as easy as adding the following:
<property name="v$session.program" value="My Program Name"/>
But that didn't work. The program name did not change. What am I doing wrong?

Resources