what is the use of durability in quartz xml - java

Here a property mention that durability=true.
<bean name="complexJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.websystique.spring.quartz.ScheduledJob" />
<property name="jobDataMap">
<map>
<entry key="anotherBean" value-ref="anotherBean1" />
<entry key="myBean" value-ref="myBean" />
</map>
</property>
<property name="durability" value="true" />
</bean>
could you please explain what is the use of durability=true.

From here:
Specify the job's durability, i.e. whether it should remain stored in
the job store even if no triggers point to it anymore.

Related

Writing Tasklet in Spring Batch

I am writing the data retrieved from the database in a .txt file in a particular format. I need to put 0s before a particular field retrieved.
For Example: If the value of a column retrieved from the database is 123, I need to make it as 5 digits and the number should be preceded by 2 zeros. i.e. "00123".
For a number like 2, it should be "00002"
But instead of 0s I need space. I am unable to figure it out.
The .xml code that I use for it is
<bean id="neiertzItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="${renewalNeiertzData}" />
<property name="lineAggregator">
<bean
class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
<property name="fieldExtractor">
<bean
class="com.accord.batch.neiertz.tasklet.FormattingBeanWrapperFieldExtractor">
<property name="names"
value="contractNumber,engagementNumber,creationDate,commercantNumber,productCode,externalReference" />
<property name="dateFormatting">
<map key-type="java.lang.String" value-type="java.lang.String">
<entry key="creationDate" value="yyyyMMdd" />
</map>
</property>
<property name="numberFormatting">
<map key-type="java.lang.String" value-type="java.lang.String">
<entry key="contractNumber" value="%015d" />
<entry key="engagementNumber" value="%011d" />
<entry key="commercantNumber" value="%09d" />
<entry key="productCode" value="%05d" />
<entry key="externalReference" value="%030d" />
</map>
</property>
</bean>
</property>
<property name="format" value="%-15s%-11s%-8s%-9s%-5s%-30s" />
</bean>
</property>
</bean>
How Do I change to make it for white spaces instead of zeros. I don't understand the equivalent for space in java and how to put it in xml.

Spring : JMS Consumer Sessions/Connections not removed on Message Broker post Batch Job Completion

I have a Batch Job Configured to read messages from JMS Destination and write to a XML file using Chuck Tasklet. The JMS reader is custom implemented which inturn invokes JMSTemplate's receive method. I am using webMethods Broker as JMS Broker. During Batch run, we observed that the Consumer session created while reading the messages from Broker Destination are not being destroyed up on completion of the batch. They are only destroyed after I shutdown the JVM. I have provided more details below,
JMS Spring XML Configuration :
<bean id="JMS.SourceQueue.JndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<map>
<entry key="java.naming.provider.url" value="wmjmsnaming://Broker #1#X.X.X.X:6849" />
<entry key="java.naming.factory.initial" value="com.webmethods.jms.naming.WmJmsNamingCtxFactory" />
<entry key="com.webmethods.jms.naming.clientgroup" value="IS-JMS" />
</map>
</property>
</bean>
<bean id="JMS.SourceQueue.JmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="JMS.SourceQueue.JndiTemplate" />
<property name="jndiName" value="SmartBatchConnectionFactory" />
<property name="lookupOnStartup" value="true" />
<property name="cache" value="false" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="JMS.SourceQueue.ConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="JMS.SourceQueue.JmsConnectionFactory" />
</bean>
<bean id="JMS.SourceQueue.DefaultDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="JMS.SourceQueue.JndiTemplate" />
<property name="jndiName" value="SourceQueue" />
</bean>
<bean id="JMS.SourceQueue.MessageTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="JMS.SourceQueue.ConnectionFactory" />
<property name="receiveTimeout" value="10000" />
<property name="sessionTransacted" value="true" />
<property name="defaultDestination" ref="JMS.SourceQueue.DefaultDestination" />
</bean>
Any help on pointing out the actual issue would be great.
Call destroy() on the JMS.SourceQueue.ConnectionFactory at the end of the last step (or otherwise when the job is completed).
Using the caching connection factory is recommended to avoid creating connections/consumers for each message, but it needs to be told when to physically release the resources.

Quartz retain state of existing trigger on redeploy

I have a Quartz trigger created through Spring Framework which I occasionally need to pause (TRIGGER_STATE=PAUSED). However, if I do a deploy of the application while the trigger is paused it gets un-paused due to the trigger being recreated. Is there a Quartz setting to retain the trigger state if the trigger already exists?
<bean id="updateJobQuartzTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="updateTrigger" />
<property name="group" value="updateDaily" />
<property name="jobDetail" ref="updateJob" />
<property name="cronExpression" value="0 0 4 * * ?" />
</bean>
<bean name="updateJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="name" value="updateJob" />
<property name="group" value="updateDaily" />
<property name="jobClass" value="com.project.quartz.SendMessageJob" />
<property name="jobDataMap">
<map>
<entry key="messageContent">
<map>
<entry key="job" value="UpdateLoad"/>
</map>
</entry>
</map>
</property>
<property name="durability" value="true"/>
</bean>

Priority between properties in HibernateJPAVendorAdapter and JPAProperty

I have the following configuration in an application Spring + JPA + Hibernate, using packagesToScan to avoid having file persistence.xml.
<!-- Configure JPA Implementation -->
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${jpa.database}" />
<property name="showSql" value="${jpa.showSql}" />
<property name="databasePlatform" value="${jpa.dialect}" />
<property name="generateDdl" value="${jpa.generateDdl}" />
</bean>
<!-- Create the JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="packagesToScan">
<list>
<value>com.proyectofinal.model</value>
</list>
</property>
<property name="jpaProperty">
<props>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.use_sql_comments" value="false" />
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.MYSQLDialect" />
<entry key="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</props>
</property>
</bean>
My question is:
Is it necessary define in both places properties like show_sql or dialect?
Which one has priority over the other?
What place is more appropriate to define it?
Thanks in advance
Properties specified in the JpaVendorAdapter don't have to be duplicated in the list of additional properties. If that would be the case the JpaVendorAdapter would be pretty useless.
Also in your configuration use either database or databasePlatform don't use both.
Properties which can be configured by using a JpaVendorAdapter I would configure right there, it would save you a couple of lines and you don't have to remember the cryptic hibernate (or which ever provider you use) property name.
The properties you need are the following.
<props>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<entry key="hibernate.use_sql_comments" value="false" />
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</props>
If you define them in both places the one from the JpaVendorAdapter are ignored.
In addition to #M. Deinum's answer, if you decide to use the jpaProperties over jpaVendorAdapter, you'll need to set the persistenceProvider property since it would normally be derived from jpaVendorAdapter
for example
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence"/>
</property>
Also, jpaProperty should be jpaProperties

spring jmx authentication

How can i turn on authentication using jmx on spring web app ?
Please take a look here for a solution that is almost working for me:
http://forum.springsource.org/showthread.php?t=73677
The only unresolved issue is how to make JMX client use the same connection to server when authenticating and when doing the secure operation.
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl" value="service:jmx:rmi:///jndi/rmi://:9875/jmxrmi" />
<property name="environment">
<map>
<entry key="jmx.remote.x.password.file" value="C:\Java\jdk1.7.0_79\jre\lib\management\jmxremote.password" />
<entry key="jmx.remote.x.access.file" value="C:\Java\jdk1.7.0_79\jre\lib\management\jmxremote.access" />
</map>
</property>
</bean>
SpringConfig
<bean id="annotationTestMBean" class="com.greenline.appservice.web.bean.AnnotationTestMBean"/>
<!-- Spring JMX 配置 begin -->
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="9875" />
<property name="alwaysCreate" value="true" />
</bean>
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl" value="service:jmx:rmi:///jndi/rmi://192.168.214.63:9875/myconnector" />
<!--jmxmp协议
<property name="objectName" value="connector:name=jmxmp" />
<property name="serviceUrl" value="service:jmx:jmxmp://192.168.214.63:9875" />
-->
<property name="environment">
<!-- the following is only valid when the sun jmx implementation is used -->
<map>
<entry key="jmx.remote.x.password.file" value="C:\Java\jdk1.7.0_79\jre\lib\management\jmxremote.password" />
<entry key="jmx.remote.x.access.file" value="C:\Java\jdk1.7.0_79\jre\lib\management\jmxremote.access" />
</map>
</property>
</bean>
<context:mbean-export registration="replaceExisting"/>
<!-- Spring JMX 配置 end-->
you can see access&password file
JDK_Path\jre\lib\management\jmxremote.password
JDK_Path\jre\lib\management\jmxremote.access
JMX and Spring Part1-3
http://www.javacodegeeks.com/2012/07/jmx-and-spring-part-1.html
oracle-Remote Management Applications (jmx)
http://docs.oracle.com/cd/E19698-01/816-7609/6mdjrf861/index.html

Categories