db4o Storing/Retrieving/Updating/Deleting structured objects
来源:互联网 发布:mysql不允许远程连接 编辑:程序博客网 时间:2024/04/29 15:38
Pilot { string name; int point; }
Car { string model; Pilot pilot; }
// storeFirstCar
Car car1=new Car("Ferrari");
Pilot pilot1=new Pilot("Michael Schumacher",100);
car1.setPilot(pilot1);//保存Car时,默认也保存Pilot了
db.set(car1);
///////////////////////////////////////////////////////////////////////////////
// retrieveCarByPilotQBE
Pilot pilotproto=new Pilot("Rubens Barrichello",0);
Car carproto=new Car(null);
carproto.setPilot(pilotproto);
ObjectSet result=db.get(carproto);
listResult(result);
// retrieveCarsByPilotNameNative
final String pilotName = "Rubens Barrichello";
ObjectSet results = db.query(new Predicate() {
public boolean match(Car car){
return car.getPilot().getName().equals(pilotName);
}
});
listResult(results);
// retrieveCarByPilotNameQuery
Query query=db.query();
query.constrain(Car.class);
query.descend("pilot").descend("name")
.constrain("Rubens Barrichello");
ObjectSet result=query.execute();
listResult(result);
// retrieveCarByPilotProtoQuery
Query query=db.query();
query.constrain(Car.class);
Pilot proto=new Pilot("Rubens Barrichello",0);
query.descend("pilot").constrain(proto);
ObjectSet result=query.execute();
listResult(result);
//////////////////////////////////////////////////////////////////////////////////
更新Car时,需要注意的地方
// updatePilotSeparateSessionsImprovedPart1
Db4o.configure().objectClass("com.db4o.f1.chapter2.Car")
.cascadeOnUpdate(true);//修改更新级联为真
// updatePilotSeparateSessionsImprovedPart2
ObjectSet result=db.query(new Predicate() {
public boolean match(Car car){
return car.getModel().equals("Ferrari");
}
});
Car found=(Car)result.next();
found.getPilot().addPoints(1);
db.set(found);//更新Pilot的分数
// updatePilotSeparateSessionsImprovedPart3
ObjectSet result=db.query(new Predicate() {
public boolean match(Car car){
return car.getModel().equals("Ferrari");
}
});
listResult(result);
///////////////////////////////////////////////////////////////////////////////
//删除要注意的地方
// deleteDeepPart1
Db4o.configure().objectClass("com.db4o.f1.chapter2.Car")
.cascadeOnDelete(true);//设置删除级联为真
// deleteDeepPart2
ObjectSet result=db.query(new Predicate() {
public boolean match(Car car){
return car.getModel().equals("BMW");
}
});
Car found=(Car)result.next();
db.delete(found);//删除Car以后,Pilot也被删除了
result=db.query(new Predicate() {
public boolean match(Car car){
return true;
}
});
listResult(result);
- db4o Storing/Retrieving/Updating/Deleting structured objects
- Deleting JPA Entity Objects
- Storing nested objects in Redis
- Storing Java objects in MySQL blobs
- handlersocket使用 第五章 Updating/Deleting data
- ORACLE 触发器 INSRETING,UPDATING,DELETING 函数
- 获取类对象(Retrieving Class Objects)
- Making and storing references to game objects (entities) in C++ and Lua
- db4o 记
- db4o 参考资料
- 深入db4o
- Deleting Logs
- Deleting Clients
- ZOJ_3643Keep Deleting
- Storing floating point numbers
- Storing data in browser
- TLS thread local storing
- Storing and Loading Strings
- .NET编程中遇到的问题
- Md5Checker v3.2.4
- 2007新发经典语录
- 设置sql*plus的autotrace(摘自Oracle编程艺术)
- 关于DSN
- db4o Storing/Retrieving/Updating/Deleting structured objects
- ResEdit 1.3.6
- 银行自助设备详细介绍(四)——存款机
- 公司是技术人员还是市场人员更重要?
- 在login.sql文件中设置sql*plus的环境(摘自《Oracle编程艺术》)
- 智能设备 C#调用MFC DLL 传参值为汉字的解决方案 CString转存 unsigned char数组
- 北京信息工程学院、北京信息科技大学 软件工程课程设计全部代码,希望对北信的下一代有用!
- VC中使用SCRIPT 正则写的LRC歌词分析类
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解