`
doctang
  • 浏览: 4443 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

ExampleDAO

 
阅读更多
package com.foxconn.nwe.flex.ejb.dao.engineering;

import java.util.List;

import com.foxconn.nwe.flex.ejb.model.engineering.Example;

public interface ExampleDAO {
public Example find(int id);

public boolean insert(Example example);

public boolean update(Example example);

public boolean delete(int id);

public List<Example> list(String nweBU, String type, String subType,
String subject, String correlate, int start, int limit);

public long sum(String nweBU, String type, String subType);

public long sum(String subject, String correlate);
}

package com.foxconn.nwe.flex.ejb.dao.engineering.jpa;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.foxconn.nwe.flex.ejb.dao.engineering.ExampleDAO;
import com.foxconn.nwe.flex.ejb.model.engineering.Example;

@Stateless
@Remote({ExampleDAO.class})
public class ExampleDAOBean implements ExampleDAO {

@PersistenceContext(unitName = "Oracle104PU")
private EntityManager em;

public boolean delete(int id) {
Example example = this.find(id);

if (example == null) {
return false;
} else {
try {
em.remove(example);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

return true;
}

public Example find(int id) {
return em.find(Example.class, id);
}

public boolean insert(Example example) {
if (example == null) {
return false;
} else {
try {
em.persist(example);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

return true;
}

@SuppressWarnings("unchecked")
public List<Example> list(String nweBU, String type, String subType,
String subject, String correlate, int start, int limit) {
String jpql = "select e from Example e where (e.nweBU=?1 and e.type=?2 and e.subType=?3) or (e.subject like '%"
+ subject
+ "%' and e.correlate like '%"
+ correlate
+ "%') order by e.recordDate desc";

Query query = em.createQuery(jpql);

query.setParameter(1, nweBU);
query.setParameter(2, type);
query.setParameter(3, subType);

query.setFirstResult(start);
query.setMaxResults(limit);

return query.getResultList();
}

public long sum(String nweBU, String type, String subType) {
String jpql = "select count(e) from Example e where e.nweBU=?1 and e.type=?2 and e.subType=?3";

Query query = em.createQuery(jpql);

query.setParameter(1, nweBU);
query.setParameter(2, type);
query.setParameter(3, subType);

return (Long) query.getSingleResult();
}

public long sum(String subject, String correlate) {
String jpql = "select count(e) from Example e where e.subject like '%"
+ subject + "%' and e.correlate like '%" + subject + "%'";

Query query = em.createQuery(jpql);

return (Long) query.getSingleResult();
}

public boolean update(Example example) {
if (example == null) {
return false;
} else {
try {
em.merge(example);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

return true;
}

}
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    spring+hibernate的配置

    public ExampleDao exampleDao() { return new ExampleDao(sessionFactory); } } ``` **六、编写业务逻辑** 6. 创建servlet或控制器类,使用Spring的ApplicationContext来获取DAO Bean,进行数据库操作。例如:...

    springdemo

    &lt;property name="exampleDao" ref="exampleDao"/&gt; ``` 这表示Spring会创建一个名为`exampleService`的Bean,其类型为`ExampleServiceImpl`,并将`exampleDao`属性注入。 五、Spring MVC与Controller 在Web开发中...

    flex-ibatis-sping项目的创建

    &lt;property name="exampleDao" ref="exampleDao"/&gt; &lt;bean id="exampleDao" class="com.example.ExampleDao"&gt; &lt;!-- 数据库连接配置 --&gt; &lt;!-- 更多Bean的定义 --&gt; ``` 通过以上步骤,我们成功地创建了一个...

    struct+spring+Hibernate框架整合文档

    &lt;property name="exampleDao" ref="exampleDao"/&gt; &lt;bean id="exampleDao" class="com.example.ExampleDao"&gt; ``` 2. **事务管理**:使用Spring的`PlatformTransactionManager`进行事务控制,通常选择...

    SSH整合方式一:无障碍整合

    &lt;property name="exampleDao" ref="exampleDao"/&gt; &lt;bean id="exampleDao" class="com.example.ExampleDaoImpl"&gt; ``` 4. **Hibernate配置**:配置hibernate.cfg.xml文件,设置数据库连接信息,以及实体类的...

    ssh整合配置(struts2.2.1+ hibernate3.6+spring3.0.5)

    &lt;property name="exampleDao" ref="exampleDao"/&gt; ``` 5. **整合步骤**: - 在Struts2的Action中通过Spring的@Autowired注解注入Service,Service再注入DAO,实现业务逻辑。 - 使用Spring的...

    框架说明.docx

    4. 如果表名是 example,对应的 model 名是 Example,DAO 是 ExampleDAO,Service 是 ExampleService,后台管理的控制层是 AdminExampleDAO。 五、开发步骤 以开发一个 example 模块为例: 1. 在数据库中创建一张...

    Spring 2.x配置详解

    private ExampleDao exampleDao; } ``` 在上述示例中,`@Service` 注解用于标记 `ExampleService` 类为服务层组件,而 `@Autowired` 注解则负责自动装配 `ExampleDao` 对象。 #### 实用技巧及其他 在使用 Spring...

    人人网jade开发指南

    - `ExampleDAO`接口定义了三个方法,分别对应插入、查询单个记录以及查询多个记录的操作。 - 方法中的`@SQL`注解包含了对应的SQL语句,通过参数占位符的方式与方法参数进行绑定。 #### 五、读写操作的区别 - **读...

    myeclipse搭建ssh并实现增删改查

    接下来编写DAO接口和实现类,例如ExampleDao.java和ExampleDaoImpl.java,以及Service接口和实现类,例如ExampleService.java和ExampleServiceImpl.java。这些类会分别处理数据库的CRUD操作和业务逻辑。 Action类...

    S2SH框架配置步骤

    &lt;bean id="exampleDao" class="com.example.ExampleDaoImpl"&gt; ``` - 配置数据源和SessionFactory:根据Hibernate配置来创建数据源和SessionFactory Bean。 6. **配置Hibernate** - 添加Hibernate库:将...

    fiware-commons:FIWARE 项目的软件部署和配置以及 PaaS 管理器实现的公共库

    public interface ExampleDao extends BaseDAO&lt;Example&gt; { // Add here some additional methods only if needed List&lt;Example&gt; findByCriteria(ExampleSearchCriteria criteria); } 如果您想使用基于 JPA 的实

    PHP中使用匿名函数操作数据库的例子

    `ExampleDao`类继承自`BaseDao`类,它使用`getList`方法获取所有的`Example`对象,并通过回调函数将结果集转换为`Example`对象的列表。 需要注意的是,示例中使用了旧的`mysql_*`系列函数,这些函数在PHP 7.0及以上...

Global site tag (gtag.js) - Google Analytics