SlideShare a Scribd company logo
PostgreSQL and PL/Java

     Server-Side Functions in Java

                 Peter Eisentraut
           petere@postgresql.org
Agenda
•   Functions in PostgreSQL
•   Enter PL/Java
•   Features of PL/Java
•   Support and Compatibility
•   Outlook and Wrap-Up




                                2
Defining a Function
Example of an SQL function:

CREATE FUNCTION add(int, int) RETURNS int
 LANGUAGE SQL
 AS 'SELECT $1 + $2;';


SELECT add(4, 5);
add
-----
   9



                                            3
Defining a Function
Example of a C function:

PG_FUNCTION_INFO_V1(funcname);
Datum add(PG_FUNCTION_ARGS)
{
    int32 a = PG_GETARG_INT32(0);
    int32 b = PG_GETARG_INT32(1);


    PG_RETURN_INT32(a + b);
}


                                    4
Defining a Function
Example of a C function, continued:

gcc -fPIC -c file.c
gcc -shared -o file.so file.o


CREATE FUNCTION add(int, int) RETURNS int
 LANGUAGE C
 AS 'file.so', 'add';




                                            5
Features of Functions
• Overloading
• Processing sets/tables
• Caching options
  (deterministic/nondeterministic)
• Execution privileges




                                     6
Advantages of Server-Side
             Functions
•   Encapsulation
•   Faster database access
•   Plan caching, inlining
•   Data validation through triggers
•   Side effects through triggers




                                       7
Functions as Building Blocks
•   Operators
•   Data types
•   Aggregate functions
•   Index access methods
•   Type casts
•   Character set conversions



                                    8
Procedural Languages
• Choice of SQL vs. C quite limited
• Solution: pluggable language handlers

• Available languages:
  Tcl, PL/pgSQL, Perl, Ruby, Python, Shell,
  R, Java, PHP



                                              9
Procedural Language Example:
          PL/pgSQL
CREATE FUNCTION logfunc(logtxt text)
 RETURNS timestamp
AS '
 DECLARE
       curtime timestamp;
 BEGIN
       curtime := ''now'';
       INSERT INTO logtable VALUES (logtxt, curtime);
       RETURN curtime;
 END;
' LANGUAGE plpgsql;

                                                        10
Procedural Language Example:
            PL/Perl
CREATE OR REPLACE FUNCTION valid_id()
 RETURNS trigger
AS '
 if (($_TD->{new}{i} >= 100) || ($_TD->{new}{i} <= 0)) {
     return "SKIP";     # skip INSERT/UPDATE command
 } elsif ($_TD->{new}{v} ne "immortal") {
     $_TD->{new}{v} .= "(modified by trigger)";
     return "MODIFY";   # modify row and run INSERT/UPDATE
 } else {
     return;            # execute INSERT/UPDATE command
 }
' LANGUAGE plperl;

                                                             11
Enter PL/Java
• Developed by Thomas Hallgren

• Stored procedures written in the Java
  language
• Java the most popular (client) language for
  PostgreSQL



                                            12
Standardization
SQL standard: ISO/IEC 9075-13:2003
SQL Routines and Types for the Java
  Programming Language ("SQL/JRT")
(210 pages)
driven by Oracle and IBM




                                      13
Timeline of PL/Java
•   Nov. 2000: first attempt with Kaffe 1.0.6
•   Dec. 2003: PL/Java project launched
•   Jan. 2004: first alpha release
•   Jan. 2005: release 1.0.0 (for PG 7.4)
•   Apr. 2005: release 1.1.0 (for PG 8.0)
•   currently “stable”



                                                14
Concept
•   Write a Java class
•   Designate static method as entry point
•   Pack into JAR
•   Load JAR into database
•   Adjust classpath
•   Create function in PostgreSQL



                                             15
Simple Example: Code
package com.example;


public class Foo
{
    static int add(int a, int b)
    {
        return a + b;
    }
}




                                   16
Simple Example: Deployment
javac com/example/Foo.java
jar cf foo.jar com/example/Foo.class


SELECT
  sqlj.install_jar('file:/home/peter/tmp/foo.jar',
  'foo', false);


SELECT sqlj.set_classpath('public', 'foo:bar:etc');


CREATE FUNCTION add(int, int) RETURNS int
 LANGUAGE java
 AS 'com.example.Foo.add';
                                                      17
Deployment Descriptor
Optional way to integrate install/uninstall SQL
 statements into the JAR file:
SQLActions[] = {
    "BEGIN INSTALL
      CREATE FUNCTION add(int, int) RETURNS int
        LANGUAGE java
        AS 'com.example.Foo.add';
    END INSTALL",
    "BEGIN REMOVE
      DROP FUNCTION add(int, int);
    END REMOVE"
}


                                                  18
Configuration
New parameters for postgresql.conf:

custom_variable_classes = 'pljava'


pljava.classpath = '/some/where/pljava.jar'
pljava.statement_cache_size = 10
pljava.release_lingering_savepoints = true
pljava.vmoptions = '-Xmx64M'
pljava.debug = false




                                              19
Parameter Type Mapping
Parameter types are mapped automatically:
  PostgreSQL         Java
  boolean            boolean
  shortint           short
  int                int
  bigint             long
  real               float
  double precision   double
  varchar, text      java.lang.String
  bytea              byte[]
  date               java.sql.Date
  time               java.sql.Time
  timestamp          java.sql.Timestamp
  other              java.lang.String


                                            20
Composite Types
CREATE TYPE compositeTest AS (
     base    integer,
     incbase integer,
     ctime   timestamp
);


CREATE FUNCTION useCompositeTest (compositeTest)
     RETURNS varchar
     AS 'foo.fee.Fum.useCompositeTest'
     LANGUAGE java;



                                                   21
Composite Types
Represented as java.sql.ResultSet with one
 row.
public static String useCompositeTest(ResultSet
   compositeTest) throws SQLException
{
    int base = compositeTest.getInt(1);
    int incbase = compositeTest.getInt(2);
    Timestamp ctime = compositeTest.getTimestamp(3);
    return "Base = "" + base +
     "", incbase = "" + incbase +
     "", ctime = "" + ctime + """;
}

                                                       22
Returning Sets
CREATE FUNCTION getNames() RETURNS SETOF varchar
   AS 'Bar.getNames'
   LANGUAGE java;


import java.util.Iterator;
public class Bar {
    public static Iterator getNames() {
        ArrayList names = new ArrayList();
        names.add("Lisa");
        names.add("Bob");
        names.add("Bill");
        return names.iterator();
    }
}

                                                   23
Built-in JDBC Driver
• Prepare/execute queries
• Query metadata
• No transaction management (can use
  savepoints)

Connection conn =
  DriverManager.getConnection("jdbc:default:connectio
  n");




                                                   24
Triggers
static void moddatetime(TriggerData td) throws SQLException
{
    if(td.isFiredForStatement())
     throw new TriggerException(td, "can't process STATEMENT events");
    if(td.isFiredAfter())
     throw new TriggerException(td, "must be fired before event");
    if(!td.isFiredByUpdate())
     throw new TriggerException(td, "can only process UPDATE events");


    ResultSet _new = td.getNew();
    String[] args = td.getArguments();
    if (args.length != 1)
     throw new TriggerException(td, "one argument was expected");
    _new.updateTimestamp(args[0], new Timestamp(System.currentTimeMillis()));
}

                                                                            25
Other Features
•   Exception handling
•   Logging
•   DatabaseMetaData
•   Multithreading
•   IN/OUT parameters (PostgreSQL 8.1)
•   Security



                                         26
Problem Areas
• Memory usage
• Performance?
• Stack handling




                           27
Build Options
• Builds with:
  • Sun JDK ≥ 1.4 (shared library + JAR)
  • GCJ ≥ 4.0 (shared library)
• Does not work with:
  • Kaffe
  • SableVM




                                           28
GCJ Issues
• Missing java.security implementation
• GCJ-based PL/Java installations are
  untrusted.




                                         29
Supported Platforms
• Linux (most architectures)
• Cygwin
• Windows (PostgreSQL 8.1/recent)

• More reports welcome!




                                    30
Compatibility
• vs. Oracle:
  • data type system not as good
  • trigger procedures not compatible (wrappers
    possible)
• vs. DB/2, Firebird, ...:
  • unknown




                                                  31
The Future
• Dynamic type system (SQL:2003)
• Work on SQL conformance and
  compatibility
• More work on J4SQL
• Cooperation with PL/J project




                                   32
Conclusion
•   PL/Java is stable today.
•   It is being used.
•   It is almost feature complete.
•   Get it now!




http://gborg.postgresql.org/project/pljava/projdisplay.php

                                                       33

More Related Content

What's hot (20)

Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406
Tim Bunce
 
FrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in FrostbiteFrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in Frostbite
Electronic Arts / DICE
 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in c
Meghna Roy
 
Triangle Visibility buffer
Triangle Visibility bufferTriangle Visibility buffer
Triangle Visibility buffer
Wolfgang Engel
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
Frank Chao
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
Mark Kilgard
 
New Integration Options with Postgres Enterprise Manager 8.0
New Integration Options with Postgres Enterprise Manager 8.0New Integration Options with Postgres Enterprise Manager 8.0
New Integration Options with Postgres Enterprise Manager 8.0
EDB
 
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
Philip Hammer
 
우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?
Arawn Park
 
How to set up opc with simatic net
How to set up opc with simatic netHow to set up opc with simatic net
How to set up opc with simatic net
hassanaagib
 
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Balwinder Kaur
 
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
Electronic Arts / DICE
 
System Calls
System CallsSystem Calls
System Calls
Anil Kumar Pugalia
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666
Tiago Sousa
 
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver OverheadOpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
Tristan Lorach
 
z/OS Communications Server Overview
z/OS Communications Server Overviewz/OS Communications Server Overview
z/OS Communications Server Overview
zOSCommserver
 
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla MahGS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
AMD Developer Central
 
PHPの関数実行とその計測
PHPの関数実行とその計測PHPの関数実行とその計測
PHPの関数実行とその計測
shinjiigarashi
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
GlobalLogic Ukraine
 
Hack.LU 2018 ARM IoT Firmware Emulation Workshop
Hack.LU 2018 ARM IoT Firmware Emulation WorkshopHack.LU 2018 ARM IoT Firmware Emulation Workshop
Hack.LU 2018 ARM IoT Firmware Emulation Workshop
Saumil Shah
 
Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406
Tim Bunce
 
FrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in FrostbiteFrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in Frostbite
Electronic Arts / DICE
 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in c
Meghna Roy
 
Triangle Visibility buffer
Triangle Visibility bufferTriangle Visibility buffer
Triangle Visibility buffer
Wolfgang Engel
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
Frank Chao
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
Mark Kilgard
 
New Integration Options with Postgres Enterprise Manager 8.0
New Integration Options with Postgres Enterprise Manager 8.0New Integration Options with Postgres Enterprise Manager 8.0
New Integration Options with Postgres Enterprise Manager 8.0
EDB
 
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
Philip Hammer
 
우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?
Arawn Park
 
How to set up opc with simatic net
How to set up opc with simatic netHow to set up opc with simatic net
How to set up opc with simatic net
hassanaagib
 
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Balwinder Kaur
 
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
Electronic Arts / DICE
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666
Tiago Sousa
 
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver OverheadOpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
Tristan Lorach
 
z/OS Communications Server Overview
z/OS Communications Server Overviewz/OS Communications Server Overview
z/OS Communications Server Overview
zOSCommserver
 
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla MahGS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
GS-4106 The AMD GCN Architecture - A Crash Course, by Layla Mah
AMD Developer Central
 
PHPの関数実行とその計測
PHPの関数実行とその計測PHPの関数実行とその計測
PHPの関数実行とその計測
shinjiigarashi
 
Hack.LU 2018 ARM IoT Firmware Emulation Workshop
Hack.LU 2018 ARM IoT Firmware Emulation WorkshopHack.LU 2018 ARM IoT Firmware Emulation Workshop
Hack.LU 2018 ARM IoT Firmware Emulation Workshop
Saumil Shah
 

Similar to PostgreSQL and PL/Java (20)

PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
S.Shayan Daneshvar
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
Reuven Lerner
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
David Wheeler
 
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
servanjervy
 
Techday2010 Postgresql9
Techday2010 Postgresql9Techday2010 Postgresql9
Techday2010 Postgresql9
Dan-Claudiu Dragoș
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf
Mustafa Keskin
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
InSync2011
 
Learning postgresql
Learning postgresqlLearning postgresql
Learning postgresql
DAVID RAUDALES
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
Mark Wong
 
Plpgsql internals
Plpgsql internalsPlpgsql internals
Plpgsql internals
Pavel Stěhule
 
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
trddarvai
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
Plpgsql russia-pgconf
Plpgsql russia-pgconfPlpgsql russia-pgconf
Plpgsql russia-pgconf
Pavel Stěhule
 
Postgres Plus Advanced Server 9.2新機能ご紹介
Postgres Plus Advanced Server 9.2新機能ご紹介Postgres Plus Advanced Server 9.2新機能ご紹介
Postgres Plus Advanced Server 9.2新機能ご紹介
Yuji Fujita
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slide
Tanu_Manu
 
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
Get PostgreSQL Server Programming - Second Edition Dar free all chaptersGet PostgreSQL Server Programming - Second Edition Dar free all chapters
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
raiyaalaiaya
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
Command Prompt., Inc
 
An evening with Postgresql
An evening with PostgresqlAn evening with Postgresql
An evening with Postgresql
Joshua Drake
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
David Wheeler
 
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
servanjervy
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf
Mustafa Keskin
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
InSync2011
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
Mark Wong
 
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
trddarvai
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
Postgres Plus Advanced Server 9.2新機能ご紹介
Postgres Plus Advanced Server 9.2新機能ご紹介Postgres Plus Advanced Server 9.2新機能ご紹介
Postgres Plus Advanced Server 9.2新機能ご紹介
Yuji Fujita
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slide
Tanu_Manu
 
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
Get PostgreSQL Server Programming - Second Edition Dar free all chaptersGet PostgreSQL Server Programming - Second Edition Dar free all chapters
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
raiyaalaiaya
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
Command Prompt., Inc
 
An evening with Postgresql
An evening with PostgresqlAn evening with Postgresql
An evening with Postgresql
Joshua Drake
 
Ad

More from Peter Eisentraut (20)

Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
Peter Eisentraut
 
Linux distribution for the cloud
Linux distribution for the cloudLinux distribution for the cloud
Linux distribution for the cloud
Peter Eisentraut
 
Most Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL FeaturesMost Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL Features
Peter Eisentraut
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
Peter Eisentraut
 
Porting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQLPorting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQL
Peter Eisentraut
 
PostgreSQL and XML
PostgreSQL and XMLPostgreSQL and XML
PostgreSQL and XML
Peter Eisentraut
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
Peter Eisentraut
 
PostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie DatenbankalternativePostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie Datenbankalternative
Peter Eisentraut
 
The Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future DevelopmentsThe Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future Developments
Peter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
Peter Eisentraut
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
Peter Eisentraut
 
PostgreSQL News
PostgreSQL NewsPostgreSQL News
PostgreSQL News
Peter Eisentraut
 
PostgreSQL News
PostgreSQL NewsPostgreSQL News
PostgreSQL News
Peter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
Peter Eisentraut
 
Docbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XMLDocbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XML
Peter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Peter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Peter Eisentraut
 
Spaß mit PostgreSQL
Spaß mit PostgreSQLSpaß mit PostgreSQL
Spaß mit PostgreSQL
Peter Eisentraut
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)
Peter Eisentraut
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
Peter Eisentraut
 
Linux distribution for the cloud
Linux distribution for the cloudLinux distribution for the cloud
Linux distribution for the cloud
Peter Eisentraut
 
Most Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL FeaturesMost Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL Features
Peter Eisentraut
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
Peter Eisentraut
 
Porting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQLPorting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQL
Peter Eisentraut
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
Peter Eisentraut
 
PostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie DatenbankalternativePostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie Datenbankalternative
Peter Eisentraut
 
The Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future DevelopmentsThe Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future Developments
Peter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
Peter Eisentraut
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
Peter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
Peter Eisentraut
 
Docbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XMLDocbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XML
Peter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Peter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Peter Eisentraut
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)
Peter Eisentraut
 
Ad

Recently uploaded (20)

War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Data Validation and System Interoperability
Data Validation and System InteroperabilityData Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Data Validation and System Interoperability
Data Validation and System InteroperabilityData Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 

PostgreSQL and PL/Java

  • 1. PostgreSQL and PL/Java Server-Side Functions in Java Peter Eisentraut [email protected]
  • 2. Agenda • Functions in PostgreSQL • Enter PL/Java • Features of PL/Java • Support and Compatibility • Outlook and Wrap-Up 2
  • 3. Defining a Function Example of an SQL function: CREATE FUNCTION add(int, int) RETURNS int LANGUAGE SQL AS 'SELECT $1 + $2;'; SELECT add(4, 5); add ----- 9 3
  • 4. Defining a Function Example of a C function: PG_FUNCTION_INFO_V1(funcname); Datum add(PG_FUNCTION_ARGS) { int32 a = PG_GETARG_INT32(0); int32 b = PG_GETARG_INT32(1); PG_RETURN_INT32(a + b); } 4
  • 5. Defining a Function Example of a C function, continued: gcc -fPIC -c file.c gcc -shared -o file.so file.o CREATE FUNCTION add(int, int) RETURNS int LANGUAGE C AS 'file.so', 'add'; 5
  • 6. Features of Functions • Overloading • Processing sets/tables • Caching options (deterministic/nondeterministic) • Execution privileges 6
  • 7. Advantages of Server-Side Functions • Encapsulation • Faster database access • Plan caching, inlining • Data validation through triggers • Side effects through triggers 7
  • 8. Functions as Building Blocks • Operators • Data types • Aggregate functions • Index access methods • Type casts • Character set conversions 8
  • 9. Procedural Languages • Choice of SQL vs. C quite limited • Solution: pluggable language handlers • Available languages: Tcl, PL/pgSQL, Perl, Ruby, Python, Shell, R, Java, PHP 9
  • 10. Procedural Language Example: PL/pgSQL CREATE FUNCTION logfunc(logtxt text) RETURNS timestamp AS ' DECLARE curtime timestamp; BEGIN curtime := ''now''; INSERT INTO logtable VALUES (logtxt, curtime); RETURN curtime; END; ' LANGUAGE plpgsql; 10
  • 11. Procedural Language Example: PL/Perl CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS ' if (($_TD->{new}{i} >= 100) || ($_TD->{new}{i} <= 0)) { return "SKIP"; # skip INSERT/UPDATE command } elsif ($_TD->{new}{v} ne "immortal") { $_TD->{new}{v} .= "(modified by trigger)"; return "MODIFY"; # modify row and run INSERT/UPDATE } else { return; # execute INSERT/UPDATE command } ' LANGUAGE plperl; 11
  • 12. Enter PL/Java • Developed by Thomas Hallgren • Stored procedures written in the Java language • Java the most popular (client) language for PostgreSQL 12
  • 13. Standardization SQL standard: ISO/IEC 9075-13:2003 SQL Routines and Types for the Java Programming Language ("SQL/JRT") (210 pages) driven by Oracle and IBM 13
  • 14. Timeline of PL/Java • Nov. 2000: first attempt with Kaffe 1.0.6 • Dec. 2003: PL/Java project launched • Jan. 2004: first alpha release • Jan. 2005: release 1.0.0 (for PG 7.4) • Apr. 2005: release 1.1.0 (for PG 8.0) • currently “stable” 14
  • 15. Concept • Write a Java class • Designate static method as entry point • Pack into JAR • Load JAR into database • Adjust classpath • Create function in PostgreSQL 15
  • 16. Simple Example: Code package com.example; public class Foo { static int add(int a, int b) { return a + b; } } 16
  • 17. Simple Example: Deployment javac com/example/Foo.java jar cf foo.jar com/example/Foo.class SELECT sqlj.install_jar('file:/home/peter/tmp/foo.jar', 'foo', false); SELECT sqlj.set_classpath('public', 'foo:bar:etc'); CREATE FUNCTION add(int, int) RETURNS int LANGUAGE java AS 'com.example.Foo.add'; 17
  • 18. Deployment Descriptor Optional way to integrate install/uninstall SQL statements into the JAR file: SQLActions[] = { "BEGIN INSTALL CREATE FUNCTION add(int, int) RETURNS int LANGUAGE java AS 'com.example.Foo.add'; END INSTALL", "BEGIN REMOVE DROP FUNCTION add(int, int); END REMOVE" } 18
  • 19. Configuration New parameters for postgresql.conf: custom_variable_classes = 'pljava' pljava.classpath = '/some/where/pljava.jar' pljava.statement_cache_size = 10 pljava.release_lingering_savepoints = true pljava.vmoptions = '-Xmx64M' pljava.debug = false 19
  • 20. Parameter Type Mapping Parameter types are mapped automatically: PostgreSQL Java boolean boolean shortint short int int bigint long real float double precision double varchar, text java.lang.String bytea byte[] date java.sql.Date time java.sql.Time timestamp java.sql.Timestamp other java.lang.String 20
  • 21. Composite Types CREATE TYPE compositeTest AS ( base integer, incbase integer, ctime timestamp ); CREATE FUNCTION useCompositeTest (compositeTest) RETURNS varchar AS 'foo.fee.Fum.useCompositeTest' LANGUAGE java; 21
  • 22. Composite Types Represented as java.sql.ResultSet with one row. public static String useCompositeTest(ResultSet compositeTest) throws SQLException { int base = compositeTest.getInt(1); int incbase = compositeTest.getInt(2); Timestamp ctime = compositeTest.getTimestamp(3); return "Base = "" + base + "", incbase = "" + incbase + "", ctime = "" + ctime + """; } 22
  • 23. Returning Sets CREATE FUNCTION getNames() RETURNS SETOF varchar AS 'Bar.getNames' LANGUAGE java; import java.util.Iterator; public class Bar { public static Iterator getNames() { ArrayList names = new ArrayList(); names.add("Lisa"); names.add("Bob"); names.add("Bill"); return names.iterator(); } } 23
  • 24. Built-in JDBC Driver • Prepare/execute queries • Query metadata • No transaction management (can use savepoints) Connection conn = DriverManager.getConnection("jdbc:default:connectio n"); 24
  • 25. Triggers static void moddatetime(TriggerData td) throws SQLException { if(td.isFiredForStatement()) throw new TriggerException(td, "can't process STATEMENT events"); if(td.isFiredAfter()) throw new TriggerException(td, "must be fired before event"); if(!td.isFiredByUpdate()) throw new TriggerException(td, "can only process UPDATE events"); ResultSet _new = td.getNew(); String[] args = td.getArguments(); if (args.length != 1) throw new TriggerException(td, "one argument was expected"); _new.updateTimestamp(args[0], new Timestamp(System.currentTimeMillis())); } 25
  • 26. Other Features • Exception handling • Logging • DatabaseMetaData • Multithreading • IN/OUT parameters (PostgreSQL 8.1) • Security 26
  • 27. Problem Areas • Memory usage • Performance? • Stack handling 27
  • 28. Build Options • Builds with: • Sun JDK ≥ 1.4 (shared library + JAR) • GCJ ≥ 4.0 (shared library) • Does not work with: • Kaffe • SableVM 28
  • 29. GCJ Issues • Missing java.security implementation • GCJ-based PL/Java installations are untrusted. 29
  • 30. Supported Platforms • Linux (most architectures) • Cygwin • Windows (PostgreSQL 8.1/recent) • More reports welcome! 30
  • 31. Compatibility • vs. Oracle: • data type system not as good • trigger procedures not compatible (wrappers possible) • vs. DB/2, Firebird, ...: • unknown 31
  • 32. The Future • Dynamic type system (SQL:2003) • Work on SQL conformance and compatibility • More work on J4SQL • Cooperation with PL/J project 32
  • 33. Conclusion • PL/Java is stable today. • It is being used. • It is almost feature complete. • Get it now! http://gborg.postgresql.org/project/pljava/projdisplay.php 33