CreateArray fails with Unsupported feature : createArrayof in mule - java

dbCreateArray function fails while using Oracle DB with c3p0 connection pooling with error, java.sql.SQLException: Unsupported feature I am using below method
#[dbCreateArray(oracle_Configurtion, <USER_DEFINED_DATA_TYPE_NAME_AS_IN_ORACLE>, Object[])]
I am using mule EE 3.9, oracle 12.2.0 and c3p0 0.9.5.2
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value = "oracle.jdbc.pool.OracleDataSource" />
<property name="jdbcUrl" value = "${db.url}" />
<property name="user" value = "${db.username}" />
<property name="password" value = "${db.password}" />
<property name="initialPoolSize" value = "${pool.initialSize}" />
</bean>
I Have seen this blog he suggested switch to oracle ucp pool but is there any way to fix this issue when using c3p0 pool.
https://help.mulesoft.com/s/article/dbCreateArray-function-failing-with-DB-connection-pooling

Oracle does not support the JDBC4-standard createArrayOf method.
Instead you must call a proprietary createARRAY method.
If you were writing code directly, it's be no problem to unwrap the c3p0 Connection to the underlying Oracle Connection and call the proprietary method. However, it looks like you are working through a higher-level language that is presumably being translated to standard JDBC methods. Unless you can get under the covers of how that conversion is done, it probably won't be easy to get this higher-level language call to work.
It look's like Oracle's own UCP has built-in an Oracle-specific workaround, but c3p0 does not include such a workaround, alas.

Related

Configure Apache Commons Pool to create objects on start up

I'm configuring a pool of objects using apache commons pool2. It seems the objects in the pool are only created when an attempt is made to borrow an object. I'd like the objects to be created up front, so I have a minimum number of objects ready when the first one needs to be borrowed.
My spring configuration looks something like this:
<bean id="webSocketConnectionPool" class="org.apache.commons.pool2.impl.GenericObjectPool">
<constructor-arg ref="webSocketConnectionFactory"/>
<constructor-arg ref="webSocketConnectionPoolConfig"/>
</bean>
<bean id="webSocketConnectionFactory" class="com.blah.WebSocketConnectionFactory" />
<bean id="webSocketConnectionPoolConfig" class="org.apache.commons.pool2.impl.GenericObjectPoolConfig">
<property name="maxIdle" value="300"/>
<property name="maxTotal" value="1000"/>
<property name="minIdle" value="10"/>
</bean>
I can see the pool is created when the app starts, but the minIdle setting doesn't seem to result in my desired behaviour. The create() method on the factory is only called when the first object is borrowed.
Any tips would be appreciated.
Thanks
My solution was to add some logic to the init method of the class with the connection pool as a member, to add objects. Hopefully this will help someone else in the future.
connectionPool.addObjects(connectionPool.getMinIdle());

How to dynamically change database password used by a DataSource, which is in turn used by a spring transaction manager

How can I dynamically (at run time) change the DB username and password used by a DataSource when using a Spring transaction manager?
We are using Spring and have a BasicDataSource and a TransactionManager defined as follows for handling database connections and transactions:
<bean id="myDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="url" ref="dbUrl"/>
<property name="username" ref="someUsername"/>
<property name="password" ref="somePassword"/>
<property name="driverClassName" value="org.postgresql.Driver" />
...
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="myDataSource" />
<tx:annotation-driven transaction-manager="transactionManager" />
We need to support dynamically changing the password that we are using at runtime. Note that I am not trying to change the password in the DB; that has already happened outside of the application. I am trying to tell my application to switch passwords that it is using to connect to the DB.
I tried extending BasicDataSource and calling setUsername() and setPassword(), but it appears that changing the username and password have no effect. I can see by looking into the implementation of BasicDataSource that the username and password appear to only be used when it initially constructs the connection pool.
I then found org.apache.commons.dbcp2.datasources.SharedPoolDataSource and thought that would be the answer to my problems. But it looks like DataSourceTransactionManager takes a javax.sql.DataSource, which surprisingly SharedPoolDataSource is not.
I can't find any other transaction managers that would take a SharedPoolDataSource or even a javax.sql.ConnectionPoolDataSource.
Is there a way to use a transaction manager and a connection pool and dynamically change the DB password that is used?

C3PO connection pooling - connections not being released

I have a web application running under Tomcat 7 using Spring with c3po as the connection pool manager. I have also used dbcp and have the same result.
I initiate a long running single threaded process which makes a large number of database calls using jdbcTemplate.update(), etc, in various dao's. As each of these updates is simple and independent, no transaction manager is being used.
For some reason, I am running out of connections. What appears to be happening is that each dao is holding onto its own connection and not returning it to the pool.
Is this normal behaviour? I had expected that the connection was tied to the jdbcTemplate.update() and released back as soon as this had finished.
...
In the context file...
<bean id="enquiryDataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${enquiry.drivername}"/>
<property name="url" value="${enquiry.jdbc}"/>
<property name="username" value="${enquiry.username}"/>
<property name="password" value="${enquiry.password}"/>
<property name="maxWait" value="30000"/>
<property name="maxActive" value="50"/>
</bean>
In a typical dao constructor...
#Autowired
public XXXCountryDao(#Qualifier("enquiryDataSource") DataSource dataSource,
#Qualifier("sqlUpdaterFactoryImpl") SqlUpdaterFactory sqlUpdaterFactory, #Qualifier("sqlFormatterFactoryImpl") SqlFormatterFactory sqlFormatterFactory) {
super("Country", dataSource, sqlUpdaterFactory, sqlFormatterFactory);
// ...other constructor stuff
}
All dao's inherit from...
public abstract class AbstractFileProcessorDao<ImportRecType, QueryRecType> extends JdbcDaoSupport {
// ...
}
In a typical dao method...
protected boolean runUpdateToSqlDatabase(Map<String, Object> values, Map<String, Object> whereValues) {
if (values.isEmpty())
return true;
String sql = updateUpdaterServer.getSql(values, whereValues);
if (logger.isDebugEnabled())
logger.debug("Server SQL -> " + sql);
getJdbcTemplate().update(sql);
return false;
}
Please check your application for "rogue" calls to DataSource#getConnection (you can use your IDE to search for method references). Connection leaks are usually caused by obtaining a connection which is then never closed via Connection#close.
When working with Spring's JdbcTemplate all JDBC resource handling (opening / closing connections, statements, result sets) is done automatically. But with legacy code you never know.

configuring infinispan in jboss 7 programmatically

is there a way i can take away the configuration of infinispan completely from the standalone.xml and have the configuration like the following in my persistence.xml :
<property name="hibernate.cache.infinispan.entity.strategy" value= "LRU" />
<property name="hibernate.cache.infinispan.entity.eviction.max_entries" value= "1000"/>
<property name="hibernate.cache.infinispan.entity.eviction.strategy" value= "LRU"/>
<property name="hibernate.cache.infinispan.entity.eviction.wake_up_interval" value= "2000"/>
<property name="hibernate.cache.infinispan.entity.eviction.max_entries" value= "5000"/>
<property name="hibernate.cache.infinispan.entity.expiration.lifespan" value= "60000"/>
<property name="hibernate.cache.infinispan.entity.expiration.max_idle" value= "30000"/>
thanks in advance
I don't know your use case but there is a possibility to configure Infinispan CacheManagers and Caches programmatically using fluent builder API. It means no need of standalone.xml and even no need of configuration for Infinispan in persistence.xml.
For more information see: https://docs.jboss.org/author/display/ISPN/Configuring+cache+programmatically
In this tutorial I can see configuration of CacheManager like this (which can be confusing now):
EmbeddedCacheManager manager = new DefaultCacheManager("my-config-file.xml");
You can configure it entirely programmatically too without any input xml file, for example:
GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
global.transport().defaultTransport();
global.globalJmxStatistics().enable();
manager = new DefaultCacheManager(global.build());

using JDBC with persistence.xml

I am building a framework that manage the access to the database.
the framework getting tasks from the user and handle a connection pooling that manage the access to the database. the user just send me SQL commands.
One of the feature that i would like to support is working with JPA, in this case i will provide entity manager. in some cases i would like to provide JDBC access as well as JPA access. the arguments for the database are written in XML file.
so for JPA i need to write the property in persistence.xml so it will be not so smart to write again the same arguments for JDBC. do you know if i can get the arguments of the database from persistence.xml, do you know if there is a source code that do it. or should i parse persistence.xml by myself?
Do you know if I can get the arguments of the database from persistence.xml, do you know if there is a source code that do it. Or should I parse persistence.xml by myself?
I'm not aware of anything in the standard JPA API allowing to retrieve the driver class name, the jdbc url, the username and password.
Second problem, the keys for those properties are not standardized in JPA 1.0. For example, Hibernate will use:
<property name="hibernate.connection.driver_class" value=""/>
<property name="hibernate.connection.url" value=""/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
While EclipseLink will use:
<property name="eclipselink.jdbc.driver" value=""/>
<property name="eclipselink.jdbc.url" value=""/>
<property name="eclipselink.jdbc.user" value=""/>
<property name="eclipselink.jdbc.password" value=""/>
This may make the parsing fragile.
If this is an option, maybe you could use a properties file to store both the provider specific keys and the values (I'd recommend using the standardized JPA 2.0 properties as keys). For example:
# keys for JPA
javax.persistence.jdbc.driver = hibernate.connection.driver_class
javax.persistence.jdbc.url = hibernate.connection.url
javax.persistence.jdbc.user = hibernate.connection.username
javax.persistence.jdbc.password = hibernate.connection.password
# values common to JPA and JDBC
driver = org.h2.Driver
url = jdbc:h2:mem:test
username = scott
password = tiger
And use Persistence.createEntityManagerFactory(String, Map) and pass a Map that you'll feed with the properties from the file to create the EntityManagerFactory:
Map map = new HashMap();
map.put(...);
...
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPu", map);

Categories