Boost your
Java Enterprise Stack
with MongoDB
!
!

bernd@mongosoup.de / twitter: @Bernd_Z
christian@mongosoup.de
!
26. Nov...
Continuous Delivery
Standard JEE Stack
Frontend Layer
Service Layer
Repository Layer
MongoDB
{

}

"_id" : ObjectId("51f2ce49c2e6dce83534b73f"),
"orderId" : NumberLong(666),
"orderItems" : [
{
"product" : {
...
Hibernate ORM
@Entity
@Table(name = „ORDER")
public class Order implements Serializable {

!

!

@Id
@GeneratedValue
@Colu...
Spring Data
@Document(collection = Order.COLLECTION_NAME)
public class Order implements Serializable {
public static final ...
Unit Tests
- Fast
- Isolated
- Repeatable

relational in memory DB for testing

- Self-verifying
- Timely
DBUnit
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User id="0" title="Mr" firstName="Bernd" lastName="Zuther"/>
<User...
Fongo
<dependency>
<groupId>com.github.fakemongo</groupId>
<artifactId>fongo</artifactId>
<version>1.3.2</version>
</depen...
NoSQLUnit
@ActiveProfiles("test")
@ContextConfiguration(locations = "classpath:com/comsysto/shop/ui/spring-context.xml")
@Us...
Continuous Delivery
Infrastructure
Danger Area
Downtime
Flyway

relational in memory DB for testing
Flyway

relational in memory DB for testing
MongoDB - Schemaless

{ name : "Bernd", age : 30, interests : "football" }

!

{ name : "Christian", age : 25 }
relational...
MongoDB - Schemaless

relational in memory DB for testing
Build... Test... Live!

https://github.com/comsysto/mongodb-onlineshop/
Questions

Presenter
LJUGM  - Boost your Java Enterprise Stack with MongoDB
LJUGM  - Boost your Java Enterprise Stack with MongoDB
Upcoming SlideShare
Loading in …5
×

LJUGM - Boost your Java Enterprise Stack with MongoDB

557 views

Published on

If you want to use MongoDB in the Java Enterprise World you have to address two questions.

The first one is: Should I use the native driver or should I use a persistence framework? Spring is a common framework in many Java applications. It has created a very good object-document-mapping framework with Spring Data for MongoDB. It is easy to integrate into new and existing Java applications.

The second question is: How can I ensure my deliverables against error? So you need a testing framework. NoSQLUnit is such a framework that helps you to write tests against a real MongoDB Server or an in-memory clone like Fongo.

This talk will cover Spring Data and NoSQLUnit. It will give a basic overview about what things are useful before you can deploy your application, e.g. in a cloud service like MongoSoup.

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
557
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

LJUGM - Boost your Java Enterprise Stack with MongoDB

  1. 1. Boost your Java Enterprise Stack with MongoDB ! ! bernd@mongosoup.de / twitter: @Bernd_Z christian@mongosoup.de ! 26. Nov. 2013 @ Leightweight Java User Group Munich
  2. 2. Continuous Delivery
  3. 3. Standard JEE Stack Frontend Layer Service Layer Repository Layer
  4. 4. MongoDB { } "_id" : ObjectId("51f2ce49c2e6dce83534b73f"), "orderId" : NumberLong(666), "orderItems" : [ { "product" : { "_id" : ObjectId("51f2ce48c2e6dce83534b6ba"), "articleId" : "100", "name" : "Margherita", "urlname" : "margherita", "description" : "our famous tomato sauce and genuine mozzarella", "type" : "PIZZA", "category" : "vegetarian", "price" : 3.8 }, "uuid" : "839f8305-a5e7-408a-96d5-e3d2819d6ad3" } ], "orderDate" : ISODate("2011-09-13T07:24:00Z"), "deliveryAddress" : { "firstname" : "Christan", "lastname" : "Kroemer", "street" : „Lindwurm Straße", "zip" : "80337", "city" : "Munich", "houseNumber" : "97" }, "userId" : "51f2ce48c2e6dce83534b70b"
  5. 5. Hibernate ORM @Entity @Table(name = „ORDER") public class Order implements Serializable { ! ! @Id @GeneratedValue @Column(name="ID") private Long id; mapping of POJOs to relational database tables ! @OneToOne(cascade = CascadeType.ALL, optional = false, orphanRemoval = false) @JoinColumn(name = "USER_ID", nullable = false) @ForeignKey(name = "ORDER_USER_FK") private User user; @OneToMany(mappedBy = "order") @Fetch(FetchMode.JOIN) private List<OrderItem> orderItems;
  6. 6. Spring Data @Document(collection = Order.COLLECTION_NAME) public class Order implements Serializable { public static final String COLLECTION_NAME = "order"; ! @Id private ObjectId id; ! @Indexed(unique = true) annotated sample class here private long orderId; ! @DBRef private User user; private List<OrderItem> orderItems; ! @Indexed private Date orderDate = new Date();
  7. 7. Unit Tests - Fast - Isolated - Repeatable relational in memory DB for testing - Self-verifying - Timely
  8. 8. DBUnit <?xml version="1.0" encoding="UTF-8"?> <dataset> <User id="0" title="Mr" firstName="Bernd" lastName="Zuther"/> <User id="1" title="Mr" firstName="Christian" lastName="Kroemer"/> </dataset> @Test @DatabaseSetup("sampleData.xml") public void testFind() throws Exception { List<User> userList = userService.findByName("Christian"); assertEquals(1, userList.size()); assertEquals("Christian", userList.get(0).getFirstName()); }
  9. 9. Fongo <dependency> <groupId>com.github.fakemongo</groupId> <artifactId>fongo</artifactId> <version>1.3.2</version> </dependency> ! ! ! alternative for the Mongo world ! TODO: does mongo soup fit in there anywhere? <bean name="fongo" class=“com.github.fakemongo.Fongo"> <constructor-arg value="InMemoryMongo" /> </bean> ! <bean id="mongo" factory-bean="fongo" factory-method="getMongo" />
  10. 10. NoSQLUnit @ActiveProfiles("test") @ContextConfiguration(locations = "classpath:com/comsysto/shop/ui/spring-context.xml") @UsingDataSet(locations="initialData.json", loadStrategy=LoadStrategyEnum.CLEAN_INSERT) public class OrderRepositoryImplTest extends AbstractJUnit4SpringContextTests { ! ! } @Autowired private OrderRepository orderRepository; @Autowired private ApplicationContext applicationContext; Presenter @Rule public MongoDbRule mongoDbRule = newMongoDbRule().defaultSpringMongoDb("pizza"); @Test public void testFindAll() { Sort sortOrder = new Sort(Sort.Direction.ASC, "orderId"); List<Order> retrievedOrders = orderRepository.findAll(10, 0, sortOrder); assertNotNull(retrievedOrders); assertEquals(5, retrievedOrders.size()); }
  11. 11. Continuous Delivery
  12. 12. Infrastructure
  13. 13. Danger Area
  14. 14. Downtime
  15. 15. Flyway relational in memory DB for testing
  16. 16. Flyway relational in memory DB for testing
  17. 17. MongoDB - Schemaless { name : "Bernd", age : 30, interests : "football" } ! { name : "Christian", age : 25 } relational in memory DB for testing
  18. 18. MongoDB - Schemaless relational in memory DB for testing
  19. 19. Build... Test... Live! https://github.com/comsysto/mongodb-onlineshop/
  20. 20. Questions Presenter

×