- 浏览: 420655 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (269)
- 原创 (7)
- Java (51)
- Java Concurrency (2)
- IDE (16)
- Linux (46)
- Database (23)
- NoSQL (35)
- Web服务器 (23)
- Log日志 (11)
- HTTP (11)
- HTML (2)
- XML (1)
- Test (7)
- Mina (0)
- Amoeba (4)
- Cobar (1)
- 序列化 (2)
- Python (5)
- PHP (1)
- Socket通信 (1)
- Network (3)
- Struts (2)
- Web前端 (10)
- Maven (6)
- SVN (15)
- Json (1)
- XMPP (2)
- Go (1)
- Other (4)
- 未整理 (5)
最新评论
-
u012374672:
[color=darkred][/color][flash=2 ...
Mongo的ORM框架的学习Morphia(annotations) -
b_l_east:
很有问题啊
利用redis的transaction功能,实现分布式下加锁
转自 http://topmanopensource.iteye.com/blog/1439448
package com.easyway.mongodb.morphia.basic; import java.net.UnknownHostException; import com.google.code.morphia.Datastore; import com.google.code.morphia.Morphia; import com.google.code.morphia.query.Query; import com.google.code.morphia.query.UpdateOperations; import com.mongodb.DB; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * * @Title: TODO * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company:易程科技股份有限公司 * @Date:2012-3-2 * @author * @version 1.0 */ public class MorphiaHotelApp { // main // public static void main(String[] args) { try { Mongo m = new Mongo("localhost"); DB db = m.getDB("morphia_test"); Morphia morphia = new Morphia(); //设置映射累的类 morphia.map(Hotel.class) .map(Address.class) .map(TwiceKey.class) .map(RecursiveChild.class) .map(RecursiveParent.class); //创建一个Datastore对象 Datastore ds = morphia.createDatastore(m, "morphia_test"); Hotel hotel =Hotel.create(); hotel.setName("My Hotel123"); // hotel.setId(new ObjectId("4ea510c8b24d395248f1f97f")); hotel.setStars(90); Address address = new Address(); address.setStreet("123 Some street"); address.setCity("Some city"); address.setPostCode("123 456"); address.setCountry("2Some country"); // set address hotel.setAddress(address); hotel.getPhoneNumbers().add(new PhoneNumber(86,21,PhoneNumber.Type.PHONE)); hotel.getPhoneNumbers().add(new PhoneNumber(80,2,PhoneNumber.Type.FAX)); //保存 ds.save(hotel); //查询信息 Query q = ds.createQuery(Hotel.class).disableValidation() .disableValidation(); System.out.println(q.filter("id =", "4eb79c8cba4d913746120ae9").asList()); //根据条件删除 ds.delete(q); ds.save(hotel); //条件修改 UpdateOperations<Hotel> ops = ds.createUpdateOperations( Hotel.class).set("name", "New Name1"); ds.update(q, ops); RecursiveChild child=new RecursiveChild(); child.setName("longgangbai"); child.setPayforType(PayforType.network); ds.save(child); RecursiveChild tchild=ds.createQuery(RecursiveChild.class).filter("name =", "longgangbai").get(); RecursiveParent temp=new RecursiveParent(); temp.setChild(child); temp.setPayforType(PayforType.cash); ds.save(temp); TwiceKey key=new TwiceKey(); ds.save(key); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MongoException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
备注:
采用的Morphia的版本为morphia-0.99.1-SNAPSHOT.jar,mongo驱动版本为mongo-java-driver-2.7.0.jar。
本文写一个简单的实例:
package com.easyway.mongodb.morphia.basic; import com.google.code.morphia.annotations.Embedded; /** * * @Title: TODO * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company:易程科技股份有限公司 * @Date:2012-3-2 * @author * @version 1.0 */ @Embedded public class Address { private String street; private String city; private String postCode; private String country; private String state; private String zipcode; public String getState() { return state; } public void setState(String state) { this.state = state; } public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getPostCode() { return postCode; } public void setPostCode(String postCode) { this.postCode = postCode; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } }
package com.easyway.mongodb.morphia.basic; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Vector; import org.bson.types.ObjectId; import com.google.code.morphia.annotations.Embedded; import com.google.code.morphia.annotations.Entity; import com.google.code.morphia.annotations.Id; import com.google.code.morphia.annotations.Transient; /** * 利用 Morphia 可以使用Mongo DB,集成到项目 的DAO *里面。最小成本地使用Nosql技术,满足实际的项目需求。 * * @Description: * @Copyright:Copyright (c) 2011 * @Company:易程科技股份有限公司 * @Date:2012-2-28 * @author * @version 1.0 */ @Entity(value="hotels",noClassnameStored=true) public class Hotel { private static final long serialVersionUID = 1L; public static Hotel create() { return new Hotel(); } public enum Type { BUSINESS, LEISURE } private String name; private Date startDate; private int stars; private boolean takesCreditCards; private Type type; private Set<String> tags; @Transient private String temp; @Embedded private Address address; @Embedded(concreteClass = java.util.Vector.class) private List<PhoneNumber> phoneNumbers; private Hotel() { super(); tags = new HashSet<String>(); phoneNumbers = new Vector<PhoneNumber>(); } /** The id for this instance */ @Id protected String id = new ObjectId().toString(); public String getId() { return id; } public void setId(String id) { this.id = id; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getStars() { return stars; } public void setStars(int stars) { this.stars = stars; } public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } public boolean isTakesCreditCards() { return takesCreditCards; } public void setTakesCreditCards(boolean takesCreditCards) { this.takesCreditCards = takesCreditCards; } public Type getType() { return type; } public void setType(Type type) { this.type = type; } public Set<String> getTags() { return tags; } public void setTags(Set<String> tags) { this.tags = tags; } public List<PhoneNumber> getPhoneNumbers() { return phoneNumbers; } public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) { this.phoneNumbers = phoneNumbers; } public String getTemp() { return temp; } public void setTemp(String temp) { this.temp = temp; } }
package com.easyway.mongodb.morphia.basic; public enum PayforType { network(0,"网络支付"),cash(1,"现金支付"); private int code; private String desc; private PayforType(int code,String name){ this.code=code; this.desc=name; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } }
package com.easyway.mongodb.morphia.basic; import com.google.code.morphia.annotations.Embedded; import com.google.code.morphia.annotations.Property; /** * Morphia支持枚举值的使用 * * @Description: * @Copyright:Copyright (c) 2011 * @Company:易程科技股份有限公司 * @Date:2012-3-2 * @author * @version 1.0 */ @Embedded public class PhoneNumber { public enum Type { PHONE, FAX } @Property private int countryCode; @Property private int localExtension; @Property private Type type; public PhoneNumber() { this.type = Type.PHONE; } public PhoneNumber( int countryCode, int localExtension, Type type ) { this.countryCode = countryCode; this.localExtension = localExtension; this.type = type; } public int getCountryCode() { return countryCode; } public void setCountryCode(int countryCode) { this.countryCode = countryCode; } public int getLocalExtension() { return localExtension; } public void setLocalExtension(int localExtension) { this.localExtension = localExtension; } public Type getType() { return type; } public void setType(Type type) { this.type = type; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final PhoneNumber other = (PhoneNumber) obj; if (this.countryCode != other.countryCode) { return false; } if (this.localExtension != other.localExtension) { return false; } if (this.type != other.type) { return false; } return true; } @Override public int hashCode() { int hash = 5; hash = 43 * hash + this.countryCode; hash = 43 * hash + this.localExtension; hash = 43 * hash + this.type.hashCode(); return hash; } }
package com.easyway.mongodb.morphia.basic; import org.bson.types.ObjectId; import com.google.code.morphia.annotations.Entity; import com.google.code.morphia.annotations.Id; import com.google.code.morphia.annotations.Reference; @Entity public class RecursiveChild { private static final long serialVersionUID = 1L; /** The id for this instance */ @Id protected String id = new ObjectId().toString(); private PayforType payforType; private String name; @Reference private RecursiveParent parent; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public PayforType getPayforType() { return payforType; } public void setPayforType(PayforType payforType) { this.payforType = payforType; }
package com.easyway.mongodb.morphia.basic; import org.bson.types.ObjectId; import com.google.code.morphia.annotations.Entity; import com.google.code.morphia.annotations.Id; import com.google.code.morphia.annotations.Reference; @Entity public class RecursiveParent { private static final long serialVersionUID = 1L; private PayforType payforType; @Reference private RecursiveChild child; /** The id for this instance */ @Id protected String id = new ObjectId().toString(); public String getId() { return id; } public PayforType getPayforType() { return payforType; } public void setPayforType(PayforType payforType) { this.payforType = payforType; } public void setId(String id) { this.id = id; } public RecursiveParent() { super(); } public RecursiveChild getChild() { return child; } public void setChild(RecursiveChild child) { this.child = child; } }
发表评论
-
mongodb 地理位置处理
2016-05-16 13:39 1387我只记录我用到的部分,没有完整分析mongodb对地理位置 ... -
Redis配置文件redis.conf
2014-11-14 14:10 1839# Redis configuration file ex ... -
Redis高可用部署及监控
2014-11-12 13:25 1075一、 Re ... -
JCS官方文档的简单笔记,仅供自己参考
2014-09-26 20:08 7491. 基本配置 jcs.default=DCjcs.de ... -
JCS基本配置
2014-09-26 19:39 9171、默认的内存缓存 ... -
NoSQL解决方案比较(MongoDB vs Redis, Tokyo Cabinet, and Berkeley DB)
2013-09-30 14:20 1312NoSQL解决方案比较 NoSQL Solution: E ... -
morphia与spring的整合
2012-12-07 15:06 1458转自: http://www.blogjava.net/wat ... -
Mongo的ORM框架的学习Morphia(十五)Morphia+spring整合
2012-12-07 15:06 1627转自:http://topmanopensource.itey ... -
Mongo的ORM框架的学习Morphia(十二) morphia的Query和Update
2012-12-07 15:06 1837转自:http://topmanopensource.itey ... -
Mongo的ORM框架的学习Morphia(十) morphia应用
2012-12-05 14:47 1433转自:http://topmanopensource.itey ... -
Mongo的ORM框架的学习Morphia(八) morphia数据库访问接口
2012-12-05 14:35 1991转自:http://topmanopensource.itey ... -
Mongo的ORM框架的学习Morphia(annotations)
2012-12-05 14:33 2503一:@Entity的使用 @Entity ... -
Instagram的Redis实践(内存占用优化)
2012-11-30 10:43 1171转自:http://blog.nosqlfan.com/htm ... -
SQL 和Mongo 对比图表
2012-11-28 14:54 2180参看官方说明: http://www.mongodb ... -
MongoDB 入门指南、示例
2012-11-23 10:38 827转自:http://www.cnblogs.com/hoojo ... -
mongodb中使用MapReduce
2012-11-23 10:12 1189MapReduce函数的用法如下: db.users.ma ... -
python的redis用法
2012-11-22 15:48 1140#! /usr/bin/env python #coding ... -
Python连接redis
2012-11-22 15:46 5581一、Redis是流行的NOSQL内存数据库,以Key-Valu ... -
【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
2012-08-29 10:42 1345转自 http://www.bwkeji.com/a/wang ... -
利用redis的transaction功能,实现分布式下加锁
2012-08-29 09:57 2346package memcached; import ja ...
相关推荐
Mongo的ORM框架的学习Morphia
mongo-2.7.3.jar和morphia-0.99.jar
spring MVC morphia mongo 整合的例子 网上下载的例子 自己调试保证绝对能运行
这个压缩文件包含mongo-2.7.3.jar和morphia-0.99.jar是morphia框架必须的jar
java mongodb orm 实现-基于mongodb-driver开发的ORM
spring-mongodb-morphia springdata-mongo morphia mongodb 学习
MongoModel - Ruby ODM用于与MongoDB数据库交互
讲解mongo中使用框架实现模糊查找,Mongo的高级查询功能
这个应用程序的起点是它是一个可配置的框架,使工作变得简单和可定制。 Next 和将用于比较所有这些非常酷的框架。 该项目主要使用java,但也贯穿始终使用Scala。 播放框架 (2.3.8) PlayAuthenticate (0.6.8) ...
morphia mongo db OR-mapping mongo db再带的CRUD 太麻烦了, 一个不错的框架 类似 Hibernate
总结了mongo数据库的映射框架morphia的基本用法。包括查询,更新等,是一份不错的mongodb操作入门文档。
使用MyBatisPlus的方式,优雅的操作MongoDB,可和现有Mongo框架结合使用,无侵入性 简化开发, 只需简单配置,即可快速进行CRUD操作,链式调用更加便捷。只做增强不做改变,引入它不会对现有工程产生影响,如丝般...
使用TF和ycsb构建mongo测试框架 准备 配置AWS凭证 安装terraform(0.14.9+) Visual Studio代码(首选) 设置 签出源代码后,在根目录中运行terraform init命令。 计划 初始化成功后,运行计划与terraform plan 。...
Mongo是一个高性能,开源,无模式的文档型数据库,它在许多场景下可用于替代传统的关系型数据库或键/值存储方式。Mongo使用C++开发,提供了以下功能:
lucid-mongo, 面向adonis框架的Mongodb ODM 清晰 Mongolucid是mongo查询生成器和 ORM 。 它还支持数据库迁移,种子和工厂作为 @adonis/lucid.
bugu-mongo1.12 mongo开源框架
MongoVUE简单操作手册,里面有增删查改的一些基本操作,对MONGO的一些学习者有一定帮助。
在线文档WORD版详细文档(完整)请见:docs /睿智平台SqlToy4.17使用手册.doc范例演示项目快速上手主要功能项目阅读其readme.md学习POJO和DTO严格分层演示项目分片分库分表演示nosql演示(mongo和elasticsearch) ...
CI框架的mongo_db数据库扩展链接文件,有了它,CI框架链接mongo_db不在烦恼!
此项目的功能是爬取用户信息以及人际拓扑关系,爬虫框架使用scrapy,数据存储使用mongo,下载这些数据感觉也没什么用,就当为大家学习scrapy提供一个例子吧。 使用方法 本地运行 爬虫程序依赖mongo和rabbitmq,因此...