Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4356fca
Showing
46 changed files
with
8,323 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
target |
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,226 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>xian</groupId> | ||
<artifactId>recipe</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>SDForum Spring MVC Tutorial</name> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jboss</id> | ||
<url>http://repository.jboss.com/maven2</url> | ||
</repository> | ||
</repositories> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<spring.version>3.0.2.RELEASE</spring.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- Testing --> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit-dep</artifactId> | ||
<version>4.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Core --> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.5.11</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>1.5.11</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>0.9.20</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.sourceforge.collections</groupId> | ||
<artifactId>collections-generic</artifactId> | ||
<version>4.01</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.collections</groupId> | ||
<artifactId>google-collections</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
<version>${spring.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.carbonfive.db-support</groupId> | ||
<artifactId>db-support</artifactId> | ||
<version>0.9.9-m4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>4.0.2.GA</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>3.3.2.GA</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>xml-apis</groupId> | ||
<artifactId>xml-apis</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javassist</groupId> | ||
<artifactId>javassist</artifactId> | ||
<version>3.8.1.GA</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.12</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>1.2.134</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<!-- Web --> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>2.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.tuckey</groupId> | ||
<artifactId>urlrewritefilter</artifactId> | ||
<version>3.0.4</version> | ||
<scope>runtime</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-mapper-asl</artifactId> | ||
<version>1.5.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>recipes</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<!--<plugin>--> | ||
<!--<groupId>org.apache.maven.plugins</groupId>--> | ||
<!--<artifactId>maven-surefire-plugin</artifactId>--> | ||
<!--<version>2.4.3</version>--> | ||
<!--</plugin>--> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,54 @@ | ||
package xian.recipes; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import xian.recipes.model.Recipe; | ||
import xian.recipes.model.Unit; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static xian.recipes.model.Ingredient.newIngredient; | ||
import static xian.recipes.model.Quantity.newQuantity; | ||
import static xian.recipes.model.Step.newStep; | ||
|
||
public class Bootstrapper | ||
{ | ||
@Autowired | ||
private RecipeRepository recipeRepository; | ||
|
||
public void bootstrap() | ||
{ | ||
Recipe recipe = new Recipe("Aloo Ghobi"); | ||
recipe.setDescription("Potatos and Cauliflower in a spicy sauce."); | ||
recipe.setPreparationTime(45); | ||
recipe.setCost(BigDecimal.valueOf(9.00)); | ||
recipe.addIngredient(newIngredient("Vegetable Oil", newQuantity(0.25, Unit.CUP))); | ||
recipe.addIngredient(newIngredient("Large Onion", newQuantity(1, Unit.WHOLE), "peeled and cut into small pieces")); | ||
recipe.addIngredient(newIngredient("Fresh Coriander", newQuantity(1, Unit.BUNCH), "separated into stalks and leaves and roughly chopped")); | ||
recipe.addIngredient(newIngredient("Small Green Chili", newQuantity(1, Unit.WHOLE), "chopped into small pieces")); | ||
recipe.addIngredient(newIngredient("Large Cauliflower", newQuantity(1, Unit.WHOLE), "eaves removed and cut evenly into eighths")); | ||
recipe.addIngredient(newIngredient("Large Potatoes", newQuantity(3, Unit.WHOLE), "peeled and cut into even pieces")); | ||
recipe.addIngredient(newIngredient("Diced Tomatoes", newQuantity(2, Unit.CANS))); | ||
recipe.addIngredient(newIngredient("Fresh Ginger", newQuantity(2, Unit.TABLESPOON), "peeled and grated")); | ||
recipe.addIngredient(newIngredient("Fresh Garlic", newQuantity(1, Unit.TEASPOON), "chopped")); | ||
recipe.addIngredient(newIngredient("Cumin Seed", newQuantity(1, Unit.TEASPOON))); | ||
recipe.addIngredient(newIngredient("Tumeric", newQuantity(2, Unit.TEASPOON))); | ||
recipe.addIngredient(newIngredient("Salt", newQuantity(1, Unit.TEASPOON))); | ||
recipe.addIngredient(newIngredient("Garam Masala", newQuantity(2, Unit.TEASPOON))); | ||
recipe.addStep(newStep("Heat vegetable oil in a large saucepan.")); | ||
recipe.addStep(newStep("Add the chopped onion and one teaspoon of cumin seeds to the oil.")); | ||
recipe.addStep(newStep("Stir together and cook until onions become creamy, golden, and translucent.")); | ||
recipe.addStep(newStep("Add chopped coriander stalks, two teaspoons of turmeric, and one teaspoon of salt.")); | ||
recipe.addStep(newStep("Add chopped chillis (according to taste) Stir tomatoes into onion mixture.")); | ||
recipe.addStep(newStep("Add ginger and garlic; mix thoroughly.")); | ||
recipe.addStep(newStep("Add potatoes and cauliflower to the sauce plus a few tablespoons of water (ensuring that the mixture doesn't stick to the saucepan).")); | ||
recipe.addStep(newStep("Ensure that the potatoes and cauliflower are coated with the curry sauce.")); | ||
recipe.addStep(newStep("Cover and allow to simmer for twenty minutes (or until potatoes are cooked).")); | ||
recipe.addStep(newStep("Add two teaspoons of Garam Masala and stir.")); | ||
recipe.addStep(newStep("Sprinkle chopped coriander leaves on top of the curry.")); | ||
recipe.addStep(newStep("Turn off the heat, cover, and leave for as long as possible before serving.")); | ||
|
||
recipeRepository.save(recipe); | ||
|
||
} | ||
} | ||
|
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,20 @@ | ||
package xian.recipes; | ||
|
||
import xian.recipes.model.Recipe; | ||
|
||
import java.util.List; | ||
|
||
public interface RecipeRepository | ||
{ | ||
Recipe find(long id); | ||
|
||
List<Recipe> find(); | ||
|
||
void save(Recipe recipe); | ||
|
||
void merge(Recipe recipe); | ||
|
||
void update(Recipe recipe); | ||
|
||
void destroy(Recipe recipe); | ||
} |
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,69 @@ | ||
package xian.recipes; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.hibernate.classic.Session; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import xian.recipes.model.Recipe; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class RecipeRepositoryImpl implements RecipeRepository | ||
{ | ||
private final SessionFactory sessionFactory; | ||
|
||
@Autowired | ||
public RecipeRepositoryImpl(SessionFactory sessionFactory) | ||
{ | ||
this.sessionFactory = sessionFactory; | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public Recipe find(long id) | ||
{ | ||
return (Recipe) getSession().createQuery("from Recipe where id = :id").setLong("id", id).uniqueResult(); | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<Recipe> find() | ||
{ | ||
return getSession().createQuery("from Recipe").list(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void save(Recipe recipe) | ||
{ | ||
getSession().save(recipe); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void merge(Recipe recipe) | ||
{ | ||
getSession().merge(recipe); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void update(Recipe recipe) | ||
{ | ||
getSession().update(recipe); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void destroy(Recipe recipe) | ||
{ | ||
getSession().delete(recipe); | ||
} | ||
|
||
private Session getSession() | ||
{ | ||
return sessionFactory.getCurrentSession(); | ||
} | ||
} |
Oops, something went wrong.