|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex

Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2

Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki

Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services

Related projects
Spring ORM support
Spring XML factories
WS frameworks

XML
XML

XML Code Generator
XML Code Generator

JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR

Tools
Schema generator

Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice

DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping

More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration

About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name

## Blobs in PostgreSQL

OID Support
OID Example

## OID Support

PostgreSQL's blob support has evolved over the years. Today PostgreSQL fields can be of unlimited length. And there are specific data types for character and binary large objects. The current Castor support for blobs, however, uses an earlier PostgreSQL blob support. This support places the blob data in the pg_largeobject table and a object id in the referring table. For most practical purposes using this earlier support does not matter.

Database version and the JDBC driver version matter greatly. To get everything to work I eventually built and installed PostgreSQL 7.2.2 and used the JDBC driver from this build (i.e. not the one from http://jdbc.postgresql.org.

Since Castor is using the earlier blob support the JDBC has to be placed in PostgreSQL 7.1 comparability mode. To do this use the following JDBC URL

          jdbc:postgresql://host:port/database?compatible=7.1

Once you have resolved the PostgreSQL version issues Castor works as documented.

## OID Example

Here are the details of an example configuration.

          Client Windows 2000, Sun Java Standard Edition 1.3.1_03, Castor 0.9.3.21
          Server RedHat 7.2, PostgreSQL 7.2.2

The interface I am using is

        public interface Document {
            String      getTitle();
            void        setTitle( String title );
            Date        getCreatedOn();
            void        setCreatedOn( Date createdOn );
            String      getContentType();
            void        setContentType( String contentType );
            InputStream getContent();
            void        setContent( InputStream content );
        }

and this is implemented by the class DocumentImpl.

The mapping file is

      <?xml version="1.0"?>
        <mapping>
         <class
             name="com.ingenta.DocumentImpl"
             identity="id"
             key-generator="SEQUENCE" >
             <description />
             <cache-type type="none" />
             <map-to table="documents" />
             <field name="id" type="integer" >
                 <sql name="id" type="integer" dirty="check" required="true"/>
             </field>
             <field name="title" type="string">
                 <sql name="title" type="longvarchar" dirty="check" />
             </field>
             <field name="createdOn" type="date">
                 <sql name="createdon" type="date" dirty="check" />
             </field>
             <field name="contentType" type="string">
                 <sql name="contenttype" type="longvarchar" dirty="check" />
             </field>
             <field name="content" type="stream">
                 <sql name="content" type="blob" dirty="ignore" />
             </field>
         </class>
     </mapping>

Note that the blob is not dirty checked.

And the SQL is

        create table documents (
            id          serial    not null,
            title       text      null,
            createdon   timestamp null,
            contenttype text      null,
            content     oid       null,
            primary key ( id )
        );

Castor caches objects between transactions for performance. With a blob however the cached object's InputStream is not reusable. To workaround this I have told the cache to not cache any objects of this class by adding to the class mapping, as noted above.

<notice> Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. </notice>
<notice> Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. </notice>