-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a main application to persist test data on local storage
- Loading branch information
Roger Kowalewski
committed
Aug 16, 2013
1 parent
0b22b8c
commit 04b5051
Showing
14 changed files
with
139 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
# Mac | ||
.DS_Store | ||
.shell_history | ||
|
||
# Maven | ||
log/ | ||
|
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,28 @@ | ||
package com.comsysto.neo4j.showcase.main; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.transaction.jta.JtaTransactionManager; | ||
|
||
import javax.transaction.*; | ||
|
||
/** | ||
* @author: rkowalewski | ||
*/ | ||
public class Main { | ||
|
||
private static final String CLASSPATH_LOCATION = "classpath:com/comsysto/neo4j/showcase/main/related-to-via-test-context.xml"; | ||
|
||
public static void main(String[] args) throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException { | ||
|
||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CLASSPATH_LOCATION); | ||
|
||
JtaTransactionManager tx = (JtaTransactionManager) context.getBean("neo4jTransactionManager"); | ||
Neo4jPersister neo4jPersister = (Neo4jPersister) context.getBean("neo4jPersister"); | ||
|
||
tx.getTransactionManager().begin(); | ||
|
||
neo4jPersister.createTestData(); | ||
|
||
tx.getTransactionManager().commit(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/comsysto/neo4j/showcase/main/Neo4jPersister.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,64 @@ | ||
package com.comsysto.neo4j.showcase.main; | ||
|
||
import com.comsysto.neo4j.showcase.model.Product; | ||
import com.comsysto.neo4j.showcase.repository.ProductRepository; | ||
import com.comsysto.neo4j.showcase.model.User; | ||
import com.comsysto.neo4j.showcase.repository.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* @author: rkowalewski | ||
*/ | ||
@Component | ||
@Transactional(propagation = Propagation.REQUIRED) | ||
public class Neo4jPersister { | ||
|
||
@Autowired | ||
public ProductRepository productRepository; | ||
@Autowired | ||
public UserRepository userRepository; | ||
|
||
private void userClickedProduct(User user, Product product) { | ||
|
||
user.addClickedProduct(product); | ||
|
||
userRepository.save(user); | ||
productRepository.save(product); | ||
} | ||
|
||
private Product createProduct(String id, String name) { | ||
return productRepository.save(new Product(id, name)); | ||
} | ||
|
||
private User createUser(String id, String name) { | ||
return userRepository.save(new User(id, name)); | ||
} | ||
|
||
public void createTestData() { | ||
User jordan = createUser("MJ", "Monika Jordan"); | ||
User pippen = createUser("SP", "Sandra Pippen"); | ||
User miller = createUser("JM", "John Miller"); | ||
|
||
Product pizzaMargarita = createProduct("Pizza_1", "Pizza Margarita"); | ||
Product pizzaFungi = createProduct("Pizza_2", "Pizza Fungi"); | ||
Product pizzaSalami = createProduct("Pizza_3", "Pizza Salami"); | ||
Product pizzaVegitarian = createProduct("Pizza_4", "Pizza Vegitarian"); | ||
Product pizzaRustica = createProduct("Pizza_5", "Pizza Rustica"); | ||
|
||
userClickedProduct(jordan, pizzaMargarita); | ||
userClickedProduct(jordan, pizzaFungi); | ||
userClickedProduct(jordan, pizzaSalami); | ||
|
||
userClickedProduct(pippen, pizzaMargarita); | ||
userClickedProduct(pippen, pizzaVegitarian); | ||
userClickedProduct(pippen, pizzaRustica); | ||
userClickedProduct(pippen, pizzaMargarita); | ||
userClickedProduct(pippen, pizzaVegitarian); | ||
|
||
userClickedProduct(miller, pizzaFungi); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...taNeo4j/showcase/ClickedRelationship.java → ...j/showcase/model/ClickedRelationship.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
2 changes: 1 addition & 1 deletion
2
...ataNeo4j/showcase/IdentifiableEntity.java → ...4j/showcase/model/IdentifiableEntity.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
2 changes: 1 addition & 1 deletion
2
...sto/springDataNeo4j/showcase/Product.java → ...omsysto/neo4j/showcase/model/Product.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
2 changes: 1 addition & 1 deletion
2
...Neo4j/showcase/RecommendRelationship.java → ...showcase/model/RecommendRelationship.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
2 changes: 1 addition & 1 deletion
2
...DataNeo4j/showcase/RelationshipTypes.java → ...o4j/showcase/model/RelationshipTypes.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
2 changes: 1 addition & 1 deletion
2
...msysto/springDataNeo4j/showcase/User.java → ...m/comsysto/neo4j/showcase/model/User.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
3 changes: 2 additions & 1 deletion
3
...DataNeo4j/showcase/ProductRepository.java → ...howcase/repository/ProductRepository.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
3 changes: 2 additions & 1 deletion
3
...ingDataNeo4j/showcase/UserRepository.java → ...j/showcase/repository/UserRepository.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
21 changes: 21 additions & 0 deletions
21
src/main/resources/com/comsysto/neo4j/showcase/main/related-to-via-test-context.xml
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" | ||
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.0.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd | ||
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> | ||
|
||
<context:spring-configured/> | ||
<context:annotation-config/> | ||
|
||
<neo4j:config storeDirectory="target/data/db_main"/> | ||
|
||
<neo4j:repositories base-package="com.comsysto.neo4j.showcase.repository"/> | ||
|
||
<context:component-scan base-package="com.comsysto.neo4j.showcase.main"/> | ||
|
||
</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
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