Spring integration

631 views
Skip to first unread message

Lucas

unread,
Jul 21, 2011, 3:33:03 PM7/21/11
to XADisk
Hello,
I'm sorry for asking such a basic question, but is there an example
for using XADisk in Spring?

sger...@gmail.com

unread,
Jul 26, 2011, 1:17:37 PM7/26/11
to xad...@googlegroups.com
Hello,
 
A Spring XML file copied from our project
 

    <bean id="xaFileDiskConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="eis/XADisk/LocalConnectionFactory" />
    </bean>
    <bean id="xaFileWrapper"
        class="my.package.MyXADiskFileRelatedBean">
        <constructor-arg ref="xaFileDiskConnectionFactory" />
    </bean>
</beans>

sger...@gmail.com

unread,
Jul 26, 2011, 1:24:30 PM7/26/11
to xad...@googlegroups.com
...and our attempt to have XADisk work in a stand-alone Spring unit-test
 
We had to implement the ConnectionManager and other required JCA interfaces and include the JOTM transaction manager as it has been removed from the latest releases of Spring.
 
In the end the XADisk transaction did not commit, mnost probably because of our dummy implementation of the interfaces :-)
You can use it as a start though, if you have more time than we did.
 

 <!-- JOTM is the JTA transaction manager -->
 <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
 <bean id="txManager"
  class="org.springframework.transaction.jta.JtaTransactionManager">
  <property name="userTransaction">
   <ref local="jotm" />
  </property>
 </bean>
 <!-- Init XADisk file system -->
 <bean id="xaStartupConfig" class="org.xadisk.filesystem.standalone.StandaloneFileSystemConfiguration">
  <constructor-arg index="0" value="${java.io.tmpdir}/xadisk"/>
  <constructor-arg index="1" value="GWFileHandler-XADisk"/>
 </bean>
 <bean id="xaDiskNativeFS" class="org.xadisk.filesystem.NativeXAFileSystem"
  factory-method="bootXAFileSystemStandAlone">
  <constructor-arg ref="xaStartupConfig"/>
 </bean>
 <!-- EOF Init XADisk -->
 
 <!-- Wire XADisk for standalone operation -->
 <bean id="xaDiskManagedConnectionFactory"
  class="org.xadisk.connector.outbound.XADiskManagedConnectionFactory">
   <property name="instanceId" value="GWFileHandler-XADisk" />
 </bean>
 <bean id="xaDiskConnectionManager"
  class="my.package.XADiskConnectionManager">
  <constructor-arg ref="txManager"/>
 </bean>
 <bean id="xaFileDiskConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="eis/XADisk" />
  <property name="defaultObject">
   <bean class="org.springframework.jca.support.LocalConnectionFactoryBean">
    <property name="managedConnectionFactory" ref="xaDiskManagedConnectionFactory"/>
    <property name="connectionManager" ref="xaDiskConnectionManager"/>
   </bean> 
  </property>
 </bean>
 <bean id="xaFileWrapper"
  class="my.package.MyXADiskRelatedBean">

  <constructor-arg ref="xaFileDiskConnectionFactory" />
 </bean>
 <!-- EOF Wire XADisk -->
</beans>

Nitin Verma

unread,
Jul 26, 2011, 2:29:03 PM7/26/11
to XADisk
Hello Lucas, Hello Stelios

Sorry, somehow I missed this thread.

Stelios, I guess you were aiming to have XADisk work in JCA style
without the standard JCA container; would XADisk Session/XASession not
serve the purpose for you?

Lucas, I have attempted a very basic example of doing XADisk in
Spring. See if this helps.


________________________________________________________________________________________________________________________________


<default-package>/Beans.xml
--------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<bean id="xaStartupConfig"

class="org.xadisk.filesystem.standalone.StandaloneFileSystemConfiguration">
<constructor-arg index="0" value="C:\\XADiskSystem"/>
<constructor-arg index="1" value="id-1"/>
</bean>

<bean id="xaDiskNativeFS"
class="org.xadisk.filesystem.NativeXAFileSystem"
factory-method="bootXAFileSystemStandAlone">
<constructor-arg ref="xaStartupConfig"/>
</bean>

</beans>


________________________________________________________________________________________________________________________________


xadiskandspring/Main.java
--------------------------------------

package xadiskandspring;

import java.io.File;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.xadisk.bridge.proxies.interfaces.Session;
import org.xadisk.bridge.proxies.interfaces.XAFileSystem;

public class Main {

public static void main(String[] args) {
final File testDirectory = new File("C:\\test");
final File testFile1 = new File(testDirectory, "a.txt");
final File testFile2 = new File(testDirectory, "b.txt");
final File testFileTemp = new File(testDirectory, "temp.txt");

try {
XmlBeanFactory beanFactory = new XmlBeanFactory(new
ClassPathResource("Beans.xml"));
XAFileSystem xafs = (XAFileSystem)
beanFactory.getBean("xaDiskNativeFS");

xafs.waitForBootup(-1);

Session session = xafs.createSessionForLocalTransaction();
session.createFile(testFile1, false);
session.createFile(testFileTemp, false);
session.moveFile(testFileTemp, testFile2);
session.commit();

xafs.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}


________________________________________________________________________


Lucas

unread,
Jul 27, 2011, 8:52:16 AM7/27/11
to XADisk
Thanks for the help Nitin and Stelios!

On 26 jul, 15:29, Nitin Verma <emailtonve...@gmail.com> wrote:
> Hello Lucas, Hello Stelios
>
> Sorry, somehow I missed this thread.
>
> Stelios, I guess you were aiming to have XADisk work in JCA style
> without the standard JCA container; would XADisk Session/XASession not
> serve the purpose for you?
>
> Lucas, I have attempted a very basic example of doing XADisk in
> Spring. See if this helps.
>
> ________________________________________________________________________________________________________________________________
>
> <default-package>/Beans.xml
> --------------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

alexis.p...@gmail.com

unread,
Nov 26, 2012, 7:28:13 AM11/26/12
to xad...@googlegroups.com
Hello,

I had the same problem you had. I published a factory that is spring configurable so you can get XASession ala hibernate (registred in Spring TransactionManager, callback to clean up resources).

I will make it clearer soon :).

A.
Reply all
Reply to author
Forward
0 new messages