-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Spring Integration Settings.
- Loading branch information
Showing
7 changed files
with
216 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/sample/datanucleus_sample/dao/ProductDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sample.datanucleus_sample.dao; | ||
|
||
import java.util.List; | ||
|
||
import javax.jdo.PersistenceManager; | ||
import javax.jdo.PersistenceManagerFactory; | ||
import javax.jdo.Query; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import sample.datanucleus_sample.model.MyClass; | ||
|
||
@Repository | ||
public class ProductDao { | ||
@Autowired | ||
private PersistenceManagerFactory persistenceManagerFactory; | ||
|
||
public Object loadProductsByCategory(String category) { | ||
PersistenceManager pm = this.persistenceManagerFactory.getPersistenceManager(); | ||
try { | ||
Query query = pm.newQuery(MyClass.class); | ||
List<MyClass> results = (List<MyClass>) query.execute(); | ||
return results.get(0); | ||
} finally { | ||
pm.close(); | ||
} | ||
} | ||
|
||
@Transactional | ||
public MyClass save(MyClass input) { | ||
PersistenceManager pm = this.persistenceManagerFactory.getPersistenceManager(); | ||
try { | ||
return pm.makePersistent(input); | ||
} finally { | ||
pm.close(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<param name="threshold" value="DEBUG" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d\t%5p %C - %m%n" /> | ||
</layout> | ||
</appender> | ||
|
||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="File" value="sample.log" /> | ||
<param name="Encoding" value="UTF-8" /> | ||
<param name="threshold" value="DEBUG" /> | ||
<param name="Append" value="true" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d %-5p: %l - %m%n" /> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<priority value="DEBUG" /> | ||
<appender-ref ref="file" /> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
</log4j:configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> | ||
|
||
<!-- Scans within the base package of the application for @Components to | ||
configure as beans --> | ||
<context:component-scan base-package="sample.datanucleus_sample" /> | ||
<context:property-placeholder location="classpath:datanucleus.properties" /> | ||
|
||
<!-- Apache Commons Configuration Composite configuration --> | ||
<bean id="configuration" class="org.apache.commons.configuration.CompositeConfiguration"> | ||
<constructor-arg> | ||
<list> | ||
<bean class="org.apache.commons.configuration.PropertiesConfiguration"> | ||
<constructor-arg type="java.net.URL"> | ||
<value>classpath:datanucleus.properties</value> | ||
</constructor-arg> | ||
</bean> | ||
</list> | ||
</constructor-arg> | ||
</bean> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd | ||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd | ||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> | ||
|
||
<!-- DBの設定を外だしにするための設定ファイルの定義 --> | ||
<bean id="pmf" | ||
class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean"> | ||
<property name="configLocation" value="classpath:datanucleus.properties" /> | ||
</bean> | ||
|
||
<bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager"> | ||
<property name="persistenceManagerFactory" ref="pmf" /> | ||
</bean> | ||
|
||
<tx:annotation-driven /> | ||
|
||
</beans> |
52 changes: 52 additions & 0 deletions
52
src/test/java/sample/datanucleus_sample/dao/ProductDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package sample.datanucleus_sample.dao; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import sample.datanucleus_sample.model.MyClass; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = { | ||
"file:src/main/resources/spring/app-config.xml", | ||
"file:src/main/resources/spring/db-config.xml" }) | ||
public class ProductDaoTest { | ||
|
||
@Autowired | ||
private ProductDao dao; | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownAfterClass() throws Exception { | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testLoadProductsByCategory() { | ||
MyClass actual = (MyClass) dao.loadProductsByCategory("firstName"); | ||
assertThat(actual.getId(), is(10L)); | ||
|
||
actual.setId(101L); | ||
dao.save(actual); | ||
} | ||
|
||
} |