Java Doc for ObjectContainer.java in  » Database-DBMS » db4o-6.4 » com » db4o » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db4o 6.4 » com.db4o 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.db4o.ObjectContainer

ObjectContainer
public interface ObjectContainer (Code)
the interface to a db4o database, stand-alone or client/server.

The ObjectContainer interface provides methods to store, query and delete objects and to commit and rollback transactions.

An ObjectContainer can either represent a stand-alone database or a connection to a Db4o.openServer(Stringint) db4o server .

An ObjectContainer also represents a transaction. All work with db4o always is transactional. Both ObjectContainer.commit() and ObjectContainer.rollback() start new transactions immediately. For working against the same database with multiple transactions, open a db4o server with Db4o.openServer(Stringint) and ObjectServer.openClient connect locally or Db4o.openClient(StringintStringString) over TCP .
See Also:   ExtObjectContainer
See Also:    ExtObjectContainer for extended functionality.




Method Summary
public  voidactivate(Object obj, int depth)
     activates all members on a stored object to the specified depth.

See com.db4o.config.Configuration.activationDepth(int) "Why activation" for an explanation why activation is necessary.

The activate method activates a graph of persistent objects in memory. Only deactivated objects in the graph will be touched: their fields will be loaded from the database.
public  booleanclose()
     closes the ObjectContainer.
public  voidcommit()
     commits the running transaction.

Transactions are back-to-back.
public  voiddeactivate(Object obj, int depth)
     deactivates a stored object by setting all members to NULL.
Primitive types will be set to their default values.

Examples: ../com/db4o/samples/activate.

Calls to this method save memory. The method has no effect, if the passed object is not stored in the ObjectContainer.

deactivate() triggers the callback method com.db4o.ext.ObjectCallbacks.objectOnDeactivate objectOnDeactivate .

Be aware that calling this method with a depth parameter greater than 1 sets members on member objects to null.
public  voiddelete(Object obj)
     deletes a stored object permanently.

Note that this method has to be called for every single object individually.
public  ExtObjectContainerext()
     returns an ObjectContainer with extended functionality.

Every ObjectContainer that db4o provides can be casted to an ExtObjectContainer.
public  ObjectSet<T>get(Object template)
     Query-By-Example interface to retrieve objects.

get() creates an ObjectSet ObjectSet containing all objects in the ObjectContainer that match the passed template object.

Calling get(NULL) returns all objects stored in the ObjectContainer.


Query Evaluation
All non-null members of the template object are compared against all stored objects of the same class. Primitive type members are ignored if they are 0 or false respectively.

Arrays and all supported Collection classes are evaluated for containment.
public  Queryquery()
     creates a new S.O.D.A.
public  ObjectSet<TargetType>query(Class<TargetType> clazz)
     queries for all instances of a class.
Parameters:
  clazz - the class to query for.
public  ObjectSet<TargetType>query(Predicate<TargetType> predicate)
     Native Query Interface.

Native Queries allow typesafe, compile-time checked and refactorable querying, following object-oriented principles.
public  ObjectSet<TargetType>query(Predicate<TargetType> predicate, QueryComparator<TargetType> comparator)
     Native Query Interface.
public  ObjectSet<TargetType>query(Predicate<TargetType> predicate, Comparator<TargetType> comparator)
     Native Query Interface.
public  voidrollback()
     rolls back the running transaction.
public  voidset(Object obj)
     newly stores objects or updates stored objects.

An object not yet stored in the ObjectContainer will be stored when it is passed to set().



Method Detail
activate
public void activate(Object obj, int depth) throws Db4oIOException, DatabaseClosedException(Code)
activates all members on a stored object to the specified depth.

See com.db4o.config.Configuration.activationDepth(int) "Why activation" for an explanation why activation is necessary.

The activate method activates a graph of persistent objects in memory. Only deactivated objects in the graph will be touched: their fields will be loaded from the database. The activate methods starts from a root object and traverses all member objects to the depth specified by the depth parameter. The depth parameter is the distance in "field hops" (object.field.field) away from the root object. The nodes at 'depth' level away from the root (for a depth of 3: object.member.member) will be instantiated but deactivated, their fields will be null. The activation depth of individual classes can be overruled with the methods com.db4o.config.ObjectClass.maximumActivationDepth maximumActivationDepth() and com.db4o.config.ObjectClass.minimumActivationDepth minimumActivationDepth() in the com.db4o.config.ObjectClass ObjectClass interface .

A successful call to activate triggers the callback method com.db4o.ext.ObjectCallbacks.objectOnActivate objectOnActivate which can be used for cascaded activation.


See Also:   com.db4o.config.Configuration.activationDepth
See Also:    Why activation?
See Also:   ObjectCallbacks
See Also:    Using callbacks
Parameters:
  obj - the object to be activated.
Parameters:
  depth - the member com.db4o.config.Configuration.activationDepth depthto which activate is to cascade.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



close
public boolean close() throws Db4oIOException(Code)
closes the ObjectContainer.

A call to close() automatically performs a ObjectContainer.commit commit() .

Note that every session opened with Db4o.openFile() requires one close()call, even if the same filename was used multiple times.

Use while(!close()){} to kill all sessions using this container.

success - true denotes that the last used instance of this containerand the database file were closed.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.



commit
public void commit() throws Db4oIOException, DatabaseClosedException, DatabaseReadOnlyException(Code)
commits the running transaction.

Transactions are back-to-back. A call to commit will starts a new transaction immedidately.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.
throws:
  DatabaseReadOnlyException - database was configured as read-only.



deactivate
public void deactivate(Object obj, int depth) throws DatabaseClosedException(Code)
deactivates a stored object by setting all members to NULL.
Primitive types will be set to their default values.

Examples: ../com/db4o/samples/activate.

Calls to this method save memory. The method has no effect, if the passed object is not stored in the ObjectContainer.

deactivate() triggers the callback method com.db4o.ext.ObjectCallbacks.objectOnDeactivate objectOnDeactivate .

Be aware that calling this method with a depth parameter greater than 1 sets members on member objects to null. This may have side effects in other places of the application.


See Also:   ObjectCallbacks
See Also:    Using callbacks
See Also:   com.db4o.config.Configuration.activationDepth
See Also:    Why activation?
Parameters:
  obj - the object to be deactivated.
Parameters:
  depth - the member com.db4o.config.Configuration.activationDepth depth to which deactivate is to cascade.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



delete
public void delete(Object obj) throws Db4oIOException, DatabaseClosedException, DatabaseReadOnlyException(Code)
deletes a stored object permanently.

Note that this method has to be called for every single object individually. Delete does not recurse to object members. Simple and array member types are destroyed.

Object members of the passed object remain untouched, unless cascaded deletes are com.db4o.config.ObjectClass.cascadeOnDelete configured for the class or for com.db4o.config.ObjectField.cascadeOnDelete one of the member fields .

The method has no effect, if the passed object is not stored in the ObjectContainer.

A subsequent call to set() with the same object newly stores the object to the ObjectContainer.

delete() triggers the callback method com.db4o.ext.ObjectCallbacks.objectOnDelete objectOnDelete which can be also used for cascaded deletes.


See Also:   com.db4o.config.ObjectClass.cascadeOnDelete
See Also:   com.db4o.config.ObjectField.cascadeOnDelete
See Also:   ObjectCallbacks
See Also:    Using callbacks
Parameters:
  obj - the object to be deleted from theObjectContainer.

throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.
throws:
  DatabaseReadOnlyException - database was configured as read-only.



ext
public ExtObjectContainer ext()(Code)
returns an ObjectContainer with extended functionality.

Every ObjectContainer that db4o provides can be casted to an ExtObjectContainer. This method is supplied for your convenience to work without a cast.

The ObjectContainer functionality is split to two interfaces to allow newcomers to focus on the essential methods.

this, casted to ExtObjectContainer



get
public ObjectSet<T> get(Object template) throws Db4oIOException, DatabaseClosedException(Code)
Query-By-Example interface to retrieve objects.

get() creates an ObjectSet ObjectSet containing all objects in the ObjectContainer that match the passed template object.

Calling get(NULL) returns all objects stored in the ObjectContainer.


Query Evaluation
All non-null members of the template object are compared against all stored objects of the same class. Primitive type members are ignored if they are 0 or false respectively.

Arrays and all supported Collection classes are evaluated for containment. Differences in length/size() are ignored.

Consult the documentation of the Configuration package to configure class-specific behaviour.


Returned Objects
The objects returned in the ObjectSet ObjectSet are instantiated and activated to the preconfigured depth of 5. The com.db4o.config.Configuration.activationDepth activation depth may be configured com.db4o.config.Configuration.activationDepth globally or com.db4o.config.ObjectClass individually for classes .

db4o keeps track of all instantiatied objects. Queries will return references to these objects instead of instantiating them a second time.

Objects newly activated by get() can respond to the callback method com.db4o.ext.ObjectCallbacks.objectOnActivate objectOnActivate .


Parameters:
  template - object to be used as an example to find all matching objects.

ObjectSet ObjectSet containing all found objects.


See Also:   com.db4o.config.Configuration.activationDepth
See Also:    Why activation?
See Also:   ObjectCallbacks
See Also:    Using callbacks
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



query
public Query query() throws DatabaseClosedException(Code)
creates a new S.O.D.A. Query Query .

Use ObjectContainer.get get(Object template) for simple Query-By-Example.

ObjectContainer.query(Predicate) Native queries are the recommended main db4o query interface.

a new Query object
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



query
public ObjectSet<TargetType> query(Class<TargetType> clazz) throws Db4oIOException, DatabaseClosedException(Code)
queries for all instances of a class.
Parameters:
  clazz - the class to query for. the ObjectSet returned by the query.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



query
public ObjectSet<TargetType> query(Predicate<TargetType> predicate) throws Db4oIOException, DatabaseClosedException(Code)
Native Query Interface.

Native Queries allow typesafe, compile-time checked and refactorable querying, following object-oriented principles. Native Queries expressions are written as if one or more lines of code would be run against all instances of a class. A Native Query expression should return true to mark specific instances as part of the result set. db4o will attempt to optimize native query expressions and execute them against indexes and without instantiating actual objects, where this is possible.

The syntax of the enclosing object for the native query expression varies, depending on the language version used. Here are some examples, how a simple native query will look like in some of the programming languages and dialects that db4o supports:

// C# .NET 2.0
IList <Cat> cats = db.Query <Cat> (delegate(Cat cat) {
   return cat.Name == "Occam";
});


// Java JDK 5
List <Cat> cats = db.query(new Predicate<Cat>() {
   public boolean match(Cat cat) {
      return cat.getName().equals("Occam");
   }
});


// Java JDK 1.2 to 1.4
List cats = db.query(new Predicate() {
   public boolean match(Cat cat) {
      return cat.getName().equals("Occam");
   }
});


// Java JDK 1.1
ObjectSet cats = db.query(new CatOccam());

public static class CatOccam extends Predicate {
   public boolean match(Cat cat) {
      return cat.getName().equals("Occam");
   }
});


// C# .NET 1.1
IList cats = db.Query(new CatOccam());

public class CatOccam : Predicate {
   public boolean Match(Cat cat) {
      return cat.Name == "Occam";
   }
});

Summing up the above:
In order to run a Native Query, you can
- use the delegate notation for .NET 2.0.
- extend the Predicate class for all other language dialects

A class that extends Predicate is required to implement the #match() / #Match() method, following the native query conventions:
- The name of the method is "#match()" (Java) / "#Match()" (.NET).
- The method must be public public.
- The method returns a boolean.
- The method takes one parameter.
- The Type (.NET) / Class (Java) of the parameter specifies the extent.
- For all instances of the extent that are to be included into the resultset of the query, the match method should return true. For all instances that are not to be included, the match method should return false.


Parameters:
  predicate - the Predicate containing the native query expression. the ObjectSet returned by the query.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



query
public ObjectSet<TargetType> query(Predicate<TargetType> predicate, QueryComparator<TargetType> comparator) throws Db4oIOException, DatabaseClosedException(Code)
Native Query Interface. Queries as with com.db4o.ObjectContainer.query(com.db4o.query.Predicate) , but will sort the resulting com.db4o.ObjectSet according to the given com.db4o.query.QueryComparator .
Parameters:
  predicate - the Predicate containing the native query expression.
Parameters:
  comparator - the QueryComparator specifiying the sort order of the result the ObjectSet returned by the query.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



query
public ObjectSet<TargetType> query(Predicate<TargetType> predicate, Comparator<TargetType> comparator) throws Db4oIOException, DatabaseClosedException(Code)
Native Query Interface. Queries as with com.db4o.ObjectContainer.query(com.db4o.query.Predicate) , but will sort the resulting com.db4o.ObjectSet according to the given com.db4o.query.QueryComparator .
Parameters:
  predicate - the Predicate containing the native query expression.
Parameters:
  comparator - the java.util.Comparator specifying the sort order of the result the ObjectSet returned by the query.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.



rollback
public void rollback() throws Db4oIOException, DatabaseClosedException, DatabaseReadOnlyException(Code)
rolls back the running transaction.

Modified application objects im memory are not restored. Use combined calls to ObjectContainer.deactivate deactivate() and ObjectContainer.activate activate() to reload an objects member values.
throws:
  Db4oIOException - I/O operation failed or was unexpectedly interrupted.
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.
throws:
  DatabaseReadOnlyException - database was configured as read-only.



set
public void set(Object obj) throws DatabaseClosedException, DatabaseReadOnlyException(Code)
newly stores objects or updates stored objects.

An object not yet stored in the ObjectContainer will be stored when it is passed to set(). An object already stored in the ObjectContainer will be updated.

Updates
- will affect all simple type object members.
- links to object members that are already stored will be updated.
- new object members will be newly stored. The algorithm traverses down new members, as long as further new members are found.
- object members that are already stored will not be updated themselves.
Every object member needs to be updated individually with a call to set() unless a deep com.db4o.config.Configuration.updateDepth global or com.db4o.config.ObjectClass.updateDepth class-specific update depth was configured or cascaded updates were com.db4o.config.ObjectClass.cascadeOnUpdate defined in the class or in com.db4o.config.ObjectField.cascadeOnUpdate one of the member fields .

Examples: ../com/db4o/samples/update.

Depending if the passed object is newly stored or updated, the callback method com.db4o.ext.ObjectCallbacks.objectOnNew objectOnNew or com.db4o.ext.ObjectCallbacks.objectOnUpdate objectOnUpdate is triggered. com.db4o.ext.ObjectCallbacks.objectOnUpdate objectOnUpdate might also be used for cascaded updates.


Parameters:
  obj - the object to be stored or updated.
See Also:   ExtObjectContainer.set(java.lang.Objectint)
See Also:    ExtObjectContainer#set(object, depth)
See Also:   com.db4o.config.Configuration.updateDepth
See Also:   com.db4o.config.ObjectClass.updateDepth
See Also:   com.db4o.config.ObjectClass.cascadeOnUpdate
See Also:   com.db4o.config.ObjectField.cascadeOnUpdate
See Also:   ObjectCallbacks
See Also:    Using callbacks
throws:
  DatabaseClosedException - db4o database file was closed or failed to open.
throws:
  DatabaseReadOnlyException - database was configured as read-only.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.