SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Boost your
Java Enterprise Stack
with MongoDB
!
!

bernd@mongosoup.de / twitter: @Bernd_Z
christian@mongosoup.de
!
26. Nov. 2013 @ Leightweight Java User Group Munich
Continuous Delivery
Standard JEE Stack
Frontend Layer
Service Layer
Repository Layer
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"
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;
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();
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 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());
}
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" />
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());
}
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 in memory DB for testing
MongoDB - Schemaless

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

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

Presenter

Más contenido relacionado

Más de Bernd Zuther

Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBernd Zuther
 
Building an-online-recommendation-engine-with-mongodb-cebit-hannover
Building an-online-recommendation-engine-with-mongodb-cebit-hannoverBuilding an-online-recommendation-engine-with-mongodb-cebit-hannover
Building an-online-recommendation-engine-with-mongodb-cebit-hannoverBernd Zuther
 
Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBernd Zuther
 
Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBernd Zuther
 
Mongodb + Hadoop Big Data Solyanka
Mongodb + Hadoop Big Data SolyankaMongodb + Hadoop Big Data Solyanka
Mongodb + Hadoop Big Data SolyankaBernd Zuther
 
Real time Analytics with MongoDB
Real time Analytics with MongoDBReal time Analytics with MongoDB
Real time Analytics with MongoDBBernd Zuther
 

Más de Bernd Zuther (6)

Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDB
 
Building an-online-recommendation-engine-with-mongodb-cebit-hannover
Building an-online-recommendation-engine-with-mongodb-cebit-hannoverBuilding an-online-recommendation-engine-with-mongodb-cebit-hannover
Building an-online-recommendation-engine-with-mongodb-cebit-hannover
 
Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDB
 
Building an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDBBuilding an Online-Recommendation Engine with MongoDB
Building an Online-Recommendation Engine with MongoDB
 
Mongodb + Hadoop Big Data Solyanka
Mongodb + Hadoop Big Data SolyankaMongodb + Hadoop Big Data Solyanka
Mongodb + Hadoop Big Data Solyanka
 
Real time Analytics with MongoDB
Real time Analytics with MongoDBReal time Analytics with MongoDB
Real time Analytics with MongoDB
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 

Último (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

LJUGM - Boost your Java Enterprise Stack with MongoDB