Archive for October, 2006

152 Persistence descriptor Whilst all XML documents must

Tuesday, October 31st, 2006

Persistence descriptor elements 153 10.3 Persistence descriptor elements We will now consider the tags which are defined in the persistence descriptor DTD, and which are used in order to specify the persistence characteristics of persistence-capable classes. 10.3.1 The element occurs at various places throughout the DTD. It is a placeholder facilitating the introduction of vendor-specific extensions into persistence descriptors whilst retaining conformance to the standard DTD. It has three attributes: vendor-name, key, and value. This element will be illustrated at the end of the chapter. 10.3.2 jdo.dtd (extract) This is the root element of the document and must be present. It has no attributes. It must contain at least one
element, and may contain more than one. It may also contain zero, or more elements. 10.3.3
jdo.dtd (extract) This element identifies a package from which some classes will be enhanced. It has one attribute, the name of the package, which must be fully qualified, as in the example below: The
element must contain one or more elements. It may also contain zero or more elements.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

152 Persistence descriptor Whilst all XML documents must

Tuesday, October 31st, 2006

152 Persistence descriptor Whilst all XML documents must be well formed, they may optionally be valid according to a grammar. The grammar for an XML document is provided through a DTD. This is a text file that defines the valid attribute names for each tag, as well as the valid contents of each tag. Tag content is specified in terms of the allowable tags that may be included, and their respective cardinality. For example, the tag has an attribute called name that is mandatory. Between the opening tag and the closing tag a document may contain zero or more or tags. The DTD specifies this as follows: The asterisk (*) represents a cardinality of zero, one, or many. You will occasionally see the plus sign (+), which is used in DTDs to represent the cardinality of one or many. The DTD for JDO persistence descriptors is a file called jdo.dtd. Every persistence descriptor references the DTD through a DOCTYPE directive. An example is shown below. The actual path to jdo.dtd will vary according to your installation. The full contents of jdo.dtd is shown in Appendix C. Hopefully the brief discussion above will be sufficient for you to read the DTD if you wish to do so. For further information about XML, and the Java APIs available to manipulate XML documents, I recommend Java and XML (McLaughlin, 2000). 10.2 Naming the persistence descriptor A single persistence descriptor document should describe either a single class, or a single package. The descriptor should be named appropriately with either the class name or package name, followed by the extension .jdo. This naming convention is recommended by the specification. However, it is unlikely that enhancement tools will enforce it, particularly since the DTD specifically provides for multiple packages to be described in a single descriptor.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

150 JDO exceptions 9.2.7 JDOFatalInternalException This is the

Tuesday, October 31st, 2006

Persistence descriptor 10 The persistence descriptor is used at enhancement time to identify classes to be made persistence-capable. Some of the information it contains may additionally be used by the implementation at runtime particularly vendor-specific enhancements such as data store mapping information. The persistence descriptor is an XML document. A brief overview follows for readers not yet familiar with XML. 10.1 XML overview Markup languages, which allow text data to be structured using a set of prescribed tags, have been in use for many years. XML is a particularly simple markup language. It defines neither the tags nor the grammar according to which the tags can be combined. Tag names for XML documents are defined by the document author in accordance with the information being marked up. This affords great flexibility. In a JDO persistence descriptor, the tags include ,
, and . Tags are not case sensitive. All XML documents must be well formed, in that each opening tag must be matched by a corresponding closing tag. Closing tags carry a preceding forward slash character, as in
, , and . The sequence in which tags are closed must match the sequence in which they were opened. Pairs of opening and closing tags may have content between them. Often this content will include other tags as appropriate to the data being marked up. Additionally, tags may contain attributes. These are name value pairs occurring within the opening tag. An example is the name attribute of the tag: class tag content goes here A tag that is opened and then closed with no intervening content may be written as a single empty tag for convenience. Empty tags may still contain attributes and are notated with a trailing forward slash character, as in . Thus is equivalent to

Hint: This post is supported by Gama besplatan domen provider

150 JDO exceptions 9.2.7 JDOFatalInternalException This is the

Tuesday, October 31st, 2006

150 JDO exceptions 9.2.7 JDOFatalInternalException This is the base class for JDO implementation failures. instances of this exception should be reported to the JDO vendor. 9.2.8 JDODataStoreException This is the base class for data store exceptions that can be retried. 9.2.9 JDOFatalDataStoreException This is the base class for fatal data store exceptions that cannot be retried. It might be thrown if the data store transaction is rolled back other than at a commit/rollback request by the application. 9.3 Application exceptions The discussion above has centered on JDO exceptions. However, it is also likely that an application will have its own cause to throw and catch domain-specific exceptions. These are referred to as application exceptions. Application exceptions are designed along with the domain model, although they typically end up in a subpackage of the domain package. Domain objects throw and catch these exceptions according to the modeling of business processes by the designer. Persistent instances are capable of throwing and catching the same exceptions as their transient counterparts. No further effort is required of developers in this regard as a result of using JDO for object persistence. What s next? In the following chapter we take a detailed look at the structure of a persistence descriptor. Specific focus is given to the DTD that constrains these XML documents.

Hint: This post is supported by Gama besplatan domen provider

148 JDO exceptions 9.2.1 JDOException This is the

Tuesday, October 31st, 2006

Base exception classes 149 9.2.2 JDOFatalException JDOFatalException is the base class for exceptions that cannot be retried. Occurrence of this exception (or a subclass thereof) generally implies that the transaction has been rolled back and should be abandoned by the application. 9.2.3 JDOCanRetryException JDOCanRetryException is the base class for exceptions that can be retried after the application has attempted to address the cause of the exception. 9.2.4 JDOUserOptionException This is the base class for all retriable exceptions that are caused by the user. The application must typically correct the problem causing the exception before attempting the operation again. Potential causes would include: . attempts to make an instance with application identity persistent, with primary key fields that are identical to an already persistent instance. Correct the primary key field values and try again. . attempts to fetch an instance by Object ID when no such persistent instance exists. Correct the Object ID and try again. . attempts to get the extent of a class or interface for which the extent is not managed by JDO. Get the extent of a different class, or alter the persistence descriptor and enhance the chosen class so that its extent is managed by JDO. 9.2.5 JDOUnsupportedOptionException A JDOUnsupportedOptionException is thrown when an application attempts to enable a particular optional feature that is not supported by the implementation. It is a subclass of JDOUserException. Potential causes would include: . use of optimistic transaction management when not supported; . the changing of an instance s primary key field values when not supported; . use of Persistent-Nontransactional instances when not supported. 9.2.6 JDOFatalUserException This is the base class for all fatal (cannot be retried) exceptions caused by the application. After a persistence manager has been closed, only its isClosed() method may be invoked. A JDOFatalUserException is thrown if any other method is invoked on the PersistenceManager, or on any Transaction, Query, Extent, or Iteratorinstances obtained from it.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

148 JDO exceptions 9.2.1 JDOException This is the

Tuesday, October 31st, 2006

148 JDO exceptions 9.2.1 JDOException This is the base class for all JDO exceptions. It extends java.lang.Runtime Exception so instances of this and all its subclasses do not have to be explicitly caught by the application. When instantiated, the JDOException is given a descriptive string, an optional nested exception, and an optional failed object. All three of these can be accessed by the application if the exception is caught. 9.2.1.1 JDOException constructors The constructors for JDOException are shown below, and equivalent constructors exist for every exception in the hierarchy. These are relevant to developers as it is occasionally necessary to throw instances of JDO exceptions from within persistence-capable objects. An example of this would be the use of the InstanceCallbacks interface to prevent an instance from being deleted in certain circumstances. The jdoPreDelete() method would throw a JDOUserException if deletion were to be prevented. Such an example has already been presented in Section 4.6. JDOException() This constructor takes no arguments. JDOException(String msg) This constructor takes a String message only. JDOException(String msg, Throwable[] nested) This constructor takes a message and an array of nested exceptions. JDOException(String msg, Throwable nested) This constructor takes a message and a single nested exception (which itself might contain further nested exceptions as necessary). JDOException(String msg, Object failed) This constructor takes a message and a reference to the failed object. JDOException(String msg, Throwable[] nested, Object failed) This constructor takes a message, an array of nested exceptions, and a reference to the failed object . JDOException(String msg, Throwable nested, Object failed) This constructor takes a message, a single nested exception, and a reference to the failed object.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

JDO exceptions JDO defines a number of exceptions

Tuesday, October 31st, 2006

JDO exception hierarchy 147 again). They may be caused by the application (user), by the data store, or by the JDO implementation itself. The exception hierarchy defines base classes to handle each of these situations (Figure 9.1). java.lang.RuntimeException JDOException JDOCanRetryException JDOFatalException JDOFatalUserException JDOFatalInternalException JDOFatalDataStoreException JDOUserException JDODataStoreException JDOUnsupportedOptionException Figure 9.1 JDO exception hierarchy When examining the hierarchy, note the following terminology that refers to the source of each exception: User: the application/component invoking JDO persistence services. DataStore: the underlying data store. Internal: The JDO implementation. implementations are free to define their own classes of exceptions that fit into this hierarchy by subclassing the appropriate base class. Alternatively they may throw instances of the base class exceptions themselves with appropriate identifying attributes. 9.2 Base exception classes Here are detailed descriptions of each of the nine JDO base exception classes.
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

JDO exceptions JDO defines a number of exceptions

Tuesday, October 31st, 2006

JDO exceptions JDO defines a number of exceptions to represent error conditions that might arise in the various layers of an implementation. These are all defined to be runtime exceptions. Since the compiler does not check such exceptions, the application is free to catch only those exceptions that warrant a particular response. This philosophy allows JDO to be more transparently applied to existing domain models and application components than would have been the case if checked exceptions were employed. In this chapter we look at the JDO exception hierarchy, examine the base class exceptions and their subclass exceptions, and look at a selection of situations that might give rise to them. Why runtime and not checked exceptions? The choice of whether to use checked or runtime (unchecked) exceptions in a new API is one which must be considered carefully, as each style of exception has its place. For instance, in Remote Method Invocation (RMI), RemoteException is a checked exception. The choice was made deliberately so that developers would always know when they were executing a remote method call. This was deemed necessary, as remote calls are particularly slow. In JDO, however, the primary focus is transparency. We aim to provide a persistence infrastructure that can be applied easily without the addition of JDO-specific code to domain classes. Some methods of JDO instances, which work fine when the instance is in the transient state, might throw JDO exceptions from other states; for example, attempting to interact with a persistent instance when no transaction is active, or when the persistence manager has been closed. In order to retain the high level of transparency desired, all of the JDO exceptions are runtime exceptions. 9.1 JDO exception hierarchy Exceptions arising through JDO fall into a number of categories. Exceptions may be fatal (the requested operation cannot be completed) or can be retried (the error can be corrected by the application and the operation attempted
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

144 Queries with JDOQL pressing the Prepare button,

Monday, October 30th, 2006

Dynamic Query Window 145 Dynamic Query Window enhancements The Dynamic Query Window was written by Ogilvie Partners and is avail able in the downloadable distribution. It gives developers an excellent way to learn and experiment with JDOQL. It may also prove useful for manu ally tuning complex queries. We plan an enhancement to generate the JDO-compliant code for each query at the user s request. This is intended as a means to coding JDOQL queries more efficiently and accurately. Refer to http://www.OgilviePartners.com for further details. What s next? In the next chapter we briefly examine JDO s exception strategy, the exception classes JDO defines, and situations that might give rise to their being thrown.
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services

144 Queries with JDOQL pressing the Prepare button,

Monday, October 30th, 2006

144 Queries with JDOQL pressing the Prepare button, a new Query is obtained from the persistence manager and the user s query elements bound to it. The Execute button parses the list of parameter values, constructs the appropriate array of parameters, and executes the query. Queries may optionally be compiled before they are executed. Query results are shown by iterating through the returned Collection and invoking the toString() method of each object reference. Figure 8.2 Dynamic Query Window
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services