Java Doc for Entity.java in  » JMX » je » com » sleepycat » persist » model » 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 » JMX » je » com.sleepycat.persist.model 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.sleepycat.persist.model.Entity

Entity
public @interface Entity(Code)
Indicates a persistent entity class. For each entity class, a PrimaryIndex can be used to store and access instances of that class. Optionally, one or more SecondaryIndex objects may be used to access entity instances by secondary key.

Entity Subclasses and Superclasses

An entity class may have any number of subclasses and superclasses; however, none of these may themselves be entity classes (annotated with Entity ).

Entity superclasses are used to share common definitions and instance data. For example, fields in an entity superclass may be defined as primary or secondary keys.

Entity subclasses are used to provide polymorphism within a single PrimaryIndex . Instances of the entity class and its subclasses are stored in the same PrimaryIndex . Fields in an entity subclass may be defined as secondary keys.

For example, the following BaseClass defines the primary key for any number of entity classes, using a single sequence to assign primary key values. The entity class Pet extends the base class, implicitly defining a primary index that will contain instances of it and its subclasses, including Cat which is defined below. The primary key ( id ) and secondary key ( name ) can be used to retrieve any Pet instance.

 class BaseClass {
 long id;
 }
 class Pet extends BaseClass {
 String name;
 float height;
 float weight;
 }

The entity subclass Cat defines a secondary key ( finickyness ) that only applies to Cat instances. Querying by this key will never retrieve a Dog instance, if such a subclass existed, because a Dog instance will never contain a finickyness key.

 class Cat extends Pet {
 int finickyness;
 }

Persistent Fields and Types

All non-transient instance fields of an entity class, as well as its superclasses and subclasses, are persistent. static and transient fields are not persistent. The persistent fields of a class may be private , package-private (default access), protected or public .

It is worthwhile to note the reasons that object persistence is defined in terms of fields rather than properties (getters and setters). This allows business methods (getters and setters) to be defined independently of the persistent state of an object; for example, a setter method may perform validation that could not be performed if it were called during object deserialization. Similarly, this allows public methods to evolve somewhat independently of the (typically non-public) persistent fields.

Simple Types

Persistent types are divided into simple types, enum types, complex types, and array types. Simple types and enum types are single valued, while array types may contain multiple elements and complex types may contain one or more named fields.

Simple types include:

When null values are required (for optional key fields, for example), primitive wrapper classes must be used instead of primitive types.

Simple types, enum types and array types do not require annotations to make them persistent.

Complex and Proxy Types

Complex persistent classes must be annotated with Entity or Persistent , or must be proxied by a persistent proxy class (described below). This includes entity classes, subclasses and superclasses, and all other complex classes referenced via fields of these classes.

All complex persistent classes must have a default constructor. The default constructor may be private , package-private (default access), protected , or public . Other constructors are allowed but are not used by the persistence mechanism.

It is sometimes desirable to store instances of a type that is externally defined and cannot be annotated or does not have a default constructor; for example, a class defined in the Java standard libraries or a 3rd party library. In this case, a PersistentProxy class may be used to represent the stored values for the externally defined type. The proxy class itself must be annotated with Persistent like other persistent classes, and the Persistent.proxyFor property must be specified.

For convenience, built-in proxy classes are included for several common classes (listed below) in the Java library. If you wish, you may define your own PersistentProxy to override these built-in proxies.

Complex persistent types should in general be application-defined classes. This gives the application control over the persistent state and its evolution over time.

Other Type Restrictions

Entity classes and subclasses may not be used in field declarations for persistent types. Fields of entity classes and subclasses must be simple types or non-entity persistent types (annotated with Persistent not with Entity ).

Entity classes, subclasses and superclasses may be abstract and may implement arbitrary interfaces. Interfaces do not need to be annotated with Persistent in order to be used in a persistent class, since interfaces do not contain instance fields.

Persistent instances of static nested classes are allowed, but the nested class must be annotated with Persistent or Entity . Inner classes (non-static nested classes, including anonymous classes) are not currently allowed as persistent types.

Arrays of simple and persistent complex types are allowed as fields of persistent types. Arrays may be multidimensional. However, an array may not be stored as a top level instance in a primary index. Only instances of entity classes and subclasses may be top level instances in a primary index.

Embedded Objects

As stated above, the embedded (or member) non-transient non-static fields of an entity class are themselves persistent and are stored along with their parent entity object. This allows embedded objects to be stored in an entity to an arbitrary depth.

There is no arbitrary limit to the nesting depth of embedded objects within an entity; however, there is a practical limit. When an entity is marshalled, each level of nesting is implemented internally via recursive method calls. If the nesting depth is large enough, a StackOverflowError can occur. In practice, this has been observed with a nesting depth of 12,000, using the default Java stack size.

This restriction on the nesting depth of embedded objects does not apply to cyclic references, since these are handled specially as described below.

Object Graphs

When an entity instance is stored, the graph of objects referenced via its fields is stored and retrieved as a graph. In other words, if a single instance is referenced by two or more fields when the entity is stored, the same will be true when the entity is retrieved.

When a reference to a particular object is stored as a member field inside that object or one of its embedded objects, this is called a cyclic reference. Because multiple references to a single object are stored as such, cycles are also represented correctly and do not cause infinite recursion or infinite processing loops. If an entity containing a cyclic reference is stored, the cyclic reference will be present when the entity is retrieved.

Note that the stored object graph is restricted in scope to a single entity instance. This is because each entity instance is stored separately. If two entities have a reference to the same object when stored, they will refer to two separate instances when the entities are retrieved.


See Also:   Persistent
See Also:   PrimaryKey
See Also:   SecondaryKey
See Also:   KeyField
author:
   Mark Hayes


Field Summary
 intversion
     Identifies a new version of a class when an incompatible class change has been made.



Field Detail
version
int version(Code)
Identifies a new version of a class when an incompatible class change has been made. Prior versions of a class are referred to by version number to perform class evolution and conversion using Mutations .

The first version of a class is version zero, if Entity.version is not specified. When an incompatible class change is made, a version number must be assigned using Entity.version that is higher than the previous version number for the class. If this is not done, an IncompatibleClassException will be thrown when the store is opened.






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