Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.
/ pg-inet-maven Public archive

PostgreSQL networking extansions rebuild and enhanced with Maven

Notifications You must be signed in to change notification settings

ancoron/pg-inet-maven

Repository files navigation

This repository is basically a Maven wrapper around the original networking
extension written by Russell Francis and hosted at the Mercurial repository over
here:

 https://hg.metro-six.com/public/pg-inet-types/


The official documentation for this is here:

 http://www.metro-six.com/products/labs/pg-inet-types


In advance, this repository provides some extended means like integration into
OSGi runtime environments as well as other code extensions to the original.

Please visit the wiki for more information:

 https://github.com/ancoron/pg-inet-maven/wiki


So, let's get started with using PostgreSQL network types within JPA:


1.) Configure this repository (if not already available):

 <repository>
     <id>sonatype-nexus-releases</id>
     <name>Release artifacts</name>
     <url>https://oss.sonatype.org/content/repositories/releases</url>
     <snapshots>
         <enabled>false</enabled>
     </snapshots>
 </repository>


2.) Add a new dependency to your JPA project:

 <dependency>
     <groupId>org.ancoron.postgresql</groupId>
     <artifactId>org.ancoron.postgresql.jpa</artifactId>
     <version>9.1.901.jdbc4.1-rc9</version>
 </dependency>


3.) Enabling type mapping to the database

3. a) Using explicit EcliseLink Converters:

 import org.ancoron.postgresql.jpa.IPNetwork;
 import org.ancoron.postgresql.jpa.eclipselink.NetworkConverter;
 import org.eclipse.persistence.annotations.Convert;
 import org.eclipse.persistence.annotations.Converter;

 // ...

 @Entity
 @Table(name="test_entity_network")
 @Converter(name="netConverter", converterClass=NetworkConverter.class)
 public class NetworkTestEntity implements Serializable {

     @Column(name="c_network", nullable=false)
     @Convert("netConverter")
     private IPNetwork network;

     // ...
 }


3. b) Using automatic conversion (keeps your Entities at pure javax.persistence):

 import java.net.InetAddress;

 // ...

 @Entity
 @Table(name="test_entity_ip")
 public class IPTestEntity implements Serializable {

     @Column(name="c_ip")
     private InetAddress ip;

     // ...
 }

Now to enable the automatic mapping for the java.net.InetAddress data type
simply add this to your persistence.xml:

 ...
 <property name="eclipselink.session-event-listener"
     value="org.ancoron.postgresql.jpa.eclipselink.ConverterInitializer"/>
 ...


4.) If you are running your application inside an application server please
make sure that you use the appropriate ServerPlaftorm with Eclipselink,
because we have to unwrap the wrapper-connections established by the app server,
e.g. for GlassFish:

 <?xml version="1.0" encoding="UTF-8"?>
 <persistence version="2.0"
              xmlns="http://java.sun.com/xml/ns/persistence"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                  http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
     <persistence-unit name="PGNetworkUnit" transaction-type="JTA">
         <jta-data-source>java:app/jdbc/NetworkTestDS</jta-data-source>
         <!--
             ...classes...
         -->
         <properties>
             <property name="eclipselink.target-server" value="SunAS9"/>

             <!--
                 ...other properties...
             -->
         </properties>
     </persistence-unit>
 </persistence>


Now you should be all set.

 Have fun!

About

PostgreSQL networking extansions rebuild and enhanced with Maven

Resources

Stars

Watchers

Forks

Packages

No packages published