dao

dao 包中的Dao层方法

匿名 (未验证) 提交于 2019-12-02 23:05:13
public class Dao { //写数据库记得在清单文件中写读写权限 private final OpenHelper helper; private final SQLiteDatabase database; public Dao(Context context){ helper = new OpenHelper(context); database = helper.getWritableDatabase(); } public long add(Bean.DataBean bean){ ContentValues values = new ContentValues(); values.put("news_id",bean.getNews_id()); values.put("news_title",bean.getNews_title()); values.put("news_summary",bean.getNews_summary()); values.put("pic_url",bean.getPic_url()); long insert = database.insert("user", null, values); return insert; } //查询 public List<Bean.DataBean> queryAll(){ Cursor

Class derived from generic class don't get the correct type

杀马特。学长 韩版系。学妹 提交于 2019-12-02 22:22:29
问题 In my spring project, I have this template for my Dao classes: public class Dao<E> { private final E entity; @Autowired SessionFactory sessionFactory; protected Session getCurrentSession(){ return sessionFactory.getCurrentSession(); } public Dao(E entity) { this.entity = entity; } public Dao(Class<?> classe) { this.entity = (E) classe; } public E getEntity() { return this.entity; } @Transactional public boolean persist(E transientInstance) { sessionFactory.getCurrentSession().persist

handling GWT RequestFactory server error responses

那年仲夏 提交于 2019-12-02 22:12:30
I have a newly coded GWT/GAE app that uses RequestFactory and Editors on the client and a custom Objectify DAO Service on the back. The flush() then persist() paths work fine on success. Client side JSR 303 works as well as can be expected too. My question is how to trigger server warnings/errors and handle UI updates? I am using Chandler's Generic DAO for Objectify 2 at http://turbomanage.wordpress.com/2010/02/09/generic-dao-for-objectify-2/ my gwt activity is calling persist( myProxy ).fire( new Receiver<> ) my dao code is throwing IllegalArgumentException and other RuntimeExceptions for

pymysql DAO简单封装

匿名 (未验证) 提交于 2019-12-02 22:06:11
#!/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 =

Spring MVC: Generic DAO and Service classes

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 21:13:14
I am writting web in Spring MVC. I wrote all DAOs using Generic DAO. Now I would like to rewrite my Service classes. How can I write "Generic Service"? There are my DAOs: /* ################################# DAO ################################ */ package net.example.com.dao; import java.util.List; public interface GenericDao<T> { public T findById(int id); public List<T> findAll(); public void update(T entity); public void save(T entity); public void delete(T entity); } /* ------------------------------------------------------ */ package net.example.com.dao; import java.io.Serializable;

DAO generator for java [closed]

送分小仙女□ 提交于 2019-12-02 21:07:17
I'm searching for free and simple DAO generator for java (it needs to create entities/bens from db tables/views and generate basic CRUD code). Currently, I`m using DAO4J which lacks some functionality like views mapping. I know that there are frameworks like Hibernate but I dont need such robust framework. Some things this framework should have to do: Generate CRUD operations with standard SQL queries and not compile-time typesafe queries Doesn't have session concept like hibernate Will not automatically close connection JDBC Connection can be configured through code None of these are perfect

Generic DAO pattern in Hibernate

浪尽此生 提交于 2019-12-02 19:51:56
While working on hibernate we are following generic Hibernate DAO pattern as mentioned in Hibernate Doc also. So as per this we are currently maintaining two parallel hirarchies 1) for interfaces 2) for Implimentation so if we work on this the way even if there is no proposed new method beside standard persistannce methods we need to create a marker interface for that entiry as well its Implimentation. Though there seems no problem in this approach and its clear seperation. my question is if there any better way/alternate way to achieve this Thanks in advance Arthur Ronald Umesh I will show

How unit test insert record in spring (no delete method)

為{幸葍}努か 提交于 2019-12-02 18:26:11
问题 I have DAO using Spring's jdbcTemplate with Create Read Update (no Delete) operation. Create method have ID parameter which is unique key in table. Except mocking DAO, how can I actually test create without getting constraint violation? Using random ID still can fail sometimes Should I override setAutoCommit to avoid adding record? is it still consider a valid unit test? Must I delete in SQL the record in database beforehand or is there spring option for this types of tests? Or should I

Spring session-scoped beans as dependencies in prototype beans?

无人久伴 提交于 2019-12-02 17:43:58
I read spring docs on this subject several times, but some things are still unclear to me. Documentation states: If you want to inject (for example) an HTTP request scoped bean into another bean, you must inject an AOP proxy in place of the scoped bean. That is, you need to inject a proxy object that exposes the same public interface as the scoped object but that can also retrieve the real, target object from the relevant scope (for example, an HTTP request) and delegate method calls onto the real object. Config example is as follows: <bean id="userPreferences" class="com.foo.UserPreferences"

How to test DAO methods using Mockito?

半腔热情 提交于 2019-12-02 17:09:21
I've started to discovered Mockito library and there is a question for which I didn't find the proper answer. If I have for example such method in my UserDAO class that saves user in database: public class UserDAO{ ... public void create(User user) { Connection connection = null; PreparedStatement pstmt = null; ResultSet generatedKeys = null; try { connection = getConnection(); pstmt = connection.prepareStatement(INSERT_USER, PreparedStatement.RETURN_GENERATED_KEYS); int counter = 1; pstmt.setString(counter++, user.getFirstName()); pstmt.setString(counter++, user.getLastName()); pstmt