出于性能原因,许多报告查询在ORM管理对象之外执行。
为了存储结果,我使用one-per-query类来保存DB访问方法和服务之间的数据行。
例如在Java/Hibernate/Spring中:
@Repository
public interface DataRepository extends JpaRepository<DataDAO, Long> {
@Query("select new com.evil.db.XXX(...) from #{#entityName} where ...")
List<XXX> findXXX(...); XXX的名称是什么?是DTO、DAO还是Business object?在模式书和框架参考手册中,中间存储类是如何命名的?它是一个POJO,但是这个术语太通用了.
我通常将这些类作为内部静态类,并且不会为包含数据指定合适的名称。
但我喜欢为类名添加后缀,如果它是代表其角色的顶级类,就像传统上为DAO/Service/Controller/etc...所做的那样
发布于 2017-02-08 21:58:58
假设您使用的是Repository模式,那么您应该不会遇到这种命名问题。存储库模式通常由名为IRepository的接口确定方向--或者也可以是一个抽象类--表示数据库上的一般操作,如下所示(C#代码):
public interface IRepository<T>
{
T GetById(int id);
IEnumerable<T> List(Expression<Func<T, bool>> predicate);
void Add(T entity);
void Delete(T entity);
void Update(T entity);
}在您的案例中,由于您需要一些自定义查询,因此您应该为您的特定案例创建一个接口。以下示例引用强制实现IRepository的产品域(IProductRepository)的特定存储库。
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
public interface IProductRepository : IRepository<Product>
{
Product GetProductBySomething(string somemething);
IEnumerable<Product> GetAvailableProducts();
}最后,您将创建一个实现IRepositoryProduct的具体类。
public class ProductRepository : IProductRepository
{
public void Add(Product entity)
{
// ...
}
public void Delete(Product entity)
{
// ...
}
public IEnumerable<Product> Get(Expression<Func<Product, bool>> predicate)
{
// ...
}
public Product Get(int id)
{
// ...
}
public IEnumerable<Product> GetAvailableProducts()
{
// ...
}
public Product GetProductBySomething(string somemething)
{
// ...
}
public void Update(Product entity)
{
// ...
}
}
public Product Get(int id)
{
// ...
}
public void Update(Product entity)
{
// ...
}
}使用这种方法,你的方法应该不会有命名问题,因为它们将遵循接口约定。
https://stackoverflow.com/questions/42113050
复制相似问题