dao

Calling one DAO from another DAO?

心已入冬 提交于 2019-11-30 10:20:14
Can this ever make sense? Say I need to fetch an object from the DB which has a relation to another object (represented by a foreign key in the DB, and by a composition in my domain object). If in my first DAO I fetch the data for object 1, then call the dao for object 2, and finally (from within the first DAO, call the setter in object 1 and give it the previously fetched object 2). I know I could do a join instead, but it just seems more logical to me to decouple the functionality (which is why I am skeptical about calling one dao from another). Or should I move some of the logic to the

Standard Naming Convention for DAO Methods

假如想象 提交于 2019-11-30 09:15:15
Is there a standard naming convention for DAO methods, similar to JavaBeans? For example, one naming convention I've seen is to use get() to return a single entity and find() to return a List of entities. If there isn't one, what's the one your team is using and why? Usually I name the methods in such way that the name hints the type of the CRUD operation that will be applied by the method, like add* , save* or find* . add* can be applied on INSERT operations, like addPhoneNumber(Long userId) . get* can be applied for SELECT operations, like getEmailAddress(Long userId) . set* can be applied

JPA @Version: how to use it?

时间秒杀一切 提交于 2019-11-30 08:42:00
@Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version private long version; // ...getters and setters } Is it required to create setter/getter for version ? When persisting this entity with Hibernate, I don't need to set this value manually, right? What else do I need to configure in order to use optimistic concurrency checking with Spring's hibernateTemplate.saveOrUpdate ? Are all databases supported? How to unit-test this entity? In my database all my records showing version field have value of 0 Will calling

Using Static methods or none static methods in Dao Class?

末鹿安然 提交于 2019-11-30 08:36:27
Hi I generate Dao classes for some DB operations in this manner making methods of Dao class as static or none static is better? Using sample dao class below ,İf more than one client got to use the AddSampleItem method in same time?how this may result? public class SampleDao { static DataAcessor dataAcessor public static void AddSampleItem(object[] params) { dataAcessor =new DataAcessor(); //generate query here string query="..." dataAcessor.ExecuteQery(query); dataAcessor.Close(); } public static void UpdateSampleItem(object[] params) { dataAcessor =new DataAcessor(); //generate query here

Ormlite DAO in android getting really slow when querying more than few thousand results

风格不统一 提交于 2019-11-30 07:51:36
问题 Have a problem with querying data via Ormlite DAO, when there are few thousand results. Code: List<Point> pl = db.getPointsDAO().queryBuilder().where(). eq("route_id", croute).query(); When I want to get a large list of points List<Point> pl for current Route croute I have to wait like 40 sec for 40.000 points. where Point.class is: @DatabaseTable(tableName = "points") public class Point extends BaseEntity { @DatabaseField(generatedId = true) private Integer point_id; @DatabaseField(canBeNull

一个android sqlite CRUD代码生成小工具

…衆ロ難τιáo~ 提交于 2019-11-30 07:44:03
把之前的文章合并到这里,添加bulk批量操作函数. 源码已开源 sqliteGenCRUD 。 android sqlite也无非是CRUD,所以通常是Ctrl+C、Ctrl+V,不过拷贝的代码容易出错浪费不少苦逼的时间。android sqlite的ORM的开源项目现在也有不少,不过对于一个嵌入式程序除了性能也需要考虑包的大小,所以ORM在嵌入式来说起码现在还不适合时机。 这个小工具功能很简单,不添加任何外部引用,使用方式直接运行按提示做即可^_^。 具体功能:通过输入create table语句生成表CRUD类、实体类(可选)。 由于sqlite解析器没有解析check约束,所以create table语句也不支持check约束。 sqlite和java类型映射关系(需要注意的是sqlite 实际 只支持5中数据类型,详情见 链接 ) sqlite java int、integer int short、byte、boolean、bool short long、number long text、varchar、char 、nvarchar 、string String float float real、double double blob byte[] 现在控制带输入sqlite create table语句就可以了 生成的CRUD代码大概是这样的 import java

MS Access Batch Update via ADO.Net and COM Interoperability

一世执手 提交于 2019-11-30 07:26:35
This is kind of a follow-up to this thread . This is all with .Net 2.0 ; for me, at least. Essentially, Marc (OP from above) tried several different approaches to update an MS Access table with 100,000 records and found that using a DAO connection was roughly 10 - 30x faster than using ADO.Net. I went down virtually the same path (examples below) and came to the same conclusion. I guess I'm just trying to understand why OleDB and ODBC are so much slower and I'd love to hear if anyone has found a better answer than DAO since that post in 2011. I would really prefer to avoid DAO and/or

Getting fewer columns with hibernate

别来无恙 提交于 2019-11-30 05:28:54
问题 I have a table with 11 columns, but I need to get only 2 of them in my application, I'm using spring/hibernate/DAO combination. For now I have a domain class which includes all 11 fields, and mapping file which maps all 11 columns in table. How do I use get just 2 of them not all? 回答1: Either: Use projections - Pro: nothing to add - Con: Not typesafe (the result is a List of rows where each row is an Object[]) : select f.foo, f.bar from FatEntity f Use a constructor expression in the SELECT

Unit testing a DAO class that uses Spring JDBC

微笑、不失礼 提交于 2019-11-30 03:45:12
I have several DAO objects that are used to retrieve information from a database and I really want to write some automated tests for them but I'm having a hard time figuring out how to do it. I'm using Spring's JdbcTemplate to run the actual query (via a prepared statement) and map the results to the model object (via the RowMapper class). If I were to write unit tests, I'm not sure how I would/should mock the objects. For example, since there are only reads, I would use the actual database connection and not mock the jdbcTemplate, but I'm not sure that's right. Here's the (simplified) code

spring-boot项目MapperScan注解包含多个包

耗尽温柔 提交于 2019-11-30 03:21:40
单个包 @MapperScan("com.mysiteforme.admin.dao")多个包 @MapperScan({"com.mysiteforme.admin.dao","com.zipon.tpf.dao"}) 原文地址:https://www.cnblogs.com/zipon/p/9545590.html 单个包 @MapperScan("com.mysiteforme.admin.dao")多个包 @MapperScan({"com.mysiteforme.admin.dao","com.zipon.tpf.dao"}) 原文地址:https://www.cnblogs.com/zipon/p/9545590.html 来源: https://www.cnblogs.com/jpfss/p/11550625.html