提交 2ffd6f03 编写于 作者: 黄勇

【F】重构 DataSet 相关方法,使其支持 Conditions 与 Orders 对象

上级 657bdfbb
......@@ -11,7 +11,9 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.smart4j.framework.orm.Conditions;
import org.smart4j.framework.orm.DataSet;
import org.smart4j.framework.orm.Sorts;
import org.smart4j.framework.tx.annotation.Service;
import org.smart4j.framework.tx.annotation.Transaction;
import org.smart4j.plugin.rest.Rest;
......@@ -26,13 +28,13 @@ public class ProductService {
@GET
@Path("/products")
public List<Product> getProductList() {
return DataSet.selectList(Product.class, "", "id asc");
return DataSet.selectList(Product.class, null, new Sorts().sort("id", "asc"));
}
@GET
@Path("/product/{productId}")
public Product getProduct(@PathParam("productId") long productId) {
return DataSet.select(Product.class, "id = ?", productId);
return DataSet.select(Product.class, new Conditions().condition("id", "=", "?"), productId);
}
@POST
......@@ -46,13 +48,13 @@ public class ProductService {
@Path("/product/{productId}")
@Transaction
public boolean updateProduct(@PathParam("productId") long productId, Map<String, Object> productFieldMap) {
return DataSet.update(Product.class, productFieldMap, "id = ?", productId);
return DataSet.update(Product.class, productFieldMap, new Conditions().condition("id", "=", "?"), productId);
}
@DELETE
@Path("/product/{productId}")
@Transaction
public boolean deleteProduct(@PathParam("productId") long productId) {
return DataSet.delete(Product.class, "id = ?", productId);
return DataSet.delete(Product.class, new Conditions().condition("id", "=", "?"), productId);
}
}
......@@ -7,7 +7,9 @@ import org.smart4j.framework.dao.bean.Pager;
import org.smart4j.framework.ioc.annotation.Inject;
import org.smart4j.framework.mvc.UploadHelper;
import org.smart4j.framework.mvc.bean.Multipart;
import org.smart4j.framework.orm.Conditions;
import org.smart4j.framework.orm.DataSet;
import org.smart4j.framework.orm.Sorts;
import org.smart4j.framework.tx.annotation.Service;
import org.smart4j.framework.tx.annotation.Transaction;
import org.smart4j.sample.Tool;
......@@ -39,7 +41,7 @@ public class ProductServiceImpl implements ProductService {
@Override
@Transaction
public boolean deleteProduct(long id) {
return DataSet.delete(Product.class, "id = ?", id);
return DataSet.delete(Product.class, new Conditions().condition("id", "=", "?"), id);
}
@Override
......@@ -48,7 +50,7 @@ public class ProductServiceImpl implements ProductService {
if (multipart != null) {
fieldMap.put("picture", multipart.getFileName());
}
boolean result = DataSet.update(Product.class, fieldMap, "id = ?", id);
boolean result = DataSet.update(Product.class, fieldMap, new Conditions().condition("id", "=", "?"), id);
if (result && multipart != null) {
UploadHelper.uploadFile(Tool.getBasePath(), multipart);
}
......@@ -60,7 +62,7 @@ public class ProductServiceImpl implements ProductService {
@Override
public Product getProduct(long id) {
return DataSet.select(Product.class, "id = ?", id);
return DataSet.select(Product.class, new Conditions().condition("id", "=", "?"), id);
}
@Override
......@@ -68,7 +70,7 @@ public class ProductServiceImpl implements ProductService {
ProductBean productBean = null;
Product product = getProduct(id);
if (product != null) {
ProductType productType = DataSet.select(ProductType.class, "id = ?", product.getProductTypeId());
ProductType productType = DataSet.select(ProductType.class, new Conditions().condition("id", "=", "?"), product.getProductTypeId());
if (productType != null) {
productBean = new ProductBean(product, productType);
}
......@@ -78,13 +80,13 @@ public class ProductServiceImpl implements ProductService {
@Override
public Pager<ProductBean> getProductBeanPager(int pageNumber, int pageSize, String name) {
String condition = "name like ?";
String sort = "id desc";
Conditions conditions = new Conditions().condition("name", "like", "?");
Sorts sorts = new Sorts().sort("id", "desc");
Object[] params = {"%" + name + "%"};
long count = DataSet.selectCount(Product.class, condition, params);
long count = DataSet.selectCount(Product.class, conditions, params);
List<ProductBean> productBeanList = new ArrayList<ProductBean>();
List<Product> productList = DataSet.selectListForPager(pageNumber, pageSize, Product.class, condition, sort, params);
List<Product> productList = DataSet.selectListForPager(pageNumber, pageSize, Product.class, conditions, sorts, params);
Map<Long, ProductType> productTypeMap = DataSet.selectMap(ProductType.class);
for (Product product : productList) {
ProductType productType = productTypeMap.get(product.getProductTypeId());
......
......@@ -2,7 +2,9 @@ package org.smart4j.sample.soap.impl;
import java.util.List;
import java.util.Map;
import org.smart4j.framework.orm.Conditions;
import org.smart4j.framework.orm.DataSet;
import org.smart4j.framework.orm.Sorts;
import org.smart4j.framework.tx.annotation.Service;
import org.smart4j.framework.tx.annotation.Transaction;
import org.smart4j.sample.entity.Product;
......@@ -13,12 +15,12 @@ public class ProductServiceImpl implements ProductService {
@Override
public List<Product> getProductList() {
return DataSet.selectList(Product.class, "", "id asc");
return DataSet.selectList(Product.class, null, new Sorts().sort("id", "asc"));
}
@Override
public Product getProduct(long productId) {
return DataSet.select(Product.class, "id = ?", productId);
return DataSet.select(Product.class, new Conditions().condition("id", "=", "?"), productId);
}
@Override
......@@ -30,12 +32,12 @@ public class ProductServiceImpl implements ProductService {
@Override
@Transaction
public boolean updateProduct(long productId, Map<String, Object> productFieldMap) {
return DataSet.update(Product.class, productFieldMap, "id = ?", productId);
return DataSet.update(Product.class, productFieldMap, new Conditions().condition("id", "=", "?"), productId);
}
@Override
@Transaction
public boolean deleteProduct(long productId) {
return DataSet.delete(Product.class, "id = ?", productId);
return DataSet.delete(Product.class, new Conditions().condition("id", "=", "?"), productId);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册