Permalink
Browse files

Added Spring Data support and removed iBatis.

  • Loading branch information...
1 parent c65a5e3 commit e616bb1716328b12a47e8d528dd8f096738a0b09 astefan committed Sep 2, 2011
Showing with 1,574 additions and 683 deletions.
  1. +1 −5 jpetstore/.classpath
  2. +3 −0 jpetstore/.settings/com.springsource.sts.maven.prefs
  3. +2 −2 jpetstore/.settings/org.maven.ide.eclipse.prefs
  4. +64 −4 jpetstore/pom.xml
  5. +6 −0 jpetstore/readme.txt
  6. +0 −24 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/MsSqlOrderDao.java
  7. +0 −19 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/OracleSequenceDao.java
  8. +0 −57 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapAccountDao.java
  9. +0 −20 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapCategoryDao.java
  10. +0 −46 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapItemDao.java
  11. +0 −43 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapOrderDao.java
  12. +0 −46 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapProductDao.java
  13. +0 −28 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/SqlMapSequenceDao.java
  14. +0 −107 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Account.xml
  15. +0 −25 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Category.xml
  16. +0 −76 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Item.xml
  17. +0 −22 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/LineItem.xml
  18. +0 −75 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Order.xml
  19. +0 −35 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Product.xml
  20. +0 −23 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml
  21. +205 −0 ...tore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataAccountDao.java
  22. +63 −0 ...ore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataCategoryDao.java
  23. +141 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataItemDao.java
  24. +201 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataOrderDao.java
  25. +100 −0 ...tore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataProductDao.java
  26. +78 −0 ...ore/src/main/java/org/springframework/samples/jpetstore/dao/springdata/SpringDataSequenceDao.java
  27. +1 −1 jpetstore/src/main/java/org/springframework/samples/jpetstore/{dao/ibatis → domain}/Sequence.java
  28. +62 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QAccount.java
  29. +42 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QBannerdata.java
  30. +46 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QCategory.java
  31. +42 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QInventory.java
  32. +64 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QItem.java
  33. +48 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QLineitem.java
  34. +88 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QOrders.java
  35. +46 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QOrderstatus.java
  36. +50 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QProduct.java
  37. +48 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QProfile.java
  38. +42 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QSequence.java
  39. +42 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QSignon.java
  40. +58 −0 jpetstore/src/main/java/org/springframework/samples/jpetstore/generated/domain/QSupplier.java
  41. +31 −25 jpetstore/src/main/webapp/WEB-INF/dataAccessContext-local.xml
View
@@ -2,11 +2,7 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
- </attributes>
- </classpathentry>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -0,0 +1,3 @@
+#Wed Aug 17 23:17:29 EEST 2011
+com.springsource.sts.maven.maven.automatically.update=true
+eclipse.preferences.version=1
@@ -1,9 +1,9 @@
-#Thu May 28 18:03:42 EDT 2009
+#Wed Aug 17 22:55:39 EEST 2011
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
-resolveWorkspaceProjects=true
+resolveWorkspaceProjects=false
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
View
@@ -19,7 +19,7 @@
<commons-io.version>1.3.2</commons-io.version>
<urlrewrite.version>3.1.0</urlrewrite.version>
<spring-js.version>2.0.7.RELEASE</spring-js.version>
- <ibatis.version>2.3.4.726</ibatis.version>
+ <!-- <ibatis.version>2.3.4.726</ibatis.version> -->
<caucho.version>3.2.1</caucho.version>
<axis.version>1.4.0</axis.version>
<wsdl.version>1.6.1</wsdl.version>
@@ -102,6 +102,31 @@
<artifactId>urlrewritefilter</artifactId>
<version>${urlrewrite.version}</version>
</dependency>
+
+ <!-- Spring Data JDBC Extensions -->
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-jdbc-core</artifactId>
+ <version>1.0.0.M2</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- Query DSL -->
+ <dependency>
+ <groupId>com.mysema.querydsl</groupId>
+ <artifactId>querydsl-sql</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+
<!-- Spring Framework Project libraries -->
<dependency>
<groupId>org.springframework</groupId>
@@ -132,7 +157,7 @@
</exclusion>
</exclusions>
</dependency>
-
+
<!-- Spring JavaScript Project -->
<dependency>
<groupId>org.springframework.webflow</groupId>
@@ -146,12 +171,15 @@
</exclusions>
</dependency>
+ <!--
<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>com.springsource.com.ibatis</artifactId>
<version>${ibatis.version}</version>
<scope>runtime</scope>
</dependency>
+ -->
+
<dependency>
<groupId>com.caucho</groupId>
<artifactId>com.springsource.com.caucho</artifactId>
@@ -188,7 +216,7 @@
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
- <!-- Container-provided dependencies-->
+ <!-- Container-provided dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
@@ -217,7 +245,12 @@
<snapshots>
<updatePolicy>daily</updatePolicy>
</snapshots>
- </repository>
+ </repository>
+ <repository>
+ <id>spring-milestone</id>
+ <name>Spring Maven MILESTONE Repository</name>
+ <url>http://maven.springframework.org/milestone</url>
+ </repository>
<repository>
<id>standard repo</id>
<url>http://repo1.maven.org/maven2</url>
@@ -259,6 +292,33 @@
<target>1.5</target>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>com.mysema.querydsl</groupId>
+ <artifactId>querydsl-maven-plugin</artifactId>
+ <version>2.2.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>export</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <jdbcDriver>com.vmware.sqlfire.jdbc.ClientDriver</jdbcDriver>
+ <jdbcUrl>jdbc:sqlfire://localhost:1527</jdbcUrl>
+ <packageName>org.springframework.samples.jpetstore.generated.domain</packageName>
+ <targetFolder>${project.basedir}/src/main/java</targetFolder>
+ <schemaPattern>APP</schemaPattern>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>com.vmware.sqlfire</groupId>
+ <artifactId>sqlfire-client</artifactId>
+ <version>1.0.0-Beta</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</build>
</project>
View
@@ -92,6 +92,12 @@ peers. These instructions use multicast for server discovery.
- The data associated with the application should be loaded into SQLFire. This is accomplished
by using the files that can be found under jpetstore\db\sqlfire.
+- To get the project to generate all the Querydsl query types for the tables in the database, the
+needed step is outlined in pom.xml using the querydsl-maven-plugin. Since this plugin needs
+the sqlfireclient jar, this has to be manually added to the local Maven repository:
+mvn install:install-file -DgroupId=com.vmware.sqlfire -DartifactId=sqlfire-client -Dpackaging=jar
+-Dversion=1.0.0-Beta -Dfile=[sqlfireclient_jar_location] -DgeneratePom=true
+
- Start the Tomcat service and, after the startup procedure has finished, copy the application
war file created earlier to [Tomcat_DIR]\webapps. After the deployment has finished, open up
a browser and go to http://localhost:8080/jpetstore-1.0.0-SNAPSHOT
@@ -1,24 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.jpetstore.domain.LineItem;
-import org.springframework.samples.jpetstore.domain.Order;
-
-public class MsSqlOrderDao extends SqlMapOrderDao {
-
- /**
- * Special MS SQL Server version to allow the Item ID
- * to be retrieved from an identity column.
- */
- public void insertOrder(Order order) throws DataAccessException {
- Integer orderId = (Integer) getSqlMapClientTemplate().queryForObject("msSqlServerInsertOrder", order);
- order.setOrderId(orderId.intValue());
- getSqlMapClientTemplate().insert("insertOrderStatus", order);
- for (int i = 0; i < order.getLineItems().size(); i++) {
- LineItem lineItem = (LineItem) order.getLineItems().get(i);
- lineItem.setOrderId(order.getOrderId());
- getSqlMapClientTemplate().insert("insertLineItem", lineItem);
- }
- }
-
-}
@@ -1,19 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import org.springframework.dao.DataAccessException;
-
-public class OracleSequenceDao extends SqlMapSequenceDao {
-
- /**
- * Get the next sequence using an Oracle thread-safe sequence
- * @param name Name is the name of the oracle sequence.
- * @return the next sequence
- */
- public int getNextId(String name) throws DataAccessException {
- Sequence sequence = new Sequence();
- sequence.setName(name);
- sequence = (Sequence) getSqlMapClientTemplate().queryForObject("oracleSequence", sequence);
- return sequence.getNextId();
- }
-
-}
@@ -1,57 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import java.util.List;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
-import org.springframework.samples.jpetstore.dao.AccountDao;
-import org.springframework.samples.jpetstore.domain.Account;
-
-/**
- * In this and other DAOs in this package, a DataSource property
- * is inherited from the SqlMapClientDaoSupport convenience superclass
- * supplied by Spring. DAOs don't need to extend such superclasses,
- * but it saves coding in many cases. There are analogous superclasses
- * for JDBC (JdbcDaoSupport), Hibernate (HibernateDaoSupport),
- * JDO (JdoDaoSupport) etc.
- *
- * <p>This and other DAOs are configured using Dependency Injection.
- * This means, for example, that Spring can source the DataSource
- * from a local class, such as the Commons DBCP BasicDataSource,
- * or from JNDI, concealing the JNDI lookup from application code.
- *
- * @author Juergen Hoeller
- * @author Colin Sampaleanu
- */
-public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
-
- public Account getAccount(String username) throws DataAccessException {
- return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsername", username);
- }
-
- public Account getAccount(String username, String password) throws DataAccessException {
- Account account = new Account();
- account.setUsername(username);
- account.setPassword(password);
- return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsernameAndPassword", account);
- }
-
- public void insertAccount(Account account) throws DataAccessException {
- getSqlMapClientTemplate().insert("insertAccount", account);
- getSqlMapClientTemplate().insert("insertProfile", account);
- getSqlMapClientTemplate().insert("insertSignon", account);
- }
-
- public void updateAccount(Account account) throws DataAccessException {
- getSqlMapClientTemplate().update("updateAccount", account, 1);
- getSqlMapClientTemplate().update("updateProfile", account, 1);
- if (account.getPassword() != null && account.getPassword().length() > 0) {
- getSqlMapClientTemplate().update("updateSignon", account, 1);
- }
- }
-
- public List getUsernameList() throws DataAccessException {
- return getSqlMapClientTemplate().queryForList("getUsernameList", null);
- }
-
-}
@@ -1,20 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import java.util.List;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
-import org.springframework.samples.jpetstore.dao.CategoryDao;
-import org.springframework.samples.jpetstore.domain.Category;
-
-public class SqlMapCategoryDao extends SqlMapClientDaoSupport implements CategoryDao {
-
- public List getCategoryList() throws DataAccessException {
- return getSqlMapClientTemplate().queryForList("getCategoryList", null);
- }
-
- public Category getCategory(String categoryId) throws DataAccessException {
- return (Category) getSqlMapClientTemplate().queryForObject("getCategory", categoryId);
- }
-
-}
@@ -1,46 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
-import org.springframework.samples.jpetstore.dao.ItemDao;
-import org.springframework.samples.jpetstore.domain.Item;
-import org.springframework.samples.jpetstore.domain.LineItem;
-import org.springframework.samples.jpetstore.domain.Order;
-
-public class SqlMapItemDao extends SqlMapClientDaoSupport implements ItemDao {
-
- public void updateQuantity(Order order) throws DataAccessException {
- for (int i = 0; i < order.getLineItems().size(); i++) {
- LineItem lineItem = (LineItem) order.getLineItems().get(i);
- String itemId = lineItem.getItemId();
- Integer increment = new Integer(lineItem.getQuantity());
- Map param = new HashMap(2);
- param.put("itemId", itemId);
- param.put("increment", increment);
- getSqlMapClientTemplate().update("updateInventoryQuantity", param, 1);
- }
- }
-
- public boolean isItemInStock(String itemId) throws DataAccessException {
- Integer i = (Integer) getSqlMapClientTemplate().queryForObject("getInventoryQuantity", itemId);
- return (i != null && i.intValue() > 0);
- }
-
- public List getItemListByProduct(String productId) throws DataAccessException {
- return getSqlMapClientTemplate().queryForList("getItemListByProduct", productId);
- }
-
- public Item getItem(String itemId) throws DataAccessException {
- Item item = (Item) getSqlMapClientTemplate().queryForObject("getItem", itemId);
- if (item != null) {
- Integer qty = (Integer) getSqlMapClientTemplate().queryForObject("getInventoryQuantity", itemId);
- item.setQuantity(qty.intValue());
- }
- return item;
- }
-
-}
@@ -1,43 +0,0 @@
-package org.springframework.samples.jpetstore.dao.ibatis;
-
-import java.util.List;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
-import org.springframework.samples.jpetstore.dao.OrderDao;
-import org.springframework.samples.jpetstore.domain.LineItem;
-import org.springframework.samples.jpetstore.domain.Order;
-
-public class SqlMapOrderDao extends SqlMapClientDaoSupport implements OrderDao {
-
- private SqlMapSequenceDao sequenceDao;
-
- public void setSequenceDao(SqlMapSequenceDao sequenceDao) {
- this.sequenceDao = sequenceDao;
- }
-
- public List getOrdersByUsername(String username) throws DataAccessException {
- return getSqlMapClientTemplate().queryForList("getOrdersByUsername", username);
- }
-
- public Order getOrder(int orderId) throws DataAccessException {
- Object parameterObject = new Integer(orderId);
- Order order = (Order) getSqlMapClientTemplate().queryForObject("getOrder", parameterObject);
- if (order != null) {
- order.setLineItems(getSqlMapClientTemplate().queryForList("getLineItemsByOrderId", new Integer(order.getOrderId())));
- }
- return order;
- }
-
- public void insertOrder(Order order) throws DataAccessException {
- order.setOrderId(this.sequenceDao.getNextId("ordernum"));
- getSqlMapClientTemplate().insert("insertOrder", order);
- getSqlMapClientTemplate().insert("insertOrderStatus", order);
- for (int i = 0; i < order.getLineItems().size(); i++) {
- LineItem lineItem = (LineItem) order.getLineItems().get(i);
- lineItem.setOrderId(order.getOrderId());
- getSqlMapClientTemplate().insert("insertLineItem", lineItem);
- }
- }
-
-}
Oops, something went wrong.

0 comments on commit e616bb1

Please sign in to comment.