dao

DAO pattern - use Static or non Static methods?

可紊 提交于 2019-12-01 14:35:09
My application is using a DAO pattern. Should I make the implementing methods "static" or not? I'm talking about this concrete implementation: findByIdentifier(String identifier) But also about the Generic implementations: E getByID(K ID); List findAll(); save(E entity); update(E entity); delete(E entity); Thanks for the advice! public interface DaoBase<K, E> { E getByID(K ID); List<E> findAll(); void save(E entity); void update(E entity); void delete(E entity); } public interface DaoLanguage extends DaoBase<Long, LanguageEntity> { LanguageEntity findByIdentifier(String identifier); } I'm

Accessing Field2 in Access 2007

社会主义新天地 提交于 2019-12-01 13:43:55
I'm trying to write a simple little routine to email an attachment stored in an Access 2007 database. For some reason I cannot get the simplest part of it to work. I get an error saying "User-defined type not defined" on the following line: Dim attachmentField As DAO.Field2 Now up to this point I haven't accessed any DAO objects yet, but my assumption was that I only needed to add the relevant reference. Thing is, I seem to have a misconception about what that reference is. I have tried "Microsoft DAO 3.6 Object Library" which made sense, but I'm still getting the same error message. Then I

Struts 2 Hibernate null pointer exception while submitting the form

梦想的初衷 提交于 2019-12-01 11:25:10
I am trying to create a registration page by integrating Struts 2 & Hibernate. But when I am running the below code , I am getting a null pointer exception when I click the register button. hibernate configuration file: <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/db_socialnetwork</property> <property name="hibernate.connection.username">root</property> <property name=

Where should validation take place?

亡梦爱人 提交于 2019-12-01 10:36:27
I want to use MVC pattern in my PHP project. I also want to use Dao-Service pattern for Model layer since it makes database engines easily interchangeable and keeps business logic out of DB interaction. Now, I heard that validation should happen in Model layer since Controllers are only responsible for transporting data. That's pretty reasonable. Should it, however, be implemented in Service layer, or entities themselves? Approach 1: validation in entities class Post extends Entity { protected $title; public function getTitle() { return $this->title; } public function setTitle($newTitle) { if

web开发dao层通用接口

六眼飞鱼酱① 提交于 2019-12-01 10:17:05
接口 public interface IDao<E> { public List<E> findAll(); public E findById(Integer id); public void deleteById(Integer id); public void update(E entity); public List<E> pageList(Integer start,Integer end); } 实现类 public class EmployeeDao implements IDao<Employee> { public Connection conn = JdbcUtils.getConn(); @Override public List<Employee> findAll() {...} @Override public Employee findById(Integer id) {...} @Override public void deleteById(Integer id) {...} @Override public void update(Employee entity) {...} @Override public List<Employee> pageList(Integer start, Integer end) {...} } 来源: https

pymysql DAO简单封装

倾然丶 夕夏残阳落幕 提交于 2019-12-01 09:52:14
#!/usr/bin/env python # -*-coding:utf-8 -*- # # 无法执行多个query,self.conn.close()放在CdbConn类的单独函数中,每次query之后要手动close;否则多次query,会自动关闭 import pymysql class CdbConn(): def __init__(self, db_host, db_user, db_pwd, db_name, db_port=3306): self.db_host = db_host self.db_port = db_port self.db_user = db_user self.db_pwd = db_pwd self.db_name = db_name self.status = True self.conn = self.getConnection() def getConnection(self): try: conn = pymysql.Connect( host=self.db_host, # 设置MYSQL地址 port=int(self.db_port), # 设置端口号 user=self.db_user, # 设置用户名 passwd=self.db_pwd, # 设置密码 db=self.db_name, # 数据库名 charset=

How to populate DTO class string fields using JPA CriteriaQuery on Entity having enum fields?

断了今生、忘了曾经 提交于 2019-12-01 08:22:55
问题 I'm using JPA Criteria API, and in my query multiselect I want to retrieve an enum attribute, and not the enum itself. This is my query : final CriteriaQuery<MyClassDTO> query = builder.createQuery(MyClassDTO.class); in MyClassDTO I have 4 fields as following: private String icon; private String provenance; private int sizeX; private int sizeY; And the path I'm retrieving data from is : final Root<MyClass> from = query.from(MyClass.class); MyClass has 3 fields : @Column @Enumerated(EnumType

JAVA传统方式访问数据库

◇◆丶佛笑我妖孽 提交于 2019-12-01 07:55:39
使用idea进行操作: 1)创建maven项目 选择maven仓库,选择自己maven安装位置,user settings file为安装maven下conf文件夹内的settings.xml 。 local repository是本地仓库,设置好后点击next 设置项目名称 2)添加依赖 pom.xml下添加依赖包 3)JDBC连接 不建议将配置写入代码中 所以在resources下创建db.properties 此处mysql8.0以上版本的driver为com.mysql.cj.jdbc.Driver。 在测试过程中会报错,因为版本问题,在url中加入?serverTimezone=GMT 创建JDBCUtil工具类 连接需要释放DB资源 4)测试:在Test包下创建JDBCUtilTest类 运行结果: 代表访问数据库成功。 5)创建数据库,插入三条数据 6)Dao层: 创建实体类,调用 set和get方法 创建Dao接口 创建Dao接口实现类 进行测试,在Test包下创建StudentDaoImplTest: 查询到数据,成功。 再添加数据,在接口类中添加: daoimpl中重写方法 进行测试 没有报错,数据库也添加了数据 来源: https://www.cnblogs.com/zchloverh/p/11671024.html

Shiro入门1

◇◆丶佛笑我妖孽 提交于 2019-12-01 07:48:51
1、Shiro是什么? Apache Shiro 是 Java 的一个安全框架。 2.Shiro一些基本概念 3.Shiro结合数据库。 RBAC的概念 Roles base access controll 基于角色的权限控制 或者 Resources base access controll 基于资源的权限控制 通俗来说,你得获得对应的资源或者权限才能够进行访问 表结构 最简单的权限控制,是建立在 “用户” —— ”角色“ —— “权限” 之间的关系。 其中用户和角色之间是多对多关系,角色和权限是多对多关系。 在进行表的设计时,可以考虑在用户、角色、权限三张表的基础上,再建立 用户-角色表,角色-权限表来维护他们之间的关系。 所以,最简单的RBAC需要五张表来实现。 4.编码,通过数据库的设计实现最简单的权限控制 SQL: 1 DROP DATABASE IF EXISTS shiro; 2 CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; 3 USE shiro; 4 5 drop table if exists user; 6 drop table if exists role; 7 drop table if exists permission; 8 drop table if exists user_role; 9

service和Dao层有什么关系

风格不统一 提交于 2019-12-01 07:34:05
Dao层:主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后就可在模块中调用此接口来进行数据业务的处理,而不用关心此接口的具体实现类是哪个类,显得结构非常清晰,DAO层的数据源配置。 dao层代码示例: service层:主要负责业务模块的逻辑应用设计,Service层的业务实现,具体要调用到已定义的DAO层的接口,封装Service层的业务逻辑有利于通用的业务逻辑的独立性和重复利用性,程序显得非常简洁。 service层代码示例: dao层和service层关系: service层经常要调用dao层的方法对数据进行增删改查的操作,现实开发中,对业务的操作会涉及到数据的操作,而对数据操作常常要用到数据库,所以service层会经常调用dao层的方法。 扩展资料 Service层是建立在DAO层之上的,建立了DAO层后才可以建立Service层 , 而Service层又是在Controller层之下的 , 因而Service层应该既调用DAO层的接口,它刚好处于一个中间层的位置 。每个模型都有一个Service接口,每个接口分别封装各自的业务处理方法。 在实际开发中DAO层大多是对某张表进行增删改查,都是一些固定的语句 ,除非涉及到更复杂的service层业务逻辑,才可能要添加更复杂的DAO层方法。 来源: https:/