12
返回列表 发新帖
楼主: jieforest

How to teach a JavaEE app new NoSQL tricks

[复制链接]
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
11#
 楼主| 发表于 2013-4-1 16:35 | 只看该作者
Derby repository calls
@Inject
EntityManager em;
find : TypedQuery<Category> typedQuery = em.createNamedQuery(Category.FIND_BY_NAME, Category.class);
typedQuery.setParameter("pname", categoryName);
save : em.persist(category);
update : em.merge(category);
delete : em.remove(em.merge(category));
Couchbase repository calls
find : client.get(categoryName);
save : client.set(category.getName(), EXP_TIME, mapper.writeValueAsString(category));
update : client.replace(category.getName(), EXP_TIME, mapper.writeValueAsString(category));
delete : client.delete(category.getName());

Code changes were required for each of the CRUD operations for Customers, Orders, and Categories. Below is an example of the changes made to create a new customer.

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
12#
 楼主| 发表于 2013-4-1 16:35 | 只看该作者
The original code for customer creation
public Customer createCustomer(final Customer customer) {
if (customer == null) throw new ValidationException("Customer object is null");
em.persist(customer);
return customer;
}
The Couchbase code for customer creation
public Customer createCustomer(final Customer customer) {

if (customer == null) throw new ValidationException("Customer object is null");

// Sets the customerId to the current time in millis
customer.setId(String.valueOf(new Date().getTime()));
try {
// Puts the document into the database.
// Uses customer login as the key since this should be unique
// EXP_TIME, Expiry time in seconds is set to 0, which means store forever.
// Uses the Jackson mapper to conver the customer to json
client.set(customer.getLogin(), EXP_TIME, mapper.writeValueAsString(customer));
} catch (Exception ex) {
ex.printStackTrace();
}
return customer;
}

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
13#
 楼主| 发表于 2013-4-2 10:35 | 只看该作者
Our experience in switching this J2EE application from Apache Derby, JPA, and Hibernate to Couchbase demonstrated that the switch was fairly simple. The most difficult part was designing the schema, which is an issue when switching any application from an RDBMS to a NoSQL database. Still, designing a document database schema is generally easier than designing a relational database schema.

With the design behind us, it was simply a matter of switching the service classes to use the Couchbase client. Although this is a small application, implementing the Couchbase version was relatively easy and quick, which bodes well for other existing Java EE applications' ability to take advantage of NoSQL.

Michael Brush, Elizabeth Edmiston, and Deep Mistry, who are all developers at Open Software Integrators, contributed to this article.

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
14#
 楼主| 发表于 2013-4-2 10:35 | 只看该作者
over.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表