How to set program name in ibatis config XML? - oracle

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?

Related

jasypt EncryptablePropertyPlaceholderConfigurer not helping in decrypting the password

I started doing some examples using Jasypt and Spring and unfortunately, could not test the decryption successfully.
I'm using Spring 4.3.15 and Jasypt 1.9.3. I think I followed the examples given in the internet carefully, but still see the password is sent encrypted only.
My spring configuration looks like below
<bean id="mydatasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="encryptedPropertyPlaceHolder" class=**"org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer"**>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true" />
<constructor-arg>
<bean class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config">
<bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
***<!-- <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" /> -->***
<property name="password" value="jasypt" />
</bean>
</property>
</bean>
</constructor-arg>
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
and jdbc.properties has values
jdbc.url=<<some url>>
jdbc.username=<<some username>>
jdbc.password=ENC(Y3EEFmt5lEAC96GJlzK9VcETH)
When I ran my testcase, which uses mydatasource as Autowired, I see that password field is set as ENC(Y3EEFmt5lEAC96GJlzK9VcETH). Other fields are properly assigned using propertyConfigurer. But the encrypted password is not decrypted before assigning to datasource.
I'm not sure, what is that I'm missing here ?
Also, as you noticed I used hard coded password in encryptedPropertyPlaceHolder. I have read about APP_ENCRYPTION_PASSWORD, but when trying to set the value using VM arguments in my eclipse as -DAPP_ENCRYPTION_PASSWORD=jasypt, it is not working.

Multiple database Schema with Spring+Hibernate+JPA

I have same database schema database_1 and database_2 and want to configuration of these two database(database schema is same) and decide run time which database is use.
My persistence.xml is as below:
<persistence-unit name="first" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.model.AboutUs</class>
<class>com.model.AccessCards</class>
<properties>
<property name="hibernate.dialect" value="com.util.customMySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.jdbc.batch_size" value="20"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
Persistence name second configure here as below :
<persistence-unit name="second" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.model.AboutUs</class>
<class>com.model.AccessCards</class>
<properties>
<property name="hibernate.dialect" value="com.util.customMySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.jdbc.batch_size" value="20"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
Both persistence units load same classes .
and now my database-configure.xml as where i configure persistence unit with data source. as below first persistence unit name configare with datasource name datasource as :
<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="first" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${datasource.driverClassName}" />
<property name="jdbcUrl" value="${datasource.url}" />
<property name="user" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryAttempts" value="1" />
<property name="maxIdleTime" value="300" />
<property name="maxPoolSize" value="20" />
<property name="minPoolSize" value="3" />
<property name="maxStatements" value="300" />
<property name="testConnectionOnCheckin" value="true" />
</bean>
Now this code for configure second persistence unit name with data source name datasource5 as below :
<bean id="transactionManager5" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory5" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource5" />
<property name="persistenceUnitName" value="second" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean id="dataSource5" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${datasource.driverClassName}" />
<property name="jdbcUrl" value="${datasource5.url}" />
<property name="user" value="${datasource5.username}" />
<property name="password" value="${datasource5.password}" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryAttempts" value="1" />
<property name="maxIdleTime" value="300" />
<property name="maxPoolSize" value="20" />
<property name="minPoolSize" value="3" />
<property name="maxStatements" value="300" />
<property name="testConnectionOnCheckin" value="true" />
</bean>
Now i use entity manager for save data in database and i am using mysql database . I got entity manager with persistence unit name first and second .
#PersistenceContext(unitName="first")
private EntityManager entityManager;
#PersistenceContext(unitName="second")
private EntityManager entityManager2;
Now entity manager save data in database using persist( object) method successfully .
entityManager.persist(project);
and entityManager2 save data in database using persist( object ) method successfully (No Exception here). But data does not store in database datbase_2 .
entityManager2.persist(project);
If I change the order of persistence unit first and second in persistence.xml then entityManager2 save data in database and entitymanager does not save data in database .
Any one have idea how i can make multiple entitymanager for same database schema .
There are a few limitations:
#Transactional corresponds to single TransactionManager.
JpaTransactionManager corresponds to single EntityManager(Factory).
Thus use separate methods with #Transactional annotation for each transaction manager:
#Transactional(transactionManager = "tmBeanName")
After that entity managers will work fine.
Also, some workaround exists to break the second limitation (DO NOT USE IT in this case):
It is possible to use single JtaTransactionManager instead of several JpaTransactionManager: distributed transaction will cover both entity managers and they will work fine too.

mysql clustering connection is failed through hibernate and 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>

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.

Camel JMS request/Reply timeouts

I am trying to send request/reply a message to a remote broker from camel but the it times out. See config below:
<bean id="providerJMSConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="alwaysSessionAsync" value="false"/>
<property name="alwaysSyncSend" value="true"/>
<property name="brokerURL"><value>${remote-broker-broker-url}</value></property>
<property name="clientID" value=""/>
<property name="closeTimeout" value="15000"/>
<property name="copyMessageOnSend" value="true"/>
<property name="disableTimeStampsByDefault" value="false"/>
<property name="dispatchAsync" value="false"/>
<property name="objectMessageSerializationDefered" value="false"/>
<property name="optimizeAcknowledge" value="false"/>
<property name="optimizedMessageDispatch" value="true"/>
<property name="password" value=""/>
<property name="producerWindowSize" value="0"/>
<property name="statsEnabled" value="false"/>
<property name="useAsyncSend" value="false"/>
<property name="useCompression" value="false"/>
<property name="useRetroactiveConsumer" value="false"/>
<property name="userName" value=""/>
<property name="watchTopicAdvisories" value="true"/>
<property name="sendTimeout" value="0"/>
</bean>
<bean id="providerJMSConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="aeroProviderJMSConnectionFactory"/>
<property name="deliveryPersistent" value="true"/>
<property name="explicitQosEnabled" value="true"/>
<property name="priority" value="${jms-message-priority}"/>
<property name="acceptMessagesWhileStopping" value="false"/>
</bean>
<bean id="providerJMS" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="aeroProviderJMSConfig"/>
</bean>
<osgi:camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
<endpoint id="providerEndpoint" uri="providerJMS:queue:provider?replyTo=providerResponse&requestTimeout=120000"/>
<route>
<from .....>
<to ref="providerEndpoint"/>
....
</route>
<osgi:camelContext>
Why does this happen? I realised on the remote broker the number of consumers are always more than 1 even though I did not specify how many consumers it should have. Also, whene I removed the replyTo destination, the name still keep coming up on the remote broker.
Pls, is there any tool I can use to debug activemq so that I can see who is picking messages off a queue?
When doing request/reply over JMS with Camel, it uses a 20 sec default timeout. Is it that timeout you hit?
You can alter it, its the requestTimeout option
http://camel.apache.org/jms

Resources