Skip to content

Commit

Permalink
in memory db
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio committed Apr 1, 2014
1 parent 7b32bc2 commit 6158583
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
.project
*.log
*.epoch
*.db
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- <dependency> -->
<!-- <groupId>mysql</groupId> -->
<!-- <artifactId>mysql-connector-java</artifactId> -->
<!-- </dependency> -->

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<dependency>
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/at/mul/CustomerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sql.DataSource;

import org.h2.jdbcx.JdbcDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -11,7 +12,6 @@
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;

@Configuration
@EnableTransactionManagement
Expand All @@ -23,15 +23,18 @@ public class CustomerConfig {

@Bean(name = "customerDataSource", initMethod = "init", destroyMethod = "close")
public DataSource customerDataSource() {
MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
mysqlXaDataSource.setUrl("jdbc:mysql://localhost:3306/atomikos_1");
mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
mysqlXaDataSource.setPassword("password");
mysqlXaDataSource.setUser("root");
mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);

// MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
// mysqlXaDataSource.setUrl("jdbc:mysql://localhost:3306/atomikos_1");
// mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
// mysqlXaDataSource.setPassword("password");
// mysqlXaDataSource.setUser("root");
// mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);

JdbcDataSource h2XaDataSource = new JdbcDataSource();
h2XaDataSource.setURL("jdbc:h2:customer");

AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
xaDataSource.setXaDataSource(mysqlXaDataSource);
xaDataSource.setXaDataSource(h2XaDataSource);
xaDataSource.setUniqueResourceName("xads1");
return xaDataSource;
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/at/mul/OrderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sql.DataSource;

import org.h2.jdbcx.JdbcDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -11,7 +12,6 @@
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;

@Configuration
@EnableTransactionManagement
Expand All @@ -23,15 +23,18 @@ public class OrderConfig {

@Bean(name = "orderDataSource", initMethod = "init", destroyMethod = "close")
public DataSource orderDataSource() {
MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
mysqlXaDataSource.setUrl("jdbc:mysql://localhost:3306/atomikos_2");
mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
mysqlXaDataSource.setPassword("password");
mysqlXaDataSource.setUser("root");
mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
// MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
// mysqlXaDataSource.setUrl("jdbc:mysql://localhost:3306/atomikos_2");
// mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
// mysqlXaDataSource.setPassword("password");
// mysqlXaDataSource.setUser("root");
// mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);

JdbcDataSource h2XaDataSource = new JdbcDataSource();
h2XaDataSource.setURL("jdbc:h2:order");

AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
xaDataSource.setXaDataSource(mysqlXaDataSource);
xaDataSource.setXaDataSource(h2XaDataSource);
xaDataSource.setUniqueResourceName("xads2");
return xaDataSource;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/at/mul/CustomerRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.at.mul.domain.customer.Customer;
Expand Down

0 comments on commit 6158583

Please sign in to comment.