diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..6f98c7f --- /dev/null +++ b/.classpath @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..36cf2de --- /dev/null +++ b/.project @@ -0,0 +1,14 @@ + + + mule-transport-hibernate + Provides support for data object management using the Hibernate object-relational mapping API. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + org.eclipse.jdt.core.javabuilder + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b0da9bc --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Sat May 19 11:34:39 BST 2012 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 diff --git a/README.md b/README.md new file mode 100644 index 0000000..4009488 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# Hibernate Transport for Mule 3.1 + +This transport implements hibernate support for Mule 3.1 + +## Build Instructions: +To build use Maven execute the below command from the root folder, this will build the mule-transport-hibernate-3.x.x.jar and add it to the transports folder, you can then reference this jar from your mule project. + +``` +mvn package +``` + +You can also import the eclipse project to your workspace and reference the project in your mule project java build path for debugging. + +## Use Instructions: +To include this transport in your mule flow you need to create... +1. Spring Bean JDBC Data Source +2. Spring Bean Hibernate Session Factory +3. Spring Bean Hibernate Transaction Manager +4. JDBC Connector +5. Hibernate Connector +6. Hibernate Endpoint + +## Spring Bean JDBC Data Source +``` + + + +``` + +## Spring Bean Hibernate Session Factory +``` + + + + true + org.hibernate.dialect.SQLServerDialect + + + + + Person + + + + org.hibernate.cfg.AnnotationConfiguration + + + +``` + +## Spring Bean Hibernate Transaction Manager +``` + + + +``` + +## JDBC Connector +``` + +``` + +## Hibernate Connector +``` + +``` + +## Hibernate Endpoint -- add to your flow +``` + +``` + +## Namespace: +To use the hibernate xml namespace you must import it into your flow add... +``` +xmlns:hibernate="http://tabletlive.com/schema/mule/hibernate" +``` +to your root node and... +``` +http://tabletlive.com/schema/mule/hibernate http://tabletlive.com/schema/mule/hibernate/mule-hibernate.xsd +``` +to the root nodes schema location attribute. + +The above example uses a JDBC connection for Microsoft SQL Server however you can change your datasource to any JDBC driver you choose. +Another thing to note is the property +``` + + + Person + + +``` +on the session factory, this is the list of the classes you would like to persist with Hibernate, you can use a plain hibernate config instead of this, please see the Spring configuration guide for hibernate for further info [http://static.springsource.org/spring/docs/2.5.x/reference/orm.html](http://static.springsource.org/spring/docs/2.5.x/reference/orm.html). \ No newline at end of file diff --git a/dist/pom.xml b/dist/pom.xml index 4c957df..e55189c 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -5,7 +5,7 @@ 2.1-SNAPSHOT org.mule.transports - 2.2.1 + 3.2.1 2.2.0 mule-transport-hibernate diff --git a/pom.xml b/pom.xml index e50af98..4ce0b3a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,21 +5,23 @@ Hibernate Transport Provides support for data object management using the Hibernate object-relational mapping API. jar - - 2.2.1 + 3.2.1 + + 3.2.1 HIBERNATE hibernate - 2.2.1-SNAPSHOT Jira http://mule.mulesource.org/jira/browse/${shortId} + Bamboo http://bamboo.muleforge.org/browse/${shortId} @@ -86,7 +88,7 @@ org.apache.maven.plugins maven-pmd-plugin - 1.5 + 1.6 @@ -161,19 +163,14 @@ ${muleVersion} provided - org.hibernate hibernate - 3.2.2.ga + 3.6.0.Final provided + diff --git a/src/main/java/org/mule/transport/hibernate/HibernateConnector.java b/src/main/java/org/mule/transport/hibernate/HibernateConnector.java index defa873..0778474 100644 --- a/src/main/java/org/mule/transport/hibernate/HibernateConnector.java +++ b/src/main/java/org/mule/transport/hibernate/HibernateConnector.java @@ -2,7 +2,9 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.mule.api.MuleContext; import org.mule.api.MuleException; +import org.mule.api.construct.FlowConstruct; import org.mule.api.endpoint.InboundEndpoint; import org.mule.api.lifecycle.InitialisationException; import org.mule.api.service.Service; @@ -19,6 +21,11 @@ public class HibernateConnector extends AbstractConnector { + public HibernateConnector(MuleContext context) { + super(context); + // TODO Auto-generated constructor stub + } + public static final String HIBERNATE_PROTOCOL = "hibernate"; private SessionFactory sessionFactory; @@ -93,11 +100,12 @@ public void delete(Session session, Object payload) { public void setSessionDelete(HibernateSessionDelete sessionDelete) { this.sessionDelete = sessionDelete; } - + @Override - protected MessageReceiver createReceiver(Service service, InboundEndpoint endpoint) throws Exception { - return getServiceDescriptor().createMessageReceiver(this, service, endpoint, createReceiverParameters(endpoint)); - } + protected MessageReceiver createReceiver(FlowConstruct flowConstruct, InboundEndpoint endpoint) throws Exception { + + return getServiceDescriptor().createMessageReceiver(this, flowConstruct, endpoint); + } private Object[] createReceiverParameters(InboundEndpoint endpoint) { diff --git a/src/main/java/org/mule/transport/hibernate/HibernateMessageDispatcher.java b/src/main/java/org/mule/transport/hibernate/HibernateMessageDispatcher.java index 8c63907..0c2c082 100644 --- a/src/main/java/org/mule/transport/hibernate/HibernateMessageDispatcher.java +++ b/src/main/java/org/mule/transport/hibernate/HibernateMessageDispatcher.java @@ -47,9 +47,10 @@ protected MuleMessage doSend(MuleEvent event) throws Exception { protected void doDispatch(MuleEvent event) throws Exception { if (logger.isDebugEnabled()) logger.debug("Dispatch event: " + event); - - String writeStmt = event.getEndpoint().getEndpointURI().getAddress(); - + + //String writeStmt = event.getEndpoint().getEndpointURI().getAddress(); + String writeStmt = endpoint.getEndpointURI().getAddress(); + Object payload = event.transformMessage(); Transaction tx = TransactionCoordination.getInstance().getTransaction(); diff --git a/src/main/java/org/mule/transport/hibernate/HibernateMessageReceiver.java b/src/main/java/org/mule/transport/hibernate/HibernateMessageReceiver.java index aeef4fd..fd78a79 100644 --- a/src/main/java/org/mule/transport/hibernate/HibernateMessageReceiver.java +++ b/src/main/java/org/mule/transport/hibernate/HibernateMessageReceiver.java @@ -13,7 +13,7 @@ import org.mule.api.service.Service; import org.mule.api.transaction.Transaction; import org.mule.api.transport.Connector; -import org.mule.api.transport.MessageAdapter; + import org.mule.transaction.TransactionCoordination; import org.mule.transport.ConnectException; import org.mule.transport.TransactedPollingMessageReceiver; @@ -67,7 +67,7 @@ public HibernateMessageReceiver(Connector connector, @SuppressWarnings("unchecked") @Override - protected List getMessages() throws Exception { + protected List getMessages() throws Exception { Session session = null; try { try { @@ -83,7 +83,7 @@ protected List getMessages() throws Exception { logger.debug("messages: "+messages); if (singleMessage) - return Collections.singletonList((Object) messages); + return Collections.singletonList((MuleMessage) messages); else return messages; } finally { @@ -101,8 +101,8 @@ protected void processMessage(Object message) throws Exception { Transaction tx = TransactionCoordination.getInstance().getTransaction(); try { session = hibernateConnector.getSession(); - MessageAdapter msgAdapter = connector.getMessageAdapter(message); - MuleMessage umoMessage = new DefaultMuleMessage(msgAdapter, (Map) null); + + MuleMessage umoMessage = new DefaultMuleMessage(message, connector.getMuleContext()); if (ackStmt != null) { if (ackIsDelete) { if (logger.isDebugEnabled()) @@ -125,7 +125,12 @@ protected void processMessage(Object message) throws Exception { } } } - routeMessage(umoMessage, tx, tx != null || endpoint.isSynchronous()); + + routeMessage(umoMessage, tx); + + // TODO: investigate why below parameters are different + //routeMessage(umoMessage, tx, tx != null || endpoint.isSynchronous()); + } catch (Exception e) { if (tx != null) tx.setRollbackOnly(); diff --git a/src/main/java/org/mule/transport/hibernate/HibernateTransaction.java b/src/main/java/org/mule/transport/hibernate/HibernateTransaction.java index cb96d6e..48d9b41 100644 --- a/src/main/java/org/mule/transport/hibernate/HibernateTransaction.java +++ b/src/main/java/org/mule/transport/hibernate/HibernateTransaction.java @@ -7,10 +7,16 @@ import org.mule.config.i18n.CoreMessages; import org.mule.transaction.AbstractSingleResourceTransaction; import org.mule.transaction.IllegalTransactionStateException; +import org.mule.api.MuleContext; import org.mule.api.transaction.TransactionException; public class HibernateTransaction extends AbstractSingleResourceTransaction { + protected HibernateTransaction(MuleContext muleContext) { + super(muleContext); + // TODO Auto-generated constructor stub + } + private Transaction sessionTx; public void bindResource(Object key, Object resource) throws TransactionException { diff --git a/src/main/java/org/mule/transport/hibernate/HibernateTransactionFactory.java b/src/main/java/org/mule/transport/hibernate/HibernateTransactionFactory.java index 2d8c788..169afd7 100644 --- a/src/main/java/org/mule/transport/hibernate/HibernateTransactionFactory.java +++ b/src/main/java/org/mule/transport/hibernate/HibernateTransactionFactory.java @@ -8,7 +8,7 @@ public class HibernateTransactionFactory implements TransactionFactory { public Transaction beginTransaction(MuleContext muleContext) throws TransactionException { - Transaction tx = new HibernateTransaction(); + Transaction tx = new HibernateTransaction(muleContext); tx.begin(); return tx; } diff --git a/src/main/resources/META-INF/mule-hibernate.xsd b/src/main/resources/META-INF/mule-hibernate.xsd index c940a83..cc7684d 100644 --- a/src/main/resources/META-INF/mule-hibernate.xsd +++ b/src/main/resources/META-INF/mule-hibernate.xsd @@ -1,17 +1,34 @@ - - - + + + - + + Enables Hibernate support in mule for inbound and outbound connectors + + Hibernate + Hibernate Transport + + + + + + + diff --git a/src/main/resources/META-INF/spring.handlers b/src/main/resources/META-INF/spring.handlers index e03b45c..a2d7f4a 100644 --- a/src/main/resources/META-INF/spring.handlers +++ b/src/main/resources/META-INF/spring.handlers @@ -1 +1 @@ -http\://www.mulesource.org/schema/mule/hibernate/2.2=org.mule.transport.hibernate.config.HibernateNamespaceHandler +http://www.mulesoft.org/schema/mule//hibernate=org.mule.transport.hibernate.config.HibernateNamespaceHandler diff --git a/src/main/resources/META-INF/spring.schemas b/src/main/resources/META-INF/spring.schemas index 40c6ab5..22317cc 100644 --- a/src/main/resources/META-INF/spring.schemas +++ b/src/main/resources/META-INF/spring.schemas @@ -1 +1 @@ -http\://www.mulesource.org/schema/mule/hibernate/2.2/mule-hibernate.xsd=META-INF/mule-hibernate.xsd +http://www.mulesoft.org/schema/mule/hibernate/mule-hibernate.xsd=META-INF/mule-hibernate.xsd \ No newline at end of file