提交 f0a6c45b 编写于 作者: 黄勇

【F】重构 DataSet 相关方法,使用 # 表达式

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