Skip to content

Commit

Permalink
#30 - Started Updating Camel JPA-JTA Example
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Saunders committed Jun 3, 2016
1 parent cdbbb0c commit 5083112
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 155 deletions.
18 changes: 0 additions & 18 deletions karaf/camel-jpa_jta/README.md

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions karaf/camel-jpa_jta/src/main/resources/datasources/oracle-ds.xml

This file was deleted.

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# important! "connector" feature required to have rollback to work
features:install jndi jpa hibernate camel-jpa transaction connector
Build Application

install -s wrap:mvn:org.postgresql/postgresql/9.3-1102-jdbc41
Start Fuse

install -s blueprint:mvn:com.redhat.consulting.fusequickstarts.karaf/camel-jpa-jta/6.2.1/xml/postgres
install -s mvn:com.redhat.consulting.fusequickstarts.karaf/camel-jpa-jta/6.2.1
Install Dependencies
````
features:install jndi jpa hibernate camel-jpa transaction connector
install -s mvn:com.h2database/h2/1.3.163
install -s blueprint:mvn:com.redhat.consulting.fusequickstarts.karaf/camel-jpa-jta/6.2.1/xml/h2
````

la -l | tail
echo JPA Example installed.
Install Application
````
install -s mvn:com.redhat.consulting.fusequickstarts.karaf/camel-jpa-jta/6.2.1
````
16 changes: 1 addition & 15 deletions karaf/camel-jpa_jta/pom.xml → karaf/jpa_jta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<relativePath>../parent/pom.xml</relativePath>
</parent>

<artifactId>camel-jpa-jta</artifactId>
<artifactId>jpa-jta</artifactId>
<packaging>bundle</packaging>
<name>Fuse Quickstart :: Karaf :: Blueprint :: Camel JPA w/ Hibernate and JTA</name>

Expand Down Expand Up @@ -96,20 +96,6 @@
<type>xml</type>
<classifier>h2</classifier>
</artifact>
<artifact>
<file>target/classes/datasources/postgresql-ds.xml</file>
<type>xml</type>
<classifier>postgres</classifier>
</artifact>
<artifact>
<file>target/classes/datasources/oracle-ds.xml</file>
<type>xml</type>
<classifier>oracle</classifier>
</artifact>
<artifact>
<file>target/classes/scripts/deploy.karaf</file>
<type>karaf</type>
</artifact>
</artifacts>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Person {

@Id
@GeneratedValue
private long id;

private String name;
Expand All @@ -17,7 +17,8 @@ public Person(){

}

public Person(String pName){
public Person(long pId, String pName){
this.id = pId;
this.name = pName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.redhat.consulting.fusequickstarts.karaf.jpa.route;

import org.redhat.consulting.fusequickstarts.karaf.jpa.model.Person;
import org.apache.camel.builder.RouteBuilder;
import org.redhat.consulting.fusequickstarts.karaf.jpa.processor.ExceptionProcessor;

public class JpaRoutes extends RouteBuilder {

@Override
public void configure() throws Exception {
from("timer://jpaTimer?fixedRate=true&period=5000&repeatCount=1")
.routeId("Success Route")
.transacted()
.log(">>> Generating New Person")
.setBody(constant(new Person(1, Person.generateName())))
.log(">>> Saving Person")
.to("jpa://org.redhat.consulting.fusequickstarts.karaf.jpa.model.Person")
.log(">>> Saved Person: ${body}!");

from("jpa://org.redhat.consulting.fusequickstarts.karaf.jpa.model.Person")
.routeId("JPA Poll")
.log("Retrieved Person: ${body}");

/*from("timer://jpaTimer?fixedRate=true&period=5000&repeatCount=1")
.routeId("Failure Route")
.transacted()
.log(">>> Generating New Person")
.setBody(constant(new Person(2, "Rolled_Back_" + Person.generateName())))
.log(">>> Saving Person")
.to("jpa://org.redhat.consulting.fusequickstarts.karaf.jpa.model.Person")
.log(">>> Saved Person: ${body}!")
.beanRef("dummy","crash")
.log(">>> Rolled back");*/

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/h2ds)</jta-data-source>
<properties>

<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

<!-- <property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> -->
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>

<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.archive.autodetection" value="class"/>
<!-- <property name="hibernate.show_sql" value="true" /> -->
<!-- <property name="hibernate.format_sql" value="true" /> -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
30 changes: 30 additions & 0 deletions karaf/jpa_jta/src/main/resources/OSGI-INF/blueprint/blueprint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.1.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<reference id="transactionManager"
interface="org.springframework.transaction.PlatformTransactionManager" />
<reference id="entityManagerFactory" interface="javax.persistence.EntityManagerFactory" />

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<jpa:unit unitname="camelJpaContainer" property="entityManagerFactory" />
<property name="transactionManager" ref="transactionManager" />
</bean>

<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="transactionManager" />
</bean>

<bean id="dummy" class="org.redhat.consulting.fusequickstarts.karaf.jpa.Dummy" />

<camel:camelContext id="camel"
xmlns="http://camel.apache.org/schema/blueprint">
<packageScan>
<package>org.redhat.consulting.fusequickstarts.karaf.jpa.route</package>
</packageScan>
</camel:camelContext>
</blueprint>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

<bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
<!-- <property name="URL" value="jdbc:h2:/tmp/myapp;AUTO_SERVER=TRUE" /> -->
<property name="URL" value="jdbc:h2:/tmp/myapp;AUTO_SERVER=TRUE;AUTOCOMMIT=FALSE" />
<property name="user" value="sa" />
<property name="password" value="" />
Expand Down

0 comments on commit 5083112

Please sign in to comment.