├── .editorconfig ├── .github └── workflows │ └── build.yml ├── .gitignore ├── CMakeLists.txt ├── README.md ├── apidocs ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── org │ └── firebirdsql │ │ └── fbjava │ │ ├── CallableRoutineContext.html │ │ ├── Context.html │ │ ├── ExternalResultSet.html │ │ ├── FunctionContext.html │ │ ├── ProcedureContext.html │ │ ├── TriggerContext.Action.html │ │ ├── TriggerContext.Type.html │ │ ├── TriggerContext.html │ │ ├── Values.html │ │ ├── ValuesMetadata.html │ │ ├── class-use │ │ ├── CallableRoutineContext.html │ │ ├── Context.html │ │ ├── ExternalResultSet.html │ │ ├── FunctionContext.html │ │ ├── ProcedureContext.html │ │ ├── TriggerContext.Action.html │ │ ├── TriggerContext.Type.html │ │ ├── TriggerContext.html │ │ ├── Values.html │ │ └── ValuesMetadata.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── overview-tree.html ├── package-list ├── script.js └── stylesheet.css ├── bootstrap.bat ├── bootstrap.sh ├── copy-javadocs.sh ├── create-linux-tarball.sh ├── examples └── fbjava-example │ ├── README │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── firebirdsql │ │ │ └── fbjava │ │ │ └── examples │ │ │ └── fbjava_example │ │ │ ├── FbJdbc.java │ │ │ ├── FbLogger.java │ │ │ └── FbRegex.java │ │ └── resources │ │ └── logback.xml │ └── util │ ├── code.sql │ ├── createdb.bat │ ├── createdb.sh │ ├── database.sql │ ├── replace-jar.bat │ ├── replace-jar.sh │ └── security.sql ├── gen-cmake.bat ├── gen-cmake.sh ├── run-maven.bat ├── run-maven.sh └── src ├── etc ├── bin │ ├── fbjava-deployer.bat │ ├── fbjava-deployer.sh │ ├── install.sh │ ├── setenv.bat │ └── setenv.sh ├── conf │ ├── fbjava.conf │ └── jvm.args └── scripts │ └── java-security.sql ├── fbjava-impl ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── firebirdsql │ │ └── fbjava │ │ ├── Deployer.java │ │ └── impl │ │ ├── BlobConnection.java │ │ ├── CallableRoutineContextImpl.java │ │ ├── CallableThrowable.java │ │ ├── CloseableMemory.java │ │ ├── ContextImpl.java │ │ ├── DataType.java │ │ ├── DbClassLoader.java │ │ ├── DbPolicy.java │ │ ├── DbPrincipal.java │ │ ├── ExternalEngine.java │ │ ├── ExternalFunction.java │ │ ├── ExternalProcedure.java │ │ ├── ExternalResultSetWrapper.java │ │ ├── ExternalTrigger.java │ │ ├── FbClientLibrary.java │ │ ├── FbException.java │ │ ├── FunctionContextImpl.java │ │ ├── InternalContext.java │ │ ├── InternalDatabaseFactory.java │ │ ├── InternalFBConnection.java │ │ ├── InternalGDSFactoryPlugin.java │ │ ├── JnaUtil.java │ │ ├── Main.java │ │ ├── Pair.java │ │ ├── Parameter.java │ │ ├── PluginFactory.java │ │ ├── ProcedureContextImpl.java │ │ ├── Routine.java │ │ ├── ThrowableFunction.java │ │ ├── ThrowableRunnable.java │ │ ├── TriggerContextImpl.java │ │ ├── ValuesImpl.java │ │ └── ValuesMetadataImpl.java │ └── resources │ ├── META-INF │ └── services │ │ └── org.firebirdsql.gds.impl.GDSFactoryPlugin │ └── org │ └── firebirdsql │ └── fbjava │ ├── install.sql │ └── uninstall.sql ├── fbjava-tests ├── pom.xml └── src │ └── main │ └── java │ └── example │ ├── Functions.java │ ├── Procedures.java │ └── Triggers.java ├── fbjava ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── firebirdsql │ └── fbjava │ ├── CallableRoutineContext.java │ ├── Context.java │ ├── ExternalResultSet.java │ ├── FunctionContext.java │ ├── ProcedureContext.java │ ├── TriggerContext.java │ ├── Values.java │ └── ValuesMetadata.java ├── native └── fbjava │ ├── .gitignore │ ├── CMakeLists.txt │ ├── fbjava.cpp │ └── include │ ├── firebird │ ├── FirebirdInterface.idl │ ├── IdlFbInterfaces.h │ ├── Interface.h │ ├── Message.h │ ├── UdrCppEngine.h │ └── impl │ │ └── boost │ │ └── preprocessor │ │ ├── arithmetic │ │ ├── dec.hpp │ │ └── inc.hpp │ │ ├── cat.hpp │ │ ├── config │ │ └── config.hpp │ │ ├── control │ │ ├── expr_if.hpp │ │ ├── expr_iif.hpp │ │ ├── if.hpp │ │ └── iif.hpp │ │ ├── debug │ │ └── error.hpp │ │ ├── detail │ │ ├── auto_rec.hpp │ │ └── dmc │ │ │ └── auto_rec.hpp │ │ ├── facilities │ │ └── empty.hpp │ │ ├── logical │ │ └── bool.hpp │ │ ├── repetition │ │ ├── detail │ │ │ ├── dmc │ │ │ │ └── for.hpp │ │ │ ├── edg │ │ │ │ └── for.hpp │ │ │ ├── for.hpp │ │ │ └── msvc │ │ │ │ └── for.hpp │ │ └── for.hpp │ │ ├── seq │ │ ├── elem.hpp │ │ ├── for_each_i.hpp │ │ ├── seq.hpp │ │ └── size.hpp │ │ └── tuple │ │ ├── eat.hpp │ │ ├── elem.hpp │ │ └── rem.hpp │ ├── ib_util.h │ ├── ibase.h │ └── iberror.h └── pom.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | 7 | [*.yml] 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | os: [windows-2019, ubuntu-20.04] 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v1 17 | with: 18 | fetch-depth: 0 19 | 20 | - name: Firebird install (Linux) 21 | if: matrix.os == 'ubuntu-20.04' 22 | run: | 23 | sudo apt-get install libtommath1 24 | sudo ln -s /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 25 | wget -nv -O Firebird-3.0.6.33328-0.amd64.tar.gz "https://github.com/FirebirdSQL/firebird/releases/download/R3_0_6/Firebird-3.0.6.33328-0.amd64.tar.gz" 26 | tar xzf Firebird-3.0.6.33328-0.amd64.tar.gz 27 | (cd Firebird-3.0.6.33328-0.amd64; sudo ./install.sh -silent) 28 | 29 | - name: Firebird install (Windows) 30 | if: matrix.os == 'windows-2019' 31 | shell: cmd 32 | run: | 33 | set FB_ZIP=Firebird-3.0.6.33328-0_x64.zip 34 | powershell Invoke-WebRequest "https://github.com/FirebirdSQL/firebird/releases/download/R3_0_6/$env:FB_ZIP" -OutFile "$env:FB_ZIP" 35 | 7z x -oC:\Firebird %FB_ZIP% 36 | 37 | - name: Setup Java 38 | uses: actions/setup-java@v1 39 | with: 40 | java-version: '8' 41 | java-package: jdk 42 | 43 | - name: Build (Linux) 44 | if: matrix.os == 'ubuntu-20.04' 45 | run: | 46 | export FIREBIRD=/opt/firebird 47 | export PATH=$FIREBIRD/bin:$PATH 48 | export FIREBIRD_LOCK=/tmp/firebird-embedded 49 | FBJAVA_CONFIG=Release ./bootstrap.sh install 50 | ./create-linux-tarball.sh install fbjava-linux-x64.tar.gz 51 | tar xzf fbjava-linux-x64.tar.gz 52 | export FBJAVA_ROOT=/opt/fbjava 53 | sudo fbjava-linux-x64/install.sh $FBJAVA_ROOT 54 | ./run-maven.sh --batch-mode install -Dgpg.skip=true 55 | echo "include $FBJAVA_ROOT/conf/fbjava.conf" | sudo tee -a $FIREBIRD/plugins.conf > /dev/null 56 | sudo chown -R $USER $FBJAVA_ROOT 57 | cd $FBJAVA_ROOT/examples/fbjava-example 58 | mvn --batch-mode package 59 | ./util/createdb.sh 60 | echo "select get_system_property('os.name') from rdb\$database;" | isql -q db.fdb 61 | echo "select regex_replace('foo', '123 foo 456', 'bar') from rdb\$database;" | isql -q db.fdb 62 | echo "insert into employee values (1, 'Juliet Burke'); insert into employee values (2, 'Kate Austen'); select * from employee_local;" | isql -q db.fdb 63 | 64 | - name: Add msbuild to PATH (Windows) 65 | if: matrix.os == 'windows-2019' 66 | uses: microsoft/setup-msbuild@v1.0.2 67 | 68 | - name: Build (Windows) 69 | if: matrix.os == 'windows-2019' 70 | shell: cmd 71 | run: | 72 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=amd64 73 | set FIREBIRD=C:\Firebird 74 | set PATH=%FIREBIRD%;%PATH% 75 | set FBJAVA_CONFIG=Release 76 | call bootstrap.bat install 77 | set FBJAVA_ROOT=%CD%\install 78 | mkdir artifacts 79 | xcopy /e install artifacts\fbjava-windows-x64\ 80 | call run-maven.bat --batch-mode install -Dgpg.skip=true 81 | echo include %FBJAVA_ROOT%\conf\fbjava.conf >> %FIREBIRD%\plugins.conf 82 | cd %FBJAVA_ROOT%\examples\fbjava-example 83 | call mvn --batch-mode package 84 | call .\util\createdb.bat 85 | echo select get_system_property('os.name') from rdb$database; | isql -q db.fdb 86 | echo select regex_replace('foo', '123 foo 456', 'bar') from rdb$database; | isql -q db.fdb 87 | echo insert into employee values (1, 'Juliet Burke'); insert into employee values (2, 'Kate Austen'); select * from employee_local; | isql -q db.fdb 88 | 89 | - name: Upload (Linux) 90 | if: matrix.os == 'ubuntu-20.04' 91 | uses: actions/upload-artifact@main 92 | with: 93 | name: fbjava-linux-x64 94 | path: fbjava-linux-x64.tar.gz 95 | 96 | - name: Upload (Windows) 97 | if: matrix.os == 'windows-2019' 98 | uses: actions/upload-artifact@main 99 | with: 100 | name: fbjava-windows-x64 101 | path: artifacts 102 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | output/ 3 | target/ 4 | .settings/ 5 | .classpath 6 | .project 7 | *.log 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project("fbjava" CXX) 4 | 5 | if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") 6 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build.") 7 | endif() 8 | 9 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 10 | 11 | add_subdirectory("src/native/fbjava") 12 | -------------------------------------------------------------------------------- /apidocs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /apidocs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /apidocs/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Constant Field Values (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Constant Field Values

73 |

Contents

74 |
75 | 76 |
77 | 78 | 79 |
Skip navigation links
80 | 81 | 82 | 83 | 92 |
93 | 120 | 121 |

Copyright © 2020. All rights reserved.

122 | 123 | 124 | -------------------------------------------------------------------------------- /apidocs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Deprecated API

73 |

Contents

74 |
75 | 76 |
77 | 78 | 79 |
Skip navigation links
80 | 81 | 82 | 83 | 92 |
93 | 120 | 121 |

Copyright © 2020. All rights reserved.

122 | 123 | 124 | -------------------------------------------------------------------------------- /apidocs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | fbjava 1.0.0-beta-1 API 8 | 61 | 62 | 63 | 64 | 65 | 66 | <noscript> 67 | <div>JavaScript is disabled on your browser.</div> 68 | </noscript> 69 | <h2>Frame Alert</h2> 70 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/firebirdsql/fbjava/package-summary.html">Non-frame version</a>.</p> 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /apidocs/org/firebirdsql/fbjava/class-use/ExternalResultSet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Interface org.firebirdsql.fbjava.ExternalResultSet (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Uses of Interface
org.firebirdsql.fbjava.ExternalResultSet

73 |
74 |
No usage of org.firebirdsql.fbjava.ExternalResultSet
75 | 76 |
77 | 78 | 79 |
Skip navigation links
80 | 81 | 82 | 83 | 92 |
93 | 120 | 121 |

Copyright © 2020. All rights reserved.

122 | 123 | 124 | -------------------------------------------------------------------------------- /apidocs/org/firebirdsql/fbjava/class-use/FunctionContext.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Interface org.firebirdsql.fbjava.FunctionContext (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Uses of Interface
org.firebirdsql.fbjava.FunctionContext

73 |
74 |
75 | 101 |
102 | 103 |
104 | 105 | 106 |
Skip navigation links
107 | 108 | 109 | 110 | 119 |
120 | 147 | 148 |

Copyright © 2020. All rights reserved.

149 | 150 | 151 | -------------------------------------------------------------------------------- /apidocs/org/firebirdsql/fbjava/class-use/ProcedureContext.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Interface org.firebirdsql.fbjava.ProcedureContext (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Uses of Interface
org.firebirdsql.fbjava.ProcedureContext

73 |
74 |
75 | 101 |
102 | 103 |
104 | 105 | 106 |
Skip navigation links
107 | 108 | 109 | 110 | 119 |
120 | 147 | 148 |

Copyright © 2020. All rights reserved.

149 | 150 | 151 | -------------------------------------------------------------------------------- /apidocs/org/firebirdsql/fbjava/class-use/TriggerContext.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Interface org.firebirdsql.fbjava.TriggerContext (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Uses of Interface
org.firebirdsql.fbjava.TriggerContext

73 |
74 |
75 | 101 |
102 | 103 |
104 | 105 | 106 |
Skip navigation links
107 | 108 | 109 | 110 | 119 |
120 | 147 | 148 |

Copyright © 2020. All rights reserved.

149 | 150 | 151 | -------------------------------------------------------------------------------- /apidocs/org/firebirdsql/fbjava/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.firebirdsql.fbjava (fbjava 1.0.0-beta-1 API) 8 | 9 | 10 | 11 | 12 |

org.firebirdsql.fbjava

13 |
14 |

Interfaces

15 | 25 |

Enums

26 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /apidocs/package-list: -------------------------------------------------------------------------------- 1 | org.firebirdsql.fbjava 2 | -------------------------------------------------------------------------------- /apidocs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bootstrap.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | if "%1"=="" ( 5 | echo "Syntax: %0 " 1>&2 6 | exit /b 1 7 | ) 8 | 9 | set THIS_DIR=%~dp0 10 | 11 | set BASE_DIR=%THIS_DIR% 12 | for /f %%i in ("%1") do set TARGET_DIR=%%~fi 13 | 14 | REM May be set by caller with values "Release" (default) or "Debug". 15 | if not defined FBJAVA_CONFIG set FBJAVA_CONFIG=Release 16 | 17 | if exist "%TARGET_DIR%\nul" ( 18 | echo "Install directory should not exist" 1>&2 19 | exit /b 1 20 | ) 21 | 22 | REM FIXME: Can we use mklink when FBJAVA_LINK=1 ? 23 | set CP=copy 24 | set CPR=xcopy /e 25 | 26 | cd "%BASE_DIR%" 27 | 28 | if exist "build\nul" ( 29 | rd build /s 30 | ) 31 | 32 | call run-maven.bat --batch-mode clean package dependency:copy-dependencies javadoc:javadoc 33 | call gen-cmake.bat %FBJAVA_CONFIG% 34 | 35 | msbuild -p:Configuration=%FBJAVA_CONFIG% build/fbjava.sln 36 | 37 | mkdir ^ 38 | "%TARGET_DIR%\bin" ^ 39 | "%TARGET_DIR%\conf" ^ 40 | "%TARGET_DIR%\jar" ^ 41 | "%TARGET_DIR%\docs" ^ 42 | "%TARGET_DIR%\lib" ^ 43 | "%TARGET_DIR%\scripts" ^ 44 | "%TARGET_DIR%\examples" 45 | 46 | %CP% "%BASE_DIR%\README.md" "%TARGET_DIR%" 47 | %CP% "%BASE_DIR%\src\etc\bin\setenv.bat" "%TARGET_DIR%\bin" 48 | %CP% "%BASE_DIR%\src\etc\bin\fbjava-deployer.bat" "%TARGET_DIR%\bin" 49 | %CP% "%BASE_DIR%\build\java\fbjava\*.jar" "%TARGET_DIR%\jar" 50 | %CP% "%BASE_DIR%\build\java\fbjava-impl\*.jar" "%TARGET_DIR%\jar" 51 | %CP% "%BASE_DIR%\build\java\fbjava-impl\dependency\*.jar" "%TARGET_DIR%\jar" 52 | %CPR% "%BASE_DIR%\build\java\fbjava\site\apidocs" "%TARGET_DIR%\docs" 53 | 54 | %CP% "%BASE_DIR%\build\src\native\fbjava\%FBJAVA_CONFIG%\libfbjava.dll" "%TARGET_DIR%\lib" 55 | 56 | %CP% "%BASE_DIR%\src\fbjava-impl\src\main\resources\org\firebirdsql\fbjava\*.sql" "%TARGET_DIR%\scripts" 57 | %CP% "%BASE_DIR%\src\etc\conf\fbjava.conf" "%TARGET_DIR%\conf" 58 | %CP% "%BASE_DIR%\src\etc\conf\jvm.args" "%TARGET_DIR%\conf" 59 | %CP% "%BASE_DIR%\src\etc\scripts\java-security.sql" "%TARGET_DIR%\scripts" 60 | %CPR% "%BASE_DIR%\examples\*" "%TARGET_DIR%\examples" 61 | 62 | if exist "%TARGET_DIR%\conf\java-security.fdb" ( 63 | del "%TARGET_DIR%\conf\java-security.fdb" 64 | ) 65 | 66 | echo create database '%TARGET_DIR%\conf\java-security.fdb' default character set utf8; | isql -q -user sysdba 67 | isql "%TARGET_DIR%\conf\java-security.fdb" -q -user sysdba -i "%TARGET_DIR%\scripts\java-security.sql" 68 | 69 | REM Transform file name to lower case. 70 | ren "%TARGET_DIR%\conf\java-security.fdb" java-security.fdb 71 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$#" != 1 ]; then 4 | echo "Syntax: $0 " 1>&2 5 | exit 1 6 | fi 7 | 8 | set -e 9 | 10 | THIS_DIR=`readlink -f $0` 11 | THIS_DIR=`dirname $THIS_DIR` 12 | 13 | BASE_DIR=$THIS_DIR 14 | TARGET_DIR=`readlink -f "$1"` 15 | 16 | # May be set by caller with values "Release" (default) or "Debug". 17 | FBJAVA_CONFIG="${FBJAVA_CONFIG:-Release}" 18 | 19 | if [ -d "$TARGET_DIR" ]; then 20 | echo "Install directory should not exist" 1>&2 21 | exit 1 22 | fi 23 | 24 | SHRLIB_EXT=so 25 | SHELL_EXT=sh 26 | 27 | if [ "$FBJAVA_LINK" = "1" ]; then 28 | CP="ln -sf" 29 | CPR="ln -sf" 30 | else 31 | CP=cp 32 | CPR="cp -r" 33 | fi 34 | 35 | cd "$BASE_DIR" 36 | 37 | if [ -d build ]; then 38 | rm -r build 39 | fi 40 | 41 | ./run-maven.sh --batch-mode clean package dependency:copy-dependencies javadoc:javadoc 42 | ./gen-cmake.sh $FBJAVA_CONFIG 43 | 44 | (cd build; make TARGET=$FBJAVA_CONFIG) 45 | 46 | mkdir -p \ 47 | "$TARGET_DIR/bin" \ 48 | "$TARGET_DIR/conf" \ 49 | "$TARGET_DIR/jar" \ 50 | "$TARGET_DIR/docs" \ 51 | "$TARGET_DIR/lib" \ 52 | "$TARGET_DIR/scripts" \ 53 | "$TARGET_DIR/examples" 54 | 55 | $CP $BASE_DIR/README.md "$TARGET_DIR" 56 | $CP $BASE_DIR/src/etc/bin/setenv.$SHELL_EXT "$TARGET_DIR/bin" 57 | $CP $BASE_DIR/src/etc/bin/fbjava-deployer.$SHELL_EXT "$TARGET_DIR/bin" 58 | $CP $BASE_DIR/build/java/fbjava/*.jar "$TARGET_DIR/jar" 59 | $CP $BASE_DIR/build/java/fbjava-impl/*.jar "$TARGET_DIR/jar" 60 | $CP $BASE_DIR/build/java/fbjava-impl/dependency/*.jar "$TARGET_DIR/jar" 61 | $CPR $BASE_DIR/build/java/fbjava/site/apidocs "$TARGET_DIR/docs" 62 | 63 | $CP $BASE_DIR/build/lib/libfbjava.$SHRLIB_EXT "$TARGET_DIR/lib" 64 | 65 | $CP $BASE_DIR/src/fbjava-impl/src/main/resources/org/firebirdsql/fbjava/*.sql "$TARGET_DIR/scripts" 66 | cp $BASE_DIR/src/etc/conf/fbjava.conf "$TARGET_DIR/conf" 67 | cp $BASE_DIR/src/etc/conf/jvm.args "$TARGET_DIR/conf" 68 | $CP $BASE_DIR/src/etc/scripts/java-security.sql "$TARGET_DIR/scripts" 69 | $CPR $BASE_DIR/examples/* "$TARGET_DIR/examples" 70 | 71 | if [ "$FBJAVA_LINK" != "1" ]; then 72 | strip "$TARGET_DIR/lib/"*.$SHRLIB_EXT 73 | fi 74 | 75 | if [ -f "$TARGET_DIR/conf/java-security.fdb" ]; then 76 | rm "$TARGET_DIR/conf/java-security.fdb" 77 | fi 78 | 79 | echo "create database '$TARGET_DIR/conf/java-security.fdb' default character set utf8;" | isql -q -user sysdba 80 | isql "$TARGET_DIR/conf/java-security.fdb" -q -user sysdba -i "$TARGET_DIR/scripts/java-security.sql" 81 | -------------------------------------------------------------------------------- /copy-javadocs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | THIS_DIR=`readlink -f $0` 5 | THIS_DIR=`dirname $THIS_DIR` 6 | 7 | if [ "$OS" = "Windows_NT" ]; then 8 | THIS_DIR=`echo "$THIS_DIR" | tr \\\\ /` 9 | fi 10 | 11 | BASE_DIR=$THIS_DIR 12 | 13 | cd $BASE_DIR 14 | 15 | ./run-maven.sh --projects fbjava javadoc:javadoc 16 | 17 | rm -rf apidocs 18 | cp -rf build/java/fbjava/site/apidocs $BASE_DIR 19 | -------------------------------------------------------------------------------- /create-linux-tarball.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | THIS_DIR=`readlink -f $0` 5 | THIS_DIR=`dirname $THIS_DIR` 6 | 7 | if [ "$#" != 2 ]; then 8 | echo "Syntax: $0 " 9 | exit 1 10 | fi 11 | 12 | INSTALL_DIR=`readlink -f $1` 13 | TARGET_FILE=`readlink -f $2` 14 | 15 | BASE_NAME=`basename $TARGET_FILE` 16 | BASE_NAME=${BASE_NAME%.tar.gz} 17 | 18 | if [ ! -f $INSTALL_DIR/conf/java-security.fdb ]; then 19 | echo "Invalid installation directory" 1>&2 20 | exit 1 21 | fi 22 | 23 | TEMP_DIR=`mktemp -d` 24 | TARGET_DIR=$TEMP_DIR/$BASE_NAME/temp 25 | 26 | mkdir -p $TARGET_DIR 27 | cp -rf $INSTALL_DIR/* $TARGET_DIR 28 | 29 | # Set file permissions 30 | find $TARGET_DIR -type d -exec chmod 755 {} \; 31 | find $TARGET_DIR -type f -exec chmod 444 {} \; 32 | chmod +x $TARGET_DIR/bin/fbjava-deployer.sh $TARGET_DIR/examples/fbjava-example/util/*.sh 33 | chmod 660 $TARGET_DIR/conf/java-security.fdb 34 | find $TARGET_DIR/examples -type f -exec chmod +w {} \; 35 | find $TARGET_DIR/lib -type f -exec chmod 555 {} \; 36 | 37 | cd $TARGET_DIR 38 | 39 | tar czvf ../buildroot.tar.gz --owner=root --group=root . 40 | 41 | cd .. 42 | rm -rf temp 43 | 44 | cp $THIS_DIR/src/etc/bin/install.sh . 45 | 46 | cd .. 47 | tar czvf $TARGET_FILE --owner=root --group=root $BASE_NAME/* 48 | 49 | rm -rf $TEMP_DIR 50 | -------------------------------------------------------------------------------- /examples/fbjava-example/README: -------------------------------------------------------------------------------- 1 | ================================= 2 | Example project for FB/Java 3 | ================================= 4 | 5 | Prerequisites 6 | ============= 7 | 8 | Java SE Development Kit 8 9 | Apache Maven (http://maven.apache.org) 10 | 11 | 12 | Preparing 13 | ========= 14 | 15 | Make sure JAVA_HOME is correctly defined and points to a Java of the same architecture (32 or 64 16 | bit) of Firebird. 17 | 18 | Set FIREBIRD environment variable. 19 | 20 | Set FBJAVA_ROOT environment variable. 21 | 22 | Go to this example's root directory. 23 | 24 | Run mvn package 25 | 26 | Run util/createdb.{sh,bat} script. 27 | 28 | Optionally create a database named employee in PostgreSQL with user name postgres and password 29 | postgres. 30 | 31 | Open the postgres employee database, create this table and insert some records. 32 | create table employee (id integer, name varchar(60)); 33 | 34 | 35 | Testing 36 | ======= 37 | 38 | Connect to db.fdb. Some things to play with: 39 | 40 | -- Lets see what Java says about our OS name, directly calling a standard method: 41 | select get_system_property('os.name') from rdb$database; 42 | 43 | -- Lets call a method that we created: 44 | select regex_replace('foo', '123 foo 456', 'bar') from rdb$database; 45 | 46 | -- INSERT/UPDATE/DELETE on the employee table. All actions will be logged in db.log file. 47 | insert into employee values (1, 'Juliet Burke'); 48 | insert into employee values (2, 'Kate Austen'); 49 | insert into employee values (3, 'John Locke'); 50 | 51 | -- This is dumb example, but you may use same concept to make cross database queries. 52 | select * from employee_local; 53 | 54 | -- This is same concept and implementation, but read data from the postgres database! 55 | select * from employee_pgsql; 56 | 57 | -- You can now open util/code.sql and see how the postgres query is created. Create another SP based 58 | -- on a Firebird database just replacing jdbc:postgresql:employee|postgres|postgres by 59 | -- jdbc:firebirdsql:database|user|password 60 | 61 | -- After change .java files, run mvn package and util/replace-jar.{sh,bat} script. 62 | 63 | -- Now you can do queries with multiple external datasources, of different DBMSs! 64 | 65 | select * from employee_local 66 | union all 67 | select * from employee_pgsql; 68 | 69 | select * 70 | from employee_local el 71 | join employee_pgsql ep 72 | on ep.id = el.id; 73 | 74 | insert into employee 75 | select * from employee_pgsql; 76 | -------------------------------------------------------------------------------- /examples/fbjava-example/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | org.firebirdsql.fbjava 6 | fbjava-example 7 | jar 8 | 1.0.0-beta-1 9 | fbjava-example 10 | 11 | 12 | 13 | UTF-8 14 | 1.8 15 | 16 | 1.0.0-beta-1 17 | 1.7.13 18 | 1.3.12 19 | 2.2-beta-3 20 | 8.3-603.jdbc4 21 | 22 | 23 | 24 | 25 | org.firebirdsql.fbjava 26 | fbjava 27 | ${fbjava.version} 28 | provided 29 | 30 | 31 | 32 | org.slf4j 33 | slf4j-api 34 | ${slf4j.version} 35 | 36 | 37 | 38 | ch.qos.logback 39 | logback-classic 40 | ${logback.version} 41 | 42 | 43 | 44 | postgresql 45 | postgresql 46 | ${postgresql.version} 47 | 48 | 49 | 50 | 51 | 52 | 53 | src/main/resources 54 | true 55 | 56 | 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-compiler-plugin 62 | 3.8.1 63 | 64 | 1.8 65 | 1.8 66 | 67 | 68 | 69 | 70 | org.apache.maven.plugins 71 | maven-dependency-plugin 72 | 3.1.2 73 | 74 | 75 | copy-dependencies 76 | package 77 | 78 | copy-dependencies 79 | 80 | 81 | provided 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /examples/fbjava-example/src/main/java/org/firebirdsql/fbjava/examples/fbjava_example/FbJdbc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.examples.fbjava_example; 20 | 21 | import java.sql.Connection; 22 | import java.sql.DriverManager; 23 | import java.sql.PreparedStatement; 24 | import java.sql.ResultSet; 25 | import java.sql.SQLException; 26 | import java.util.StringTokenizer; 27 | 28 | import org.firebirdsql.fbjava.ExternalResultSet; 29 | import org.firebirdsql.fbjava.ProcedureContext; 30 | import org.firebirdsql.fbjava.Values; 31 | import org.firebirdsql.fbjava.ValuesMetadata; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | 36 | /** 37 | * @author Adriano dos Santos Fernandes 38 | */ 39 | public class FbJdbc 40 | { 41 | private static final Logger log = LoggerFactory.getLogger(FbJdbc.class); 42 | 43 | static 44 | { 45 | try 46 | { 47 | Class.forName("org.postgresql.Driver"); 48 | } 49 | catch (ClassNotFoundException e) 50 | { 51 | log.warn("Cannot load org.postgresql.Driver", e); 52 | } 53 | } 54 | 55 | public static ExternalResultSet executeQuery() throws Exception 56 | { 57 | final ProcedureContext context = ProcedureContext.get(); 58 | return new ExternalResultSet() { 59 | ValuesMetadata outMetadata = context.getOutputMetadata(); 60 | Values outValues = context.getOutputValues(); 61 | int count = outMetadata.getParameterCount(); 62 | Connection conn; 63 | PreparedStatement stmt; 64 | ResultSet rs; 65 | 66 | { 67 | StringTokenizer tokenizer = new StringTokenizer(context.getNameInfo(), "|"); 68 | 69 | String uri = tokenizer.nextToken(); 70 | String user = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; 71 | String password = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; 72 | 73 | conn = DriverManager.getConnection(uri, user, password); 74 | try 75 | { 76 | StringBuilder sb = new StringBuilder("select "); 77 | 78 | for (int i = 0; i < count; ++i) 79 | { 80 | if (i != 0) 81 | sb.append(", "); 82 | sb.append("x." + outMetadata.getName(i + 1)); 83 | } 84 | 85 | sb.append(" from (" + context.getBody() + ") x"); 86 | 87 | stmt = conn.prepareStatement(sb.toString()); 88 | rs = stmt.executeQuery(); 89 | } 90 | catch (Exception e) 91 | { 92 | close(); 93 | throw e; 94 | } 95 | } 96 | 97 | @Override 98 | public void close() 99 | { 100 | try 101 | { 102 | if (rs != null) 103 | rs.close(); 104 | 105 | if (stmt != null) 106 | stmt.close(); 107 | 108 | if (conn != null) 109 | conn.close(); 110 | } 111 | catch (SQLException e) 112 | { 113 | log.error("Error closing the ExternalResultSet", e); 114 | } 115 | } 116 | 117 | @Override 118 | public boolean fetch() throws Exception 119 | { 120 | if (!rs.next()) 121 | return false; 122 | 123 | for (int i = 0; i < count; ++i) 124 | { 125 | Object obj = rs.getObject(i + 1); 126 | 127 | if (obj instanceof Number) 128 | obj = rs.getBigDecimal(i + 1); 129 | 130 | outValues.setObject(i + 1, obj); 131 | } 132 | 133 | return true; 134 | } 135 | }; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /examples/fbjava-example/src/main/java/org/firebirdsql/fbjava/examples/fbjava_example/FbLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.examples.fbjava_example; 20 | 21 | import java.sql.SQLException; 22 | 23 | import org.firebirdsql.fbjava.TriggerContext; 24 | import org.firebirdsql.fbjava.Values; 25 | import org.firebirdsql.fbjava.ValuesMetadata; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | 30 | /** 31 | * @author Adriano dos Santos Fernandes 32 | */ 33 | public class FbLogger 34 | { 35 | private static final Logger log = LoggerFactory.getLogger(FbLogger.class); 36 | private static final String NEWLINE = System.getProperty("line.separator"); 37 | 38 | public static void info() throws SQLException 39 | { 40 | TriggerContext context = TriggerContext.get(); 41 | 42 | String msg = "Table: " + context.getTableName() + 43 | "; Type: " + context.getType() + 44 | "; Action: " + context.getAction() + 45 | valuesToStr(context.getFieldsMetadata(), context.getOldValues(), NEWLINE + "OLD:" + NEWLINE) + 46 | valuesToStr(context.getFieldsMetadata(), context.getNewValues(), NEWLINE + "NEW:" + NEWLINE); 47 | 48 | log.info(msg); 49 | } 50 | 51 | private static String valuesToStr(ValuesMetadata metadata, Values values, String label) throws SQLException 52 | { 53 | if (values == null) 54 | return ""; 55 | 56 | StringBuilder sb = new StringBuilder(label); 57 | 58 | for (int i = 1, count = metadata.getParameterCount(); i <= count; ++i) 59 | sb.append(metadata.getName(i) + ": " + values.getObject(i) + NEWLINE); 60 | 61 | return sb.toString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /examples/fbjava-example/src/main/java/org/firebirdsql/fbjava/examples/fbjava_example/FbRegex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.examples.fbjava_example; 20 | 21 | 22 | /** 23 | * @author Adriano dos Santos Fernandes 24 | */ 25 | public class FbRegex 26 | { 27 | public static String replace(String regex, String str, String replacement) 28 | { 29 | return str.replaceAll(regex, replacement); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/fbjava-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${basedir}/db.log 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss},%p %m%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/code.sql: -------------------------------------------------------------------------------- 1 | create or alter trigger employee_log_bdiu before delete or insert or update on employee 2 | external name 'org.firebirdsql.fbjava.examples.fbjava_example.FbLogger.info()' 3 | engine java; 4 | 5 | create or alter trigger employee_log_adiu after delete or insert or update on employee 6 | external name 'org.firebirdsql.fbjava.examples.fbjava_example.FbLogger.info()' 7 | engine java; 8 | 9 | create or alter function get_system_property ( 10 | name varchar(60) 11 | ) returns varchar(60) 12 | external name 'java.lang.System.getProperty(String)' 13 | engine java; 14 | 15 | create or alter function regex_replace ( 16 | regex varchar(60), 17 | str varchar(60), 18 | replacement varchar(60) 19 | ) returns varchar(60) 20 | external name 'org.firebirdsql.fbjava.examples.fbjava_example.FbRegex.replace(String, 21 | String, String)' 22 | engine java; 23 | 24 | create or alter procedure employee_local ( 25 | dummy integer = 1 -- Firebird 3.0.0 has a bug with external procedures without parameters 26 | ) returns ( 27 | id type of column employee.id, 28 | name type of column employee.name 29 | ) 30 | external name 'org.firebirdsql.fbjava.examples.fbjava_example.FbJdbc.executeQuery() 31 | !jdbc:default:connection' 32 | engine java 33 | as 'select * from employee'; 34 | 35 | create or alter procedure employee_pgsql ( 36 | dummy integer = 1 -- Firebird 3.0.0 has a bug with external procedures without parameters 37 | ) returns ( 38 | id type of column employee.id, 39 | name type of column employee.name 40 | ) 41 | external name 'org.firebirdsql.fbjava.examples.fbjava_example.FbJdbc.executeQuery() 42 | !jdbc:postgresql:employee|postgres|postgres' 43 | engine java 44 | as 'select * from employee'; 45 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/createdb.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | set FB_BIN=%FIREBIRD% 5 | set FBJAVA_BIN=%FBJAVA_ROOT%\bin 6 | 7 | set THIS_DIR=%~dp0 8 | 9 | pushd %THIS_DIR%.. 10 | set EXAMPLES_ROOT=%cd% 11 | popd 12 | 13 | REM Configure some permissions necessary for our test. 14 | 15 | %FB_BIN%\isql -q -user sysdba %FBJAVA_ROOT%\conf\java-security.fdb -i util\security.sql 16 | echo execute procedure setup_fbjava_example('%EXAMPLES_ROOT%', '\'); | %FB_BIN%\isql -q -user sysdba %FBJAVA_ROOT%\conf\java-security.fdb 17 | echo drop procedure setup_fbjava_example; | %FB_BIN%\isql -q -user sysdba %FBJAVA_ROOT%\conf\java-security.fdb 18 | 19 | REM Create an empty database. 20 | echo create database '%EXAMPLES_ROOT%\db.fdb' default character set utf8; | %FB_BIN%\isql -q 21 | 22 | REM Install the Java plugin. 23 | call %FBJAVA_BIN%\fbjava-deployer.bat --database embedded:%EXAMPLES_ROOT%\db.fdb ^ 24 | --install-plugin 25 | 26 | REM Store our JAR dependencies on the database. 27 | for %%i in (%EXAMPLES_ROOT%\target\dependency\*.jar) do ( 28 | call %FBJAVA_BIN%\fbjava-deployer.bat --database embedded:%EXAMPLES_ROOT%\db.fdb ^ 29 | --install-jar %%i %%~xni 30 | ) 31 | 32 | REM Store our JAR on the database. 33 | call %FBJAVA_BIN%\fbjava-deployer.bat --database embedded:%EXAMPLES_ROOT%\db.fdb ^ 34 | --install-jar %EXAMPLES_ROOT%\target\fbjava-example-1.0.0-beta-1.jar fbjava-example-1.0.0-beta-1.jar 35 | 36 | REM Create the metadata. 37 | %FB_BIN%\isql -q %EXAMPLES_ROOT%\db.fdb -i %THIS_DIR%\database.sql 38 | %FB_BIN%\isql -q %EXAMPLES_ROOT%\db.fdb -i %THIS_DIR%\code.sql 39 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/createdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FB_BIN=$FIREBIRD/bin 4 | FBJAVA_BIN=$FBJAVA_ROOT/bin 5 | 6 | THIS_DIR=`readlink -f $0` 7 | THIS_DIR=`dirname $THIS_DIR` 8 | 9 | EXAMPLES_ROOT=$THIS_DIR/.. 10 | EXAMPLES_ROOT=`readlink -f $EXAMPLES_ROOT` 11 | 12 | # Configure some permissions necessary for our test. 13 | 14 | $FB_BIN/isql -q -user sysdba $FBJAVA_ROOT/conf/java-security.fdb -i util/security.sql 15 | echo "execute procedure setup_fbjava_example('$EXAMPLES_ROOT', '/');" | $FB_BIN/isql -q -user sysdba $FBJAVA_ROOT/conf/java-security.fdb 16 | echo "drop procedure setup_fbjava_example;" | $FB_BIN/isql -q -user sysdba $FBJAVA_ROOT/conf/java-security.fdb 17 | 18 | # Create an empty database. 19 | echo "create database '$EXAMPLES_ROOT/db.fdb' default character set utf8;" | $FB_BIN/isql -q 20 | 21 | # Install the Java plugin. 22 | $FBJAVA_BIN/fbjava-deployer.sh --database embedded:$EXAMPLES_ROOT/db.fdb \ 23 | --install-plugin 24 | 25 | # Store our JAR dependencies on the database. 26 | for line in `find $EXAMPLES_ROOT/target/dependency -name '*.jar' -print |xargs -0 echo` 27 | do 28 | $FBJAVA_BIN/fbjava-deployer.sh --database embedded:$EXAMPLES_ROOT/db.fdb \ 29 | --install-jar $line `basename $line` 30 | done 31 | 32 | # Store our JAR on the database. 33 | $FBJAVA_BIN/fbjava-deployer.sh --database embedded:$EXAMPLES_ROOT/db.fdb \ 34 | --install-jar $EXAMPLES_ROOT/target/fbjava-example-1.0.0-beta-1.jar fbjava-example-1.0.0-beta-1.jar 35 | 36 | # Create the metadata. 37 | $FB_BIN/isql -q $EXAMPLES_ROOT/db.fdb -i $THIS_DIR/database.sql 38 | $FB_BIN/isql -q $EXAMPLES_ROOT/db.fdb -i $THIS_DIR/code.sql 39 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/database.sql: -------------------------------------------------------------------------------- 1 | create domain d_id as bigint not null; 2 | create domain d_name as varchar(60) character set utf8 not null; 3 | 4 | create table employee ( 5 | id d_id, 6 | name d_name 7 | ); 8 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/replace-jar.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | set FB_BIN=%FIREBIRD% 5 | set FBJAVA_BIN=%FBJAVA_ROOT%\bin 6 | 7 | set THIS_DIR=%~dp0 8 | 9 | set EXAMPLES_ROOT=%THIS_DIR%.. 10 | 11 | REM Replace our JAR. 12 | call %FBJAVA_BIN%\fbjava-deployer.bat --database embedded:%EXAMPLES_ROOT%\db.fdb ^ 13 | --replace-jar %EXAMPLES_ROOT%\target\fbjava-example-1.0.0-beta-1.jar fbjava-example-1.0.0-beta-1.jar 14 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/replace-jar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FB_BIN=$FIREBIRD/bin 4 | FBJAVA_BIN=$FBJAVA_ROOT/bin 5 | 6 | THIS_DIR=`readlink -f $0` 7 | THIS_DIR=`dirname $THIS_DIR` 8 | 9 | EXAMPLES_ROOT=$THIS_DIR/.. 10 | EXAMPLES_ROOT=`readlink -f $EXAMPLES_ROOT` 11 | 12 | # Replace our JAR. 13 | $FBJAVA_BIN/fbjava-deployer.sh --database embedded:$EXAMPLES_ROOT/db.fdb \ 14 | --replace-jar $EXAMPLES_ROOT/target/fbjava-example-1.0.0-beta-1.jar fbjava-example-1.0.0-beta-1.jar 15 | -------------------------------------------------------------------------------- /examples/fbjava-example/util/security.sql: -------------------------------------------------------------------------------- 1 | set term !; 2 | 3 | create or alter procedure setup_fbjava_example ( 4 | root varchar(512), 5 | separator char(1) 6 | ) 7 | as 8 | declare function esc(i varchar(512)) returns varchar(512) 9 | as 10 | begin 11 | return replace(i, '-', '&-'); 12 | end 13 | 14 | declare pergro_id type of column permission_group.id; 15 | begin 16 | merge into permission_group 17 | using rdb$database 18 | on name = 'fbjava-example' 19 | when matched then 20 | update set name = name 21 | when not matched then 22 | insert (id, name) values (next value for seq_permission_group, 'fbjava-example') 23 | returning new.id into pergro_id; 24 | 25 | -- Read permission in the directory. 26 | update or insert into permission (permission_group, class_name, arg1, arg2) 27 | values (:pergro_id, 'java.io.FilePermission', :root, 'read') 28 | matching (permission_group, class_name, arg1, arg2); 29 | 30 | -- Write permission in the log file. 31 | update or insert into permission (permission_group, class_name, arg1, arg2) 32 | values (:pergro_id, 'java.io.FilePermission', :root || :separator || 'db.log', 'write') 33 | matching (permission_group, class_name, arg1, arg2); 34 | 35 | -- Allow connections to localhost, to interact with the postgresql server. 36 | update or insert into permission (permission_group, class_name, arg1, arg2) 37 | values (:pergro_id, 'java.net.SocketPermission', 'localhost', 'connect') 38 | matching (permission_group, class_name, arg1, arg2); 39 | 40 | update or insert into permission_group_grant 41 | (permission_group, database_pattern, grantee_type, grantee_pattern) 42 | values (:pergro_id, esc(:root || :separator || 'db.fdb'), 'USER', '%') 43 | matching (permission_group); 44 | end! 45 | 46 | set term ;! 47 | -------------------------------------------------------------------------------- /gen-cmake.bat: -------------------------------------------------------------------------------- 1 | cmake -S . -B build -DCMAKE_BUILD_TYPE=%1 2 | -------------------------------------------------------------------------------- /gen-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cmake -S . -B build -DCMAKE_BUILD_TYPE=$1 3 | -------------------------------------------------------------------------------- /run-maven.bat: -------------------------------------------------------------------------------- 1 | call mvn -f src -Dbuild.dir="%cd%\build\java" %* 2 | -------------------------------------------------------------------------------- /run-maven.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mvn -f src -Dbuild.dir=`pwd`/build/java $@ 3 | -------------------------------------------------------------------------------- /src/etc/bin/fbjava-deployer.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | set THIS_DIR=%~dp0 5 | 6 | call "%THIS_DIR%\setenv.bat" 7 | 8 | set PATH=%FB_DIR%\bin;%PATH% 9 | 10 | "%JAVA_HOME%\bin\java" -cp "%JAR_DIR%\*" ^ 11 | "-Djava.library.path=%NATIVE_DIR%" ^ 12 | org.firebirdsql.fbjava.Deployer %* 13 | -------------------------------------------------------------------------------- /src/etc/bin/fbjava-deployer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | THIS_DIR=`readlink -f $0` 4 | THIS_DIR=`dirname $THIS_DIR` 5 | 6 | . $THIS_DIR/setenv.sh 7 | 8 | $JAVA_HOME/bin/java -cp "$JAR_DIR/*" org.firebirdsql.fbjava.Deployer $@ 9 | -------------------------------------------------------------------------------- /src/etc/bin/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | THIS_DIR=`readlink -f $0` 4 | THIS_DIR=`dirname $THIS_DIR` 5 | 6 | if [ "`whoami`" != "root" ]; then 7 | echo "This script must be run as root" 1>&2 8 | exit 1 9 | fi 10 | 11 | if [ "$#" != 1 ]; then 12 | echo "Syntax: $0 " 13 | exit 1 14 | fi 15 | 16 | TARGET_DIR=`readlink -f "$1"` 17 | 18 | if [ -e $TARGET_DIR ]; then 19 | echo "Install directory should not exist" 1>&2 20 | exit 1 21 | fi 22 | 23 | set -e 24 | 25 | mkdir $TARGET_DIR 26 | tar xzf $THIS_DIR/buildroot.tar.gz --directory $TARGET_DIR > /dev/null 27 | 28 | # Set file owners 29 | chown -R root:root $TARGET_DIR 30 | chown firebird:firebird $TARGET_DIR/conf/java-security.fdb 31 | 32 | echo "You must manually add the following line to /plugins.conf:" 33 | echo "include $TARGET_DIR/conf/fbjava.conf" 34 | echo 35 | echo "And set the parameter JavaHome in $TARGET_DIR/conf/fbjava.conf to a JRE/JDK install path." 36 | -------------------------------------------------------------------------------- /src/etc/bin/setenv.bat: -------------------------------------------------------------------------------- 1 | set BIN_DIR=%THIS_DIR% 2 | set JAR_DIR=%THIS_DIR%\..\jar 3 | -------------------------------------------------------------------------------- /src/etc/bin/setenv.sh: -------------------------------------------------------------------------------- 1 | BIN_DIR=$THIS_DIR 2 | JAR_DIR=$THIS_DIR/../jar 3 | -------------------------------------------------------------------------------- /src/etc/conf/fbjava.conf: -------------------------------------------------------------------------------- 1 | Plugin = JAVA { 2 | Module = $(this)/../lib/libfbjava 3 | Config = JAVA_config 4 | } 5 | 6 | Config = JAVA_config { 7 | # JavaHome = /opt/jdk1.8 8 | # JvmArgsFile = $(this)/jvm.args 9 | SecurityDatabase = $(this)/java-security.fdb 10 | } 11 | -------------------------------------------------------------------------------- /src/etc/conf/jvm.args: -------------------------------------------------------------------------------- 1 | #-Xdebug 2 | #-Xnoagent 3 | #-Xrunjdwp:transport=dt_socket,server=y,address=5005,suspend=n 4 | #-Djnidispatch.preserve=true 5 | #-Djava.compiler=NONE 6 | 7 | #-Djna.debug_load=true 8 | #-Djna.debug_load.jna=true 9 | #-Djna.dump_memory=true 10 | -------------------------------------------------------------------------------- /src/etc/scripts/java-security.sql: -------------------------------------------------------------------------------- 1 | create sequence seq_permission_group; 2 | 3 | create table permission_group ( 4 | id bigint not null constraint pergro_pk primary key, 5 | name varchar(255) not null 6 | ); 7 | 8 | create table permission ( 9 | permission_group bigint not null constraint per_fk01 references permission_group, 10 | class_name varchar(255) not null, 11 | arg1 varchar(255), 12 | arg2 varchar(255) 13 | ); 14 | 15 | create table permission_group_grant ( 16 | permission_group bigint not null constraint pergrogra_fk01 references permission_group, 17 | database_pattern varchar(1024) not null, 18 | grantee_type varchar(4) not null constraint pergrogra_ck01 check (grantee_type in ('USER', 'ROLE')), 19 | grantee_pattern varchar(512) not null 20 | ); 21 | 22 | set term !; 23 | 24 | execute block 25 | as 26 | declare pergro_id type of column permission_group.id; 27 | begin 28 | -- Common permissions, by default granted to all users. 29 | 30 | insert into permission_group (id, name) 31 | values (next value for seq_permission_group, 'COMMON') 32 | returning id into pergro_id; 33 | 34 | insert into permission (permission_group, class_name, arg1, arg2) 35 | values (:pergro_id, 'java.util.PropertyPermission', 'file.separator', 'read'); 36 | insert into permission (permission_group, class_name, arg1, arg2) 37 | values (:pergro_id, 'java.util.PropertyPermission', 'java.version', 'read'); 38 | insert into permission (permission_group, class_name, arg1, arg2) 39 | values (:pergro_id, 'java.util.PropertyPermission', 'java.vendor', 'read'); 40 | insert into permission (permission_group, class_name, arg1, arg2) 41 | values (:pergro_id, 'java.util.PropertyPermission', 'java.vendor.url', 'read'); 42 | insert into permission (permission_group, class_name, arg1, arg2) 43 | values (:pergro_id, 'java.util.PropertyPermission', 'line.separator', 'read'); 44 | insert into permission (permission_group, class_name, arg1, arg2) 45 | values (:pergro_id, 'java.util.PropertyPermission', 'os.*', 'read'); 46 | insert into permission (permission_group, class_name, arg1, arg2) 47 | values (:pergro_id, 'java.util.PropertyPermission', 'path.separator', 'read'); 48 | insert into permission (permission_group, class_name, arg1, arg2) 49 | values (:pergro_id, 'java.util.PropertyPermission', 'jna.encoding', 'read'); 50 | insert into permission (permission_group, class_name, arg1, arg2) 51 | values (:pergro_id, 'java.util.PropertyPermission', 'jna.profiler.prefix', 'read'); 52 | 53 | insert into permission_group_grant (permission_group, database_pattern, grantee_type, grantee_pattern) 54 | values (:pergro_id, '%', 'USER', '%'); 55 | end! 56 | 57 | set term ;! 58 | -------------------------------------------------------------------------------- /src/fbjava-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 4.0.0 6 | 7 | 8 | org.firebirdsql.fbjava 9 | fbjava-parent 10 | 1.0.0-beta-1 11 | ../pom.xml 12 | 13 | 14 | fbjava-impl 15 | jar 16 | 17 | ${project.groupId}:${project.artifactId} 18 | Java plugin for Firebird Database 19 | https://github.com/FirebirdSQL/fbjava 20 | 21 | 22 | 23 | org.firebirdsql.fbjava 24 | fbjava 25 | ${project.version} 26 | 27 | 28 | 29 | org.firebirdsql.jdbc 30 | jaybird 31 | 32 | 33 | 34 | net.java.dev.jna 35 | jna 36 | 37 | 38 | 39 | 40 | 41 | 42 | maven-deploy-plugin 43 | 44 | true 45 | 46 | 47 | 48 | 49 | maven-install-plugin 50 | 51 | true 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/BlobConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.io.ByteArrayInputStream; 22 | import java.io.ByteArrayOutputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.io.PrintWriter; 26 | import java.net.URL; 27 | import java.net.URLConnection; 28 | import java.sql.Connection; 29 | import java.sql.PreparedStatement; 30 | import java.sql.ResultSet; 31 | import java.sql.SQLException; 32 | 33 | import org.firebirdsql.logging.Logger; 34 | import org.firebirdsql.logging.LoggerFactory; 35 | 36 | 37 | /** 38 | * URLConnection for blobs in plugin tables. 39 | * 40 | * @author Adriano dos Santos Fernandes 41 | */ 42 | final class BlobConnection extends URLConnection 43 | { 44 | private static final Logger log = LoggerFactory.getLogger(BlobConnection.class); 45 | private ByteArrayOutputStream bout; 46 | 47 | public BlobConnection(URL url) throws IOException 48 | { 49 | super(url); 50 | 51 | connect(); 52 | } 53 | 54 | @Override 55 | public void connect() throws IOException 56 | { 57 | if (bout != null) 58 | return; 59 | 60 | try 61 | { 62 | final DbClassLoader classLoader = (DbClassLoader) Thread.currentThread().getContextClassLoader(); 63 | final Connection conn = classLoader.getConnection(); 64 | 65 | try (final PreparedStatement stmt = conn.prepareStatement("select content from sqlj.read_jar(?)")) 66 | { 67 | final String urlStr = url.toString().substring(8); // "fbjava:/" 68 | stmt.setString(1, urlStr); 69 | 70 | try (final ResultSet rs = stmt.executeQuery()) 71 | { 72 | if (rs.next()) 73 | { 74 | final InputStream in = rs.getBinaryStream(1); 75 | bout = new ByteArrayOutputStream(); 76 | 77 | final byte[] buffer = new byte[8192]; 78 | int count; 79 | 80 | while ((count = in.read(buffer)) != -1) 81 | bout.write(buffer, 0, count); 82 | } 83 | else 84 | { 85 | try (final PreparedStatement stmt2 = conn.prepareStatement("select child from sqlj.list_dir(?)")) 86 | { 87 | stmt2.setString(1, urlStr); 88 | 89 | try (final ResultSet rs2 = stmt2.executeQuery()) 90 | { 91 | if (rs2.next()) 92 | { 93 | bout = new ByteArrayOutputStream(); 94 | final PrintWriter writer = new PrintWriter(bout); 95 | 96 | do 97 | { 98 | writer.println(rs2.getString(1)); 99 | } while (rs2.next()); 100 | 101 | writer.flush(); 102 | } 103 | } 104 | } 105 | 106 | throw new IOException( 107 | String.format("Resource '%s' has not been found on the database.", url)); 108 | } 109 | } 110 | } 111 | } 112 | catch (final SQLException e) 113 | { 114 | log.error("Error retrieving resource or class from the database", e); 115 | throw new IOException(e); 116 | } 117 | } 118 | 119 | @Override 120 | public InputStream getInputStream() throws IOException 121 | { 122 | return new ByteArrayInputStream(bout.toByteArray()); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/CallableRoutineContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.CallableRoutineContext; 22 | import org.firebirdsql.fbjava.Values; 23 | import org.firebirdsql.fbjava.ValuesMetadata; 24 | 25 | 26 | abstract class CallableRoutineContextImpl extends ContextImpl implements CallableRoutineContext 27 | { 28 | public CallableRoutineContextImpl(InternalContext internalContext) 29 | { 30 | super(internalContext); 31 | } 32 | 33 | @Override 34 | public final String getPackageName() 35 | { 36 | return internalContext.getRoutine().packageName; 37 | } 38 | 39 | @Override 40 | public final ValuesMetadata getInputMetadata() 41 | { 42 | return internalContext.getRoutine().inputMetadata; 43 | } 44 | 45 | @Override 46 | public final ValuesMetadata getOutputMetadata() 47 | { 48 | return internalContext.getRoutine().outputMetadata; 49 | } 50 | 51 | @Override 52 | public final Values getInputValues() 53 | { 54 | return internalContext.getInValues(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/CallableThrowable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | 22 | /*** 23 | * A Callable which throws Throwable. 24 | * 25 | * @author asfernandes 26 | */ 27 | @FunctionalInterface 28 | interface CallableThrowable 29 | { 30 | V call() throws Throwable; 31 | } 32 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/CloseableMemory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import com.sun.jna.Memory; 22 | 23 | 24 | /*** 25 | * JNA Memory with AutoCloseable. 26 | * 27 | * @author asfernandes 28 | */ 29 | final class CloseableMemory extends Memory implements AutoCloseable 30 | { 31 | public CloseableMemory(long size) 32 | { 33 | super(size); 34 | } 35 | 36 | @Override 37 | public void close() 38 | { 39 | dispose(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.sql.Connection; 22 | import java.sql.SQLException; 23 | 24 | import org.firebirdsql.fbjava.Context; 25 | 26 | 27 | abstract class ContextImpl implements Context 28 | { 29 | InternalContext internalContext; 30 | 31 | public ContextImpl(InternalContext internalContext) 32 | { 33 | this.internalContext = internalContext; 34 | } 35 | 36 | @Override 37 | public final Connection getConnection() throws SQLException 38 | { 39 | return internalContext.getConnection(); 40 | } 41 | 42 | @Override 43 | public final String getObjectName() 44 | { 45 | return internalContext.getRoutine().objectName; 46 | } 47 | 48 | @Override 49 | public final String getNameInfo() 50 | { 51 | return internalContext.getRoutine().nameInfo; 52 | } 53 | 54 | @Override 55 | public final String getBody() 56 | { 57 | return internalContext.getRoutine().body; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/DataType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 22 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IMessageMetadata; 23 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IMetadataBuilder; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 25 | 26 | import com.sun.jna.Pointer; 27 | 28 | 29 | abstract class DataType 30 | { 31 | static final short NOT_NULL_FLAG = (short) 0; // Should test with this constant instead of with NULL_FLAG. 32 | static final short NULL_FLAG = (short) -1; 33 | 34 | abstract class Conversion 35 | { 36 | abstract Object getFromMessagePrivileged(IExternalContext context, Pointer message, int nullOffset, int offset) 37 | throws FbException; 38 | 39 | abstract Object getFromMessageUnprivileged(IExternalContext context, Object result) throws FbException; 40 | 41 | abstract Object putInMessageUnprivileged(IExternalContext context, Object o) throws FbException; 42 | 43 | abstract void putInMessagePrivileged(IExternalContext context, Pointer message, int nullOffset, int offset, 44 | Object o, Object result) throws FbException; 45 | } 46 | 47 | abstract Conversion setupConversion(IStatus status, Class javaClass, IMessageMetadata metadata, 48 | IMetadataBuilder builder, int index) throws FbException; 49 | } 50 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/DbClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.io.IOException; 22 | import java.net.URL; 23 | import java.net.URLClassLoader; 24 | import java.security.CodeSource; 25 | import java.security.PermissionCollection; 26 | import java.security.Permissions; 27 | import java.security.cert.Certificate; 28 | import java.sql.Connection; 29 | import java.sql.DriverManager; 30 | import java.sql.SQLException; 31 | import java.util.Properties; 32 | 33 | import org.firebirdsql.gds.ISCConstants; 34 | import org.firebirdsql.gds.TransactionParameterBuffer; 35 | import org.firebirdsql.jdbc.FBConnection; 36 | 37 | 38 | /** 39 | * Per database ClassLoader. 40 | * 41 | * @author Adriano dos Santos Fernandes 42 | */ 43 | final class DbClassLoader extends URLClassLoader 44 | { 45 | private final URL contextUrl; 46 | final String databaseName; 47 | private final FBConnection connection; 48 | final CodeSource codeSource; 49 | final PermissionCollection codeSourcePermission = new Permissions(); 50 | 51 | DbClassLoader(final String databaseName, final URL contextUrl, final ClassLoader parent) 52 | throws SQLException 53 | { 54 | super(new URL[] {contextUrl}, parent); 55 | 56 | this.contextUrl = contextUrl; 57 | this.databaseName = databaseName; 58 | 59 | codeSource = new CodeSource(contextUrl, (Certificate[]) null); 60 | 61 | final Properties properties = new Properties(); 62 | properties.setProperty("user", "SYSDBA"); //// FIXME: 63 | properties.setProperty("isc_dpb_no_db_triggers", "1"); 64 | 65 | connection = (FBConnection) DriverManager.getConnection( 66 | "jdbc:firebirdsql:embedded:" + databaseName + "?charSet=UTF-8", properties); 67 | connection.setAutoCommit(false); 68 | connection.setReadOnly(true); 69 | 70 | final TransactionParameterBuffer tpb = connection.createTransactionParameterBuffer(); 71 | tpb.addArgument(ISCConstants.isc_tpb_read_committed); 72 | tpb.addArgument(ISCConstants.isc_tpb_rec_version); 73 | tpb.addArgument(ISCConstants.isc_tpb_read); 74 | connection.setTransactionParameters(Connection.TRANSACTION_READ_COMMITTED, tpb); 75 | 76 | DbPolicy.databaseOpened(); 77 | } 78 | 79 | @Override 80 | public void close() throws IOException 81 | { 82 | try 83 | { 84 | DbPolicy.databaseClosed(); 85 | connection.close(); 86 | } 87 | catch (final SQLException e) 88 | { 89 | throw new IOException(e); 90 | } 91 | } 92 | 93 | @Override 94 | protected PermissionCollection getPermissions(final CodeSource codesource) 95 | { 96 | return codeSourcePermission; 97 | } 98 | 99 | public Connection getConnection() 100 | { 101 | return connection; 102 | } 103 | 104 | @Override 105 | public URL getResource(final String name) 106 | { 107 | URL url = super.getResource(name); 108 | 109 | if (url == null) 110 | { 111 | try 112 | { 113 | url = new URL(contextUrl, name); 114 | url.openConnection(); 115 | } 116 | catch (final Exception e) 117 | { 118 | url = null; 119 | } 120 | } 121 | 122 | return url; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/DbPrincipal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.security.Principal; 22 | 23 | 24 | /** 25 | * A database user for security handling purposes. 26 | * 27 | * @author Adriano dos Santos Fernandes 28 | */ 29 | final class DbPrincipal implements Principal 30 | { 31 | private final String databaseName; 32 | private final String roleName; 33 | private final String userName; 34 | 35 | public DbPrincipal(final String databaseName, final String roleName, final String userName) 36 | { 37 | this.databaseName = databaseName; 38 | this.roleName = roleName; 39 | this.userName = userName; 40 | } 41 | 42 | @Override 43 | public String getName() 44 | { 45 | return userName; 46 | } 47 | 48 | @Override 49 | public boolean equals(final Object another) 50 | { 51 | return (another instanceof DbPrincipal) && 52 | databaseName.equals(((DbPrincipal) another).databaseName) && 53 | roleName.equals(((DbPrincipal) another).roleName) && 54 | userName.equals(((DbPrincipal) another).userName); 55 | } 56 | 57 | @Override 58 | public int hashCode() 59 | { 60 | return userName.hashCode(); 61 | } 62 | 63 | @Override 64 | public String toString() 65 | { 66 | return databaseName + "::" + userName; 67 | } 68 | 69 | String getDatabaseName() 70 | { 71 | return databaseName; 72 | } 73 | 74 | public String getRoleName() 75 | { 76 | return roleName; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 22 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalFunction; 23 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalFunctionIntf; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 25 | 26 | import com.sun.jna.Pointer; 27 | 28 | 29 | final class ExternalFunction implements IExternalFunctionIntf 30 | { 31 | private IExternalFunction wrapper; 32 | private final Routine routine; 33 | 34 | private ExternalFunction(Routine routine) 35 | { 36 | this.routine = routine; 37 | } 38 | 39 | public static IExternalFunction create(final Routine routine) 40 | { 41 | final ExternalFunction wrapped = new ExternalFunction(routine); 42 | wrapped.wrapper = JnaUtil.pin(new IExternalFunction(wrapped)); 43 | return wrapped.wrapper; 44 | } 45 | 46 | @Override 47 | public void dispose() 48 | { 49 | JnaUtil.unpin(wrapper); 50 | } 51 | 52 | @Override 53 | public void getCharSet(IStatus status, IExternalContext context, Pointer name, int nameSize) throws FbException 54 | { 55 | name.setString(0, "UTF8"); 56 | } 57 | 58 | @Override 59 | public void execute(IStatus status, IExternalContext context, Pointer inMsg, Pointer outMsg) throws FbException 60 | { 61 | try 62 | { 63 | final Object[] in = new Object[routine.inputParameters.size()]; 64 | 65 | try (final InternalContext internalContext = InternalContext.create(status, context, routine, 66 | new ValuesImpl(in, in.length), null)) 67 | { 68 | final ThrowableRunnable preExecute = () -> 69 | routine.getFromMessage(status, context, routine.inputParameters, inMsg, in); 70 | 71 | final ThrowableFunction postExecute = out -> { 72 | routine.putInMessage(status, context, routine.outputParameters, new Object[] {out}, 0, outMsg); 73 | return null; 74 | }; 75 | 76 | final InternalContext oldContext = InternalContext.set(internalContext); 77 | try 78 | { 79 | routine.run(status, context, in, preExecute, postExecute); 80 | } 81 | finally 82 | { 83 | InternalContext.set(oldContext); 84 | } 85 | } 86 | } 87 | catch (final Throwable t) 88 | { 89 | FbException.rethrow(t); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.lang.reflect.Array; 22 | 23 | import org.firebirdsql.fbjava.ExternalResultSet; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 25 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalProcedure; 26 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalProcedureIntf; 27 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalResultSet; 28 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 29 | 30 | import com.sun.jna.Pointer; 31 | 32 | 33 | final class ExternalProcedure implements IExternalProcedureIntf 34 | { 35 | private IExternalProcedure wrapper; 36 | private final Routine routine; 37 | 38 | private ExternalProcedure(Routine routine) 39 | { 40 | this.routine = routine; 41 | } 42 | 43 | public static IExternalProcedure create(final Routine routine) 44 | { 45 | final ExternalProcedure wrapped = new ExternalProcedure(routine); 46 | wrapped.wrapper = JnaUtil.pin(new IExternalProcedure(wrapped)); 47 | return wrapped.wrapper; 48 | } 49 | 50 | @Override 51 | public void dispose() 52 | { 53 | JnaUtil.unpin(wrapper); 54 | } 55 | 56 | @Override 57 | public void getCharSet(IStatus status, IExternalContext context, Pointer name, int nameSize) throws FbException 58 | { 59 | name.setString(0, "UTF8"); 60 | } 61 | 62 | @Override 63 | public IExternalResultSet open(IStatus status, IExternalContext context, Pointer inMsg, Pointer outMsg) 64 | throws FbException 65 | { 66 | try 67 | { 68 | final int inCount = routine.inputParameters.size(); 69 | final int outCount = routine.outputParameters.size(); 70 | final Object[] inOut = new Object[inCount + outCount]; 71 | final Object[] inOut2 = new Object[inCount + outCount]; 72 | 73 | boolean closeContext = true; 74 | 75 | InternalContext internalContext = InternalContext.create(status, context, routine, 76 | new ValuesImpl(inOut, inCount), 77 | new ValuesImpl(inOut, inCount, outCount)); 78 | 79 | try 80 | { 81 | final ThrowableRunnable preExecute = () -> { 82 | routine.getFromMessage(status, context, routine.inputParameters, inMsg, inOut); 83 | 84 | for (int i = inCount; i < inOut.length; ++i) 85 | inOut[i] = Array.newInstance(routine.outputParameters.get(i - inCount).javaClass, 1); 86 | }; 87 | 88 | final ThrowableFunction postExecute = out -> { 89 | final ExternalResultSet rs = (ExternalResultSet) out; 90 | 91 | if (rs == null) 92 | { 93 | for (int i = inCount; i < inOut.length; ++i) 94 | inOut2[i] = Array.get(inOut[i], 0); 95 | 96 | routine.putInMessage(status, context, routine.outputParameters, inOut2, inCount, outMsg); 97 | return null; 98 | } 99 | else 100 | { 101 | return ExternalEngine.doPrivileged(() -> 102 | ExternalResultSetWrapper.create(routine, context, internalContext, outMsg, rs, inCount, inOut, inOut2) 103 | ); 104 | } 105 | }; 106 | 107 | final InternalContext oldContext = InternalContext.set(internalContext); 108 | try 109 | { 110 | final IExternalResultSet extResultSet = routine.run(status, context, inOut, preExecute, postExecute); 111 | 112 | if (extResultSet != null) 113 | closeContext = false; 114 | 115 | return extResultSet; 116 | } 117 | finally 118 | { 119 | InternalContext.set(oldContext); 120 | } 121 | } 122 | finally 123 | { 124 | if (closeContext) 125 | internalContext.close(); 126 | } 127 | } 128 | catch (final Throwable t) 129 | { 130 | FbException.rethrow(t); 131 | return null; 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalResultSetWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.lang.reflect.Array; 22 | 23 | import org.firebirdsql.fbjava.ExternalResultSet; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 25 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalResultSet; 26 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalResultSetIntf; 27 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 28 | 29 | import com.sun.jna.Pointer; 30 | 31 | 32 | final class ExternalResultSetWrapper implements IExternalResultSetIntf 33 | { 34 | private IExternalResultSet wrapper; 35 | private final Routine routine; 36 | private final IExternalContext context; 37 | private final InternalContext internalContext; 38 | private final Pointer outMsg; 39 | private final ExternalResultSet extRs; 40 | private final int inCount; 41 | private final Object[] inOut; 42 | private final Object[] inOut2; 43 | 44 | private ExternalResultSetWrapper(Routine routine, IExternalContext context, InternalContext internalContext, 45 | Pointer outMsg, ExternalResultSet extRs, int inCount, Object[] inOut, Object[] inOut2) 46 | { 47 | this.routine = routine; 48 | this.context = context; 49 | this.internalContext = internalContext; 50 | this.outMsg = outMsg; 51 | this.extRs = extRs; 52 | this.inCount = inCount; 53 | this.inOut = inOut; 54 | this.inOut2 = inOut2; 55 | } 56 | 57 | public static IExternalResultSet create(Routine routine, IExternalContext context, InternalContext internalContext, Pointer outMsg, 58 | ExternalResultSet extRs, int inCount, Object[] inOut, Object[] inOut2) 59 | { 60 | final ExternalResultSetWrapper wrapped = new ExternalResultSetWrapper(routine, context, internalContext, 61 | outMsg, extRs, inCount, inOut, inOut2); 62 | wrapped.wrapper = JnaUtil.pin(new IExternalResultSet(wrapped)); 63 | return wrapped.wrapper; 64 | } 65 | 66 | @Override 67 | public void dispose() 68 | { 69 | try 70 | { 71 | final IStatus status = Main.master.getStatus(); 72 | try 73 | { 74 | final InternalContext oldContext = InternalContext.set(internalContext); 75 | try 76 | { 77 | try 78 | { 79 | routine.engine.runInClassLoader(status, context, 80 | extRs.getClass().getName(), "close", 81 | () -> { 82 | extRs.close(); 83 | return null; 84 | }); 85 | } 86 | finally 87 | { 88 | internalContext.close(); 89 | } 90 | } 91 | finally 92 | { 93 | InternalContext.set(oldContext); 94 | } 95 | } 96 | finally 97 | { 98 | status.dispose(); 99 | } 100 | } 101 | catch (final Throwable t) 102 | { 103 | //// TODO: ??? 104 | } 105 | 106 | JnaUtil.unpin(wrapper); 107 | } 108 | 109 | @Override 110 | public boolean fetch(IStatus status) throws FbException 111 | { 112 | //// TODO: batch 113 | 114 | try 115 | { 116 | final InternalContext oldContext = InternalContext.set(internalContext); 117 | try 118 | { 119 | return routine.engine.runInClassLoader(status, context, 120 | extRs.getClass().getName(), "fetch", 121 | () -> { 122 | if (extRs.fetch()) 123 | { 124 | for (int i = inCount; i < inOut.length; ++i) 125 | inOut2[i] = Array.get(inOut[i], 0); 126 | 127 | routine.putInMessage(status, context, routine.outputParameters, 128 | inOut2, inCount, outMsg); 129 | 130 | return true; 131 | } 132 | else 133 | return false; 134 | }); 135 | } 136 | finally 137 | { 138 | InternalContext.set(oldContext); 139 | } 140 | } 141 | catch (final Throwable t) 142 | { 143 | FbException.rethrow(t); 144 | return false; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalTrigger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.util.List; 22 | 23 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalTrigger; 25 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalTriggerIntf; 26 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 27 | 28 | import com.sun.jna.Pointer; 29 | 30 | 31 | final class ExternalTrigger implements IExternalTriggerIntf 32 | { 33 | private IExternalTrigger wrapper; 34 | private final Routine routine; 35 | 36 | private ExternalTrigger(final Routine routine) 37 | { 38 | this.routine = routine; 39 | } 40 | 41 | public static IExternalTrigger create(final Routine routine) 42 | { 43 | final ExternalTrigger wrapped = new ExternalTrigger(routine); 44 | wrapped.wrapper = JnaUtil.pin(new IExternalTrigger(wrapped)); 45 | return wrapped.wrapper; 46 | } 47 | 48 | @Override 49 | public void dispose() 50 | { 51 | JnaUtil.unpin(wrapper); 52 | } 53 | 54 | @Override 55 | public void getCharSet(IStatus status, IExternalContext context, Pointer name, int nameSize) throws FbException 56 | { 57 | name.setString(0, "UTF8"); 58 | } 59 | 60 | @Override 61 | public void execute(IStatus status, IExternalContext context, int action, Pointer oldMsg, Pointer newMsg) 62 | throws FbException 63 | { 64 | try 65 | { 66 | final List fieldParameters = routine.inputParameters; 67 | final int count = fieldParameters.size(); 68 | final Object[] oldValues = oldMsg == null ? null : new Object[count]; 69 | final Object[] newValues = newMsg == null ? null : new Object[count]; 70 | 71 | try (final InternalContext internalContext = InternalContext.createTrigger( 72 | status, context, routine, action, 73 | (oldMsg == null ? null : new ValuesImpl(oldValues, count)), 74 | (newMsg == null ? null : new ValuesImpl(newValues, count)))) 75 | { 76 | final ThrowableRunnable preExecute = () -> { 77 | if (oldMsg != null) 78 | routine.getFromMessage(status, context, fieldParameters, oldMsg, oldValues); 79 | 80 | if (newMsg != null) 81 | routine.getFromMessage(status, context, fieldParameters, newMsg, newValues); 82 | }; 83 | 84 | final ThrowableFunction postExecute = out -> { 85 | if (newMsg != null) 86 | routine.putInMessage(status, context, fieldParameters, newValues, 0, newMsg); 87 | return null; 88 | }; 89 | 90 | final InternalContext oldContext = InternalContext.set(internalContext); 91 | try 92 | { 93 | routine.run(status, context, null, preExecute, postExecute); 94 | } 95 | finally 96 | { 97 | InternalContext.set(oldContext); 98 | } 99 | } 100 | } 101 | catch (final Throwable t) 102 | { 103 | FbException.rethrow(t); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/FbException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.io.PrintWriter; 22 | import java.io.StringWriter; 23 | 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 25 | import org.firebirdsql.gds.ISCConstants; 26 | 27 | import com.sun.jna.Pointer; 28 | 29 | 30 | final class FbException extends Exception 31 | { 32 | private static final long serialVersionUID = 1L; 33 | 34 | public FbException(final Throwable t) 35 | { 36 | super(t); 37 | } 38 | 39 | public FbException(final String msg) 40 | { 41 | super(msg); 42 | } 43 | 44 | public FbException(final String msg, final Throwable t) 45 | { 46 | super(msg, t); 47 | } 48 | 49 | public static void rethrow(final Throwable t) throws FbException 50 | { 51 | throw new FbException(null, t); 52 | } 53 | 54 | public static void catchException(final IStatus status, Throwable t) 55 | { 56 | while (t != null && t instanceof FbException && t.getMessage() == null) 57 | t = t.getCause(); 58 | 59 | final StringWriter sw = new StringWriter(); 60 | final PrintWriter pw = new PrintWriter(sw); 61 | t.printStackTrace(pw); 62 | final String msg = sw.toString(); 63 | 64 | try (final CloseableMemory memory = new CloseableMemory(msg.length() + 1)) 65 | { 66 | memory.setString(0, msg); 67 | 68 | final Pointer[] vector = new Pointer[] { 69 | new Pointer(ISCConstants.isc_arg_gds), 70 | new Pointer(ISCConstants.isc_random), 71 | new Pointer(ISCConstants.isc_arg_cstring), 72 | new Pointer(msg.length()), 73 | memory, 74 | new Pointer(ISCConstants.isc_arg_end) 75 | }; 76 | 77 | status.setErrors2(vector.length, vector); 78 | } 79 | } 80 | 81 | public static void checkException(final IStatus status) throws FbException 82 | { 83 | if ((status.getState() & IStatus.STATE_ERRORS) != 0) 84 | throw new FbException("FIXME:"); //// FIXME: 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/FunctionContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.FunctionContext; 22 | 23 | 24 | class FunctionContextImpl extends CallableRoutineContextImpl implements FunctionContext 25 | { 26 | public FunctionContextImpl(final InternalContext internalContext) 27 | { 28 | super(internalContext); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/InternalContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.sql.Connection; 22 | import java.sql.DriverManager; 23 | import java.sql.SQLException; 24 | import java.util.Properties; 25 | 26 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IAttachment; 27 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalContext; 28 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 29 | import org.firebirdsql.fbjava.impl.FbClientLibrary.ITransaction; 30 | 31 | 32 | // This (non-public) class is accessed by org.firebirdsql.fbjava.Context by reflection. 33 | final class InternalContext implements AutoCloseable 34 | { 35 | private static final ThreadLocal tls = new ThreadLocal(); 36 | private IAttachment attachment; 37 | private ITransaction transaction; 38 | private Routine routine; 39 | private ValuesImpl inValues; 40 | private ValuesImpl outValues; 41 | private Connection connection; 42 | private ContextImpl contextImpl; 43 | 44 | public static InternalContext get() 45 | { 46 | return tls.get(); 47 | } 48 | 49 | public static InternalContext set(final InternalContext newValue) 50 | { 51 | final InternalContext oldValue = tls.get(); 52 | tls.set(newValue); 53 | return oldValue; 54 | } 55 | 56 | public static ContextImpl getContextImpl() 57 | { 58 | final InternalContext context = get(); 59 | return context.contextImpl; 60 | } 61 | 62 | public static InternalContext create(final IStatus status, final IExternalContext context, final Routine routine, 63 | final ValuesImpl inValues, final ValuesImpl outValues) throws FbException 64 | { 65 | final InternalContext internalContext = new InternalContext(); 66 | internalContext.setup(status, context, routine, 0, inValues, outValues); 67 | return internalContext; 68 | } 69 | 70 | public static InternalContext createTrigger(final IStatus status, final IExternalContext context, 71 | final Routine routine, final int action, final ValuesImpl oldValues, final ValuesImpl newValues) 72 | throws FbException 73 | { 74 | final InternalContext internalContext = new InternalContext(); 75 | internalContext.setup(status, context, routine, action, oldValues, newValues); 76 | return internalContext; 77 | } 78 | 79 | private void setup(final IStatus status, final IExternalContext context, final Routine routine, 80 | final int triggerAction, final ValuesImpl inValues, final ValuesImpl outValues) throws FbException 81 | { 82 | attachment = context.getAttachment(status); 83 | transaction = context.getTransaction(status); 84 | 85 | this.routine = routine; 86 | this.inValues = inValues; 87 | this.outValues = outValues; 88 | 89 | if (routine == null) 90 | contextImpl = null; 91 | else 92 | { 93 | switch (routine.type) 94 | { 95 | case FUNCTION: 96 | contextImpl = new FunctionContextImpl(this); 97 | break; 98 | 99 | case PROCEDURE: 100 | contextImpl = new ProcedureContextImpl(this); 101 | break; 102 | 103 | case TRIGGER: 104 | contextImpl = new TriggerContextImpl(this, triggerAction); 105 | break; 106 | } 107 | } 108 | } 109 | 110 | public IAttachment getAttachment() 111 | { 112 | return attachment; 113 | } 114 | 115 | public ITransaction getTransaction() 116 | { 117 | return transaction; 118 | } 119 | 120 | public Routine getRoutine() 121 | { 122 | return routine; 123 | } 124 | 125 | public ValuesImpl getInValues() 126 | { 127 | return inValues; 128 | } 129 | 130 | public ValuesImpl getOutValues() 131 | { 132 | return outValues; 133 | } 134 | 135 | public Connection getConnection() throws SQLException 136 | { 137 | if (connection == null) 138 | { 139 | final Properties properties = new Properties(); 140 | properties.setProperty("encoding", "utf8"); 141 | 142 | connection = DriverManager.getConnection("jdbc:default:connection", properties); 143 | } 144 | 145 | return connection; 146 | } 147 | 148 | @Override 149 | public void close() throws Exception 150 | { 151 | if (connection != null) 152 | connection.close(); 153 | connection = null; 154 | 155 | transaction.release(); 156 | transaction = null; 157 | 158 | attachment.release(); 159 | attachment = null; 160 | 161 | routine = null; 162 | contextImpl = null; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/InternalDatabaseFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.security.AccessController; 22 | import java.security.PrivilegedActionException; 23 | import java.security.PrivilegedExceptionAction; 24 | import java.sql.SQLException; 25 | 26 | import org.firebirdsql.gds.DatabaseParameterBuffer; 27 | import org.firebirdsql.gds.ng.IConnectionProperties; 28 | import org.firebirdsql.gds.ng.jna.FbEmbeddedDatabaseFactory; 29 | import org.firebirdsql.gds.ng.jna.JnaDatabase; 30 | import org.firebirdsql.gds.ng.jna.JnaDatabaseConnection; 31 | import org.firebirdsql.jna.fbclient.ISC_STATUS; 32 | 33 | import com.sun.jna.ptr.IntByReference; 34 | 35 | 36 | final class InternalDatabaseFactory extends FbEmbeddedDatabaseFactory 37 | { 38 | private static final InternalDatabaseFactory INSTANCE = new InternalDatabaseFactory(); 39 | 40 | public static InternalDatabaseFactory getInstance() 41 | { 42 | return INSTANCE; 43 | } 44 | 45 | @Override 46 | public JnaDatabase connect(IConnectionProperties connectionProperties) throws SQLException 47 | { 48 | final InternalContext internalContext = InternalContext.get(); 49 | final IntByReference attachmentHandle = new IntByReference(); 50 | final ISC_STATUS[] statusVector = new ISC_STATUS[20]; 51 | 52 | Main.library.fb_get_database_handle(statusVector, attachmentHandle, internalContext.getAttachment()); 53 | 54 | try 55 | { 56 | final JnaDatabaseConnection jnaDatabaseConnection = 57 | AccessController.doPrivileged(new PrivilegedExceptionAction() 58 | { 59 | @Override 60 | public JnaDatabaseConnection run() throws Exception 61 | { 62 | return new JnaDatabaseConnection(getClientLibrary(), connectionProperties) { 63 | @Override 64 | public JnaDatabase identify() throws SQLException 65 | { 66 | return new JnaDatabase(this) { 67 | @Override 68 | protected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create) 69 | throws SQLException 70 | { 71 | handle.setValue(attachmentHandle.getValue()); 72 | setAttached(); 73 | afterAttachActions(); 74 | } 75 | 76 | @Override 77 | protected void internalDetach() 78 | { 79 | } 80 | }; 81 | } 82 | }; 83 | } 84 | }); 85 | 86 | return jnaDatabaseConnection.identify(); 87 | } 88 | catch (final PrivilegedActionException e) 89 | { 90 | throw new SQLException(e.getCause()); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/InternalFBConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.sql.SQLException; 22 | 23 | import org.firebirdsql.gds.ng.TransactionState; 24 | import org.firebirdsql.gds.ng.jna.JnaDatabase; 25 | import org.firebirdsql.gds.ng.jna.JnaTransaction; 26 | import org.firebirdsql.jca.FBManagedConnection; 27 | import org.firebirdsql.jdbc.FBConnection; 28 | import org.firebirdsql.jna.fbclient.ISC_STATUS; 29 | 30 | import com.sun.jna.ptr.IntByReference; 31 | 32 | 33 | public final class InternalFBConnection extends FBConnection // must be public 34 | { 35 | public InternalFBConnection(final FBManagedConnection mc) throws SQLException 36 | { 37 | super(mc); 38 | 39 | final InternalContext internalContext = InternalContext.get(); 40 | final IntByReference transactionHandle = new IntByReference(); 41 | final ISC_STATUS[] statusVector = new ISC_STATUS[20]; 42 | 43 | Main.library.fb_get_transaction_handle(statusVector, transactionHandle, internalContext.getTransaction()); 44 | 45 | final JnaTransaction jnaTransaction = new JnaTransaction((JnaDatabase) getFbDatabase(), transactionHandle, 46 | TransactionState.ACTIVE) 47 | { 48 | @Override 49 | protected void finalize() 50 | { 51 | } 52 | }; 53 | 54 | getGDSHelper().setCurrentTransaction(jnaTransaction); 55 | } 56 | 57 | @Override 58 | public void setManagedEnvironment(final boolean managedConnection) throws SQLException 59 | { 60 | // for autocommit off 61 | checkValidity(); 62 | setTransactionCoordinator(managedConnection, false); 63 | } 64 | 65 | @Override 66 | public synchronized void close() throws SQLException 67 | { 68 | freeStatements(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/InternalGDSFactoryPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.gds.GDSException; 22 | import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; 23 | import org.firebirdsql.gds.ng.FbDatabaseFactory; 24 | 25 | 26 | public final class InternalGDSFactoryPlugin extends BaseGDSFactoryPlugin // must be public 27 | { 28 | public static final String INTERNAL_TYPE_NAME = "INTERNAL"; 29 | private static final String[] TYPE_ALIASES = {}; 30 | private static final String[] JDBC_PROTOCOLS = {"jdbc:default:connection"}; 31 | 32 | @Override 33 | public String getPluginName() 34 | { 35 | return "GDS implementation for default connection."; 36 | } 37 | 38 | @Override 39 | public String getTypeName() 40 | { 41 | return INTERNAL_TYPE_NAME; 42 | } 43 | 44 | @Override 45 | public String[] getTypeAliases() 46 | { 47 | return TYPE_ALIASES; 48 | } 49 | 50 | @Override 51 | public Class getConnectionClass() 52 | { 53 | return InternalFBConnection.class; 54 | } 55 | 56 | @Override 57 | public String[] getSupportedProtocols() 58 | { 59 | return JDBC_PROTOCOLS; 60 | } 61 | 62 | @Override 63 | public String getDatabasePath(String server, Integer port, String path) throws GDSException 64 | { 65 | return path; 66 | } 67 | 68 | @Override 69 | public String getDatabasePath(String jdbcUrl) throws GDSException 70 | { 71 | return "default"; //// FIXME: ??? 72 | } 73 | 74 | @Override 75 | public FbDatabaseFactory getDatabaseFactory() 76 | { 77 | return InternalDatabaseFactory.getInstance(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/JnaUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.util.Collections; 22 | import java.util.Set; 23 | import java.util.concurrent.ConcurrentHashMap; 24 | 25 | 26 | final class JnaUtil 27 | { 28 | private static final Set objects = Collections.newSetFromMap(new ConcurrentHashMap()); 29 | 30 | public static T pin(T o) 31 | { 32 | final boolean added = objects.add(o); 33 | assert added; 34 | return o; 35 | } 36 | 37 | public static void unpin(Object o) 38 | { 39 | final boolean removed = objects.remove(o); 40 | assert removed; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IMaster; 22 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IPluginManager; 23 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IUtil; 24 | 25 | import com.sun.jna.Native; 26 | import com.sun.jna.Pointer; 27 | import com.sun.jna.Structure; 28 | 29 | 30 | final class Main 31 | { 32 | public static FbClientLibrary library; 33 | public static IMaster master; 34 | public static IUtil util; 35 | 36 | public static void initialize(final String nativeLibrary, final String fbclientLibrary, final Pointer masterPtr) throws ClassNotFoundException 37 | { 38 | library = (FbClientLibrary) Native.load(fbclientLibrary, FbClientLibrary.class); 39 | 40 | master = Structure.newInstance(IMaster.class, masterPtr); 41 | master.read(); 42 | util = master.getUtilInterface(); 43 | 44 | // We assume the plugin is used with a UTF-8 connection charset, so 45 | // set the Jaybird 3 default charset and disable logging. 46 | System.setProperty("org.firebirdsql.jdbc.disableLogging", "true"); 47 | System.setProperty("org.firebirdsql.jdbc.defaultConnectionEncoding", "utf8"); 48 | 49 | // Load Jaybird and register jdbc:default:connection url. 50 | Class.forName("org.firebirdsql.jdbc.FBDriver"); 51 | 52 | master.getPluginManager().registerPluginFactory(IPluginManager.TYPE_EXTERNAL_ENGINE, "JAVA", 53 | PluginFactory.create()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | 22 | final class Pair 23 | { 24 | private final T1 first; 25 | private final T2 second; 26 | 27 | public Pair(final T1 first, final T2 second) 28 | { 29 | this.first = first; 30 | this.second = second; 31 | } 32 | 33 | public static Pair of(final T1 first, final T2 second) 34 | { 35 | return new Pair(first, second); 36 | } 37 | 38 | public T1 getFirst() 39 | { 40 | return first; 41 | } 42 | 43 | public T2 getSecond() 44 | { 45 | return second; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | 22 | final class Parameter 23 | { 24 | Parameter(final DataType dataType, final Class javaClass) 25 | { 26 | this.dataType = dataType; 27 | this.javaClass = javaClass; 28 | } 29 | 30 | final DataType dataType; 31 | final Class javaClass; 32 | DataType.Conversion conversion; 33 | String name; 34 | Pair type; // Pair of String, java.sql.Types.* 35 | int nullOffset; 36 | int offset; 37 | int length; 38 | int scale; 39 | boolean isNullable; 40 | } 41 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/PluginFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.security.Policy; 22 | 23 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IConfig; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IConfigEntry; 25 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IPluginBase; 26 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IPluginConfig; 27 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IPluginFactory; 28 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IPluginFactoryIntf; 29 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IStatus; 30 | 31 | 32 | final class PluginFactory implements IPluginFactoryIntf 33 | { 34 | private static Boolean securityInitialized = false; 35 | 36 | private PluginFactory() 37 | { 38 | } 39 | 40 | public static IPluginFactory create() 41 | { 42 | return JnaUtil.pin(new IPluginFactory(new PluginFactory())); 43 | } 44 | 45 | @Override 46 | public IPluginBase createPlugin(IStatus status, IPluginConfig pluginConfig) throws FbException 47 | { 48 | final String securityDatabase; 49 | 50 | IConfig config = pluginConfig.getDefaultConfig(status); 51 | try 52 | { 53 | IConfigEntry entry = config.find(status, "SecurityDatabase"); 54 | try 55 | { 56 | securityDatabase = entry.getValue(); 57 | } 58 | finally 59 | { 60 | entry.release(); 61 | } 62 | } 63 | finally 64 | { 65 | config.release(); 66 | } 67 | 68 | synchronized (securityInitialized) 69 | { 70 | if (!securityInitialized) 71 | { 72 | // Set the police and install the security manager. 73 | Policy.setPolicy(new DbPolicy(securityDatabase)); 74 | System.setSecurityManager(new SecurityManager()); 75 | 76 | securityInitialized = true; 77 | } 78 | } 79 | 80 | return ExternalEngine.create(securityDatabase); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ProcedureContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.ProcedureContext; 22 | import org.firebirdsql.fbjava.Values; 23 | 24 | 25 | class ProcedureContextImpl extends CallableRoutineContextImpl implements ProcedureContext 26 | { 27 | public ProcedureContextImpl(InternalContext internalContext) 28 | { 29 | super(internalContext); 30 | } 31 | 32 | @Override 33 | public final Values getOutputValues() 34 | { 35 | return internalContext.getOutValues(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ThrowableFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | 22 | // Same as java.util.function.Function but with throws Throwable. 23 | interface ThrowableFunction 24 | { 25 | R apply(T t) throws Throwable; 26 | } 27 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ThrowableRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | 22 | // Same as java.lang.Runnable but with throws Throwable. 23 | interface ThrowableRunnable 24 | { 25 | void run() throws Throwable; 26 | } 27 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/TriggerContextImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.TriggerContext; 22 | import org.firebirdsql.fbjava.Values; 23 | import org.firebirdsql.fbjava.ValuesMetadata; 24 | import org.firebirdsql.fbjava.impl.FbClientLibrary.IExternalTrigger; 25 | 26 | 27 | final class TriggerContextImpl extends ContextImpl implements TriggerContext 28 | { 29 | private final Action action; 30 | 31 | public TriggerContextImpl(final InternalContext internalContext, final int triggerAction) 32 | { 33 | super(internalContext); 34 | 35 | switch (triggerAction) 36 | { 37 | case IExternalTrigger.ACTION_CONNECT: 38 | action = Action.CONNECT; 39 | break; 40 | 41 | case IExternalTrigger.ACTION_DISCONNECT: 42 | action = Action.DISCONNECT; 43 | break; 44 | 45 | case IExternalTrigger.ACTION_TRANS_START: 46 | action = Action.TRANS_START; 47 | break; 48 | 49 | case IExternalTrigger.ACTION_TRANS_COMMIT: 50 | action = Action.TRANS_COMMIT; 51 | break; 52 | 53 | case IExternalTrigger.ACTION_TRANS_ROLLBACK: 54 | action = Action.TRANS_ROLLBACK; 55 | break; 56 | 57 | case IExternalTrigger.ACTION_DDL: 58 | action = Action.DDL; 59 | break; 60 | 61 | case IExternalTrigger.ACTION_DELETE: 62 | action = Action.DELETE; 63 | break; 64 | 65 | case IExternalTrigger.ACTION_INSERT: 66 | action = Action.INSERT; 67 | break; 68 | 69 | case IExternalTrigger.ACTION_UPDATE: 70 | action = Action.UPDATE; 71 | break; 72 | 73 | default: 74 | throw new AssertionError("Unrecognized trigger action"); 75 | } 76 | } 77 | 78 | @Override 79 | public final String getTableName() 80 | { 81 | return internalContext.getRoutine().tableName; 82 | } 83 | 84 | @Override 85 | public final Type getType() 86 | { 87 | return internalContext.getRoutine().triggerType; 88 | } 89 | 90 | @Override 91 | public final Action getAction() 92 | { 93 | return action; 94 | } 95 | 96 | @Override 97 | public final ValuesMetadata getFieldsMetadata() 98 | { 99 | Routine routine = internalContext.getRoutine(); 100 | return routine.triggerType == Type.DATABASE ? null : routine.inputMetadata; 101 | } 102 | 103 | @Override 104 | public final Values getOldValues() 105 | { 106 | return internalContext.getInValues(); 107 | } 108 | 109 | @Override 110 | public final Values getNewValues() 111 | { 112 | return internalContext.getOutValues(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ValuesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import org.firebirdsql.fbjava.Values; 22 | 23 | 24 | final class ValuesImpl implements Values 25 | { 26 | private final Object[] array; 27 | private final int inCount; 28 | private final int outCount; 29 | 30 | ValuesImpl(Object[] array, int inCount, int outCount) 31 | { 32 | this.array = array; 33 | this.inCount = inCount; 34 | this.outCount = outCount; 35 | } 36 | 37 | ValuesImpl(Object[] array, int inCount) 38 | { 39 | this(array, inCount, -1); 40 | } 41 | 42 | @Override 43 | public Object getObject(int index) 44 | { 45 | //// TODO: read only values 46 | 47 | if (outCount == -1) 48 | { 49 | checkIndex(index, inCount); 50 | return array[index - 1]; 51 | } 52 | else 53 | { 54 | checkIndex(index, outCount); 55 | return ((Object[]) array[inCount + index - 1])[0]; 56 | } 57 | } 58 | 59 | @Override 60 | public Object setObject(int index, Object value) 61 | { 62 | final Object oldValue = getObject(index); 63 | 64 | if (outCount == -1) 65 | { 66 | checkIndex(index, inCount); 67 | array[index - 1] = value; 68 | } 69 | else 70 | { 71 | checkIndex(index, outCount); 72 | ((Object[]) array[inCount + index - 1])[0] = value; 73 | } 74 | 75 | return oldValue; 76 | } 77 | 78 | private static void checkIndex(int index, int count) 79 | { 80 | if (index < 1 || index > count) 81 | { 82 | throw new IndexOutOfBoundsException( 83 | String.format("Values index out of bounds: Index: %d, Size: %d", index, count)); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ValuesMetadataImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava.impl; 20 | 21 | import java.sql.ParameterMetaData; 22 | import java.sql.SQLException; 23 | import java.util.List; 24 | 25 | import org.firebirdsql.fbjava.ValuesMetadata; 26 | 27 | 28 | final class ValuesMetadataImpl implements ValuesMetadata 29 | { 30 | private List parameters; 31 | 32 | void setup(List parameters) 33 | { 34 | this.parameters = parameters; 35 | } 36 | 37 | @Override 38 | public int getIndex(String name) 39 | { 40 | for (int i = 0; i < parameters.size(); ++i) 41 | { 42 | if (name.equals(parameters.get(i).name)) 43 | return i + 1; 44 | } 45 | 46 | return -1; 47 | } 48 | 49 | @Override 50 | public String getName(int index) 51 | { 52 | checkIndex(index); 53 | return parameters.get(index - 1).name; 54 | } 55 | 56 | @Override 57 | public Class getJavaClass(int index) 58 | { 59 | checkIndex(index); 60 | return parameters.get(index - 1).javaClass; 61 | } 62 | 63 | @Override 64 | public int getParameterCount() 65 | { 66 | return parameters.size(); 67 | } 68 | 69 | @Override 70 | public int getParameterType(int index) 71 | { 72 | checkIndex(index); 73 | return parameters.get(index - 1).type.getSecond(); 74 | } 75 | 76 | @Override 77 | public int getPrecision(int index) 78 | { 79 | checkIndex(index); 80 | //// FIXME: Incorrect for multi-byte strings, for numerics etc. 81 | return parameters.get(index - 1).length; 82 | } 83 | 84 | @Override 85 | public int getScale(int index) 86 | { 87 | checkIndex(index); 88 | return parameters.get(index - 1).scale; 89 | } 90 | 91 | @Override 92 | public int isNullable(int index) 93 | { 94 | checkIndex(index); 95 | return parameters.get(index - 1).isNullable ? 96 | ParameterMetaData.parameterNullable : ParameterMetaData.parameterNoNulls; 97 | } 98 | 99 | @Override 100 | public boolean isSigned(int index) throws SQLException 101 | { 102 | checkIndex(index); 103 | return true; 104 | } 105 | 106 | @Override 107 | public String getParameterTypeName(int index) throws SQLException 108 | { 109 | checkIndex(index); 110 | return null; //// FIXME: 111 | } 112 | 113 | @Override 114 | public String getParameterClassName(int index) throws SQLException 115 | { 116 | checkIndex(index); 117 | return parameters.get(index - 1).javaClass.getName(); 118 | } 119 | 120 | @Override 121 | public int getParameterMode(int index) throws SQLException 122 | { 123 | checkIndex(index); 124 | return ParameterMetaData.parameterModeUnknown; 125 | } 126 | 127 | @Override 128 | public T unwrap(Class iface) throws SQLException 129 | { 130 | return null; 131 | } 132 | 133 | @Override 134 | public boolean isWrapperFor(Class iface) throws SQLException 135 | { 136 | return false; 137 | } 138 | 139 | private void checkIndex(int index) 140 | { 141 | if (index < 1 || index > parameters.size()) 142 | { 143 | throw new IndexOutOfBoundsException( 144 | String.format("ValuesMetadata index out of bounds: Index: %d, Size: %d", index, parameters.size())); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/resources/META-INF/services/org.firebirdsql.gds.impl.GDSFactoryPlugin: -------------------------------------------------------------------------------- 1 | org.firebirdsql.fbjava.impl.InternalGDSFactoryPlugin 2 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/resources/org/firebirdsql/fbjava/install.sql: -------------------------------------------------------------------------------- 1 | create sequence fb$java$seq! 2 | 3 | create exception fb$java$ex ''! 4 | 5 | create table fb$java$jar ( 6 | id bigint not null 7 | constraint fb$java$jar_pk primary key 8 | using asc index fb$java$jar_id, 9 | name varchar(64) character set utf8 not null 10 | constraint fb$java$jar_name_uk unique 11 | using asc index fb$java$jar_name, 12 | owner varchar(31) character set utf8 not null 13 | )! 14 | 15 | create table fb$java$jar_entry ( 16 | id bigint not null 17 | constraint fb$java$jar_entry_pk primary key 18 | using asc index fb$java$jar_entry_id, 19 | jar bigint not null 20 | constraint fb$java$jar_entry_jar_fk references fb$java$jar 21 | using asc index fb$java$jar_entry_jar, 22 | name varchar(253) character set utf8 not null 23 | constraint fb$java$jar_entry_name_uk unique 24 | using asc index fb$java$jar_entry_name, 25 | content blob not null 26 | )! 27 | 28 | create view fb$java$user_jar as 29 | select id, name 30 | from fb$java$jar 31 | where owner = current_user! 32 | 33 | create view fb$java$user_jar_entry as 34 | select je.id, je.jar, je.name, je.content 35 | from fb$java$jar_entry je 36 | join fb$java$user_jar uj 37 | on uj.id = je.jar! 38 | 39 | create trigger fb$java$jar_bi 40 | before insert on fb$java$jar 41 | as 42 | begin 43 | if (new.owner <> current_user) then 44 | exception fb$java$ex 'Attempt to store a jar in another user name'; 45 | end! 46 | 47 | create trigger fb$java$jar_entry_bi 48 | before insert on fb$java$jar_entry 49 | as 50 | declare user_jar integer; 51 | begin 52 | select 1 from fb$java$user_jar where id = new.jar into user_jar; 53 | 54 | if (user_jar is null) then 55 | exception fb$java$ex 'Attempt to store a jar entry on a jar from another user'; 56 | end! 57 | 58 | create package sqlj 59 | as 60 | begin 61 | procedure install_jar ( 62 | url varchar(256) character set utf8 not null, 63 | name type of column fb$java$jar.name not null 64 | ); 65 | 66 | procedure remove_jar ( 67 | name type of column fb$java$jar.name not null 68 | ); 69 | 70 | procedure update_jar ( 71 | url varchar(256) character set utf8 not null, 72 | name type of column fb$java$jar.name not null 73 | ); 74 | 75 | procedure replace_jar ( 76 | url varchar(256) character set utf8 not null, 77 | name type of column fb$java$jar.name not null 78 | ); 79 | 80 | procedure read_jar ( 81 | name type of column fb$java$jar_entry.name not null 82 | ) returns ( 83 | content type of column fb$java$jar_entry.content --not null 84 | ); 85 | 86 | procedure list_dir ( 87 | name type of column fb$java$jar_entry.name not null 88 | ) returns ( 89 | child type of column fb$java$jar_entry.name 90 | ); 91 | end! 92 | 93 | create package body sqlj 94 | as 95 | begin 96 | procedure verbose_install_jar ( 97 | url varchar(256) character set utf8 not null, 98 | name type of column fb$java$jar.name not null 99 | ) returns ( 100 | class_name type of column fb$java$jar_entry.name not null 101 | ) 102 | external name 'org.firebirdsql.fbjava.Deployer.verboseInstallJar(String, String, String[])' engine java; 103 | 104 | procedure verbose_remove_jar ( 105 | name type of column fb$java$jar.name not null 106 | ) returns ( 107 | class_name type of column fb$java$jar_entry.name not null 108 | ) 109 | as 110 | declare owner type of column fb$java$jar.owner; 111 | begin 112 | select owner from fb$java$jar where name = :name into owner; 113 | 114 | if (owner is null) then 115 | exception fb$java$ex 'Attempt to remove uninstalled JAR'; 116 | else if (owner <> current_user and current_user <> 'SYSDBA') then 117 | exception fb$java$ex 'Cannot remove a JAR from another user'; 118 | 119 | for select name from fb$java$jar_entry 120 | where jar = (select id from fb$java$jar where name = :name) 121 | into class_name 122 | as cursor c do 123 | begin 124 | delete from fb$java$jar_entry where current of c; 125 | suspend; 126 | end 127 | 128 | delete from fb$java$jar where name = :name; 129 | end 130 | 131 | procedure install_jar ( 132 | url varchar(256) character set utf8 not null, 133 | name type of column fb$java$jar.name not null 134 | ) 135 | as 136 | declare dummy integer; 137 | begin 138 | for select 1 from verbose_install_jar(:url, :name) into dummy do 139 | begin 140 | end 141 | end 142 | 143 | procedure remove_jar ( 144 | name type of column fb$java$jar.name not null 145 | ) 146 | as 147 | declare dummy integer; 148 | begin 149 | for select 1 from verbose_remove_jar(:name) into dummy do 150 | begin 151 | end 152 | end 153 | 154 | procedure update_jar ( 155 | url varchar(256) character set utf8 not null, 156 | name type of column fb$java$jar.name not null 157 | ) 158 | as 159 | begin 160 | execute procedure remove_jar(name); 161 | execute procedure install_jar(url, name); 162 | end 163 | 164 | procedure replace_jar ( 165 | url varchar(256) character set utf8 not null, 166 | name type of column fb$java$jar.name not null 167 | ) 168 | as 169 | begin 170 | begin 171 | execute procedure remove_jar(name); 172 | when any do 173 | begin 174 | end 175 | end 176 | 177 | execute procedure install_jar(url, name); 178 | end 179 | 180 | procedure read_jar ( 181 | name type of column fb$java$jar_entry.name not null 182 | ) returns ( 183 | content type of column fb$java$jar_entry.content --not null 184 | ) 185 | as 186 | declare owner type of column fb$java$jar.owner; 187 | begin 188 | select je.content, j.owner 189 | from fb$java$jar_entry je 190 | join fb$java$jar j 191 | on j.id = je.jar 192 | where je.name = :name 193 | into content, owner; 194 | 195 | if (owner <> current_user and current_user <> 'SYSDBA') then 196 | exception fb$java$ex 'Cannot read a JAR from another user'; 197 | 198 | if (content is not null) then 199 | suspend; 200 | end 201 | 202 | procedure list_dir ( 203 | name type of column fb$java$jar_entry.name not null 204 | ) returns ( 205 | child type of column fb$java$jar_entry.name 206 | ) 207 | as 208 | declare len integer; 209 | begin 210 | len = char_length(name); 211 | if (not len = 0) then 212 | begin 213 | if (substring(name from len for 1) <> '/') then 214 | begin 215 | name = name || '/'; 216 | len = len + 1; 217 | end 218 | end 219 | 220 | for select distinct substring(je.name from :len + 1 for 221 | position('/', je.name || '/', :len + 1) - (:len + 1)) 222 | from fb$java$jar_entry je 223 | join fb$java$jar j 224 | on j.id = je.jar 225 | where je.name starting with :name and 226 | not (owner <> current_user and current_user <> 'SYSDBA') 227 | into child 228 | do 229 | begin 230 | suspend; 231 | end 232 | end 233 | end! 234 | 235 | grant all on table fb$java$jar to package sqlj! 236 | grant all on table fb$java$jar_entry to package sqlj! 237 | 238 | grant insert on table fb$java$jar to public! 239 | grant insert on table fb$java$jar_entry to public! 240 | 241 | grant select on fb$java$user_jar to public! 242 | grant select on fb$java$user_jar_entry to public! 243 | 244 | grant execute on package sqlj to public! 245 | -------------------------------------------------------------------------------- /src/fbjava-impl/src/main/resources/org/firebirdsql/fbjava/uninstall.sql: -------------------------------------------------------------------------------- 1 | drop package sqlj! 2 | 3 | drop trigger fb$java$jar_entry_bi! 4 | drop trigger fb$java$jar_bi! 5 | 6 | commit /* FIXME: dependencies error */ ! 7 | 8 | drop view fb$java$user_jar_entry! 9 | drop view fb$java$user_jar! 10 | 11 | drop table fb$java$jar_entry! 12 | drop table fb$java$jar! 13 | 14 | drop exception fb$java$ex! 15 | 16 | drop sequence fb$java$seq! 17 | -------------------------------------------------------------------------------- /src/fbjava-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 4.0.0 6 | 7 | 8 | org.firebirdsql.fbjava 9 | fbjava-parent 10 | 1.0.0-beta-1 11 | ../pom.xml 12 | 13 | 14 | fbjava-tests 15 | jar 16 | 17 | ${project.groupId}:${project.artifactId} 18 | Java plugin for Firebird Database 19 | https://github.com/FirebirdSQL/fbjava 20 | 21 | 22 | 23 | org.firebirdsql.fbjava 24 | fbjava 25 | ${project.version} 26 | provided 27 | 28 | 29 | 30 | 31 | 32 | 33 | maven-deploy-plugin 34 | 35 | true 36 | 37 | 38 | 39 | 40 | maven-install-plugin 41 | 42 | true 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/fbjava-tests/src/main/java/example/Procedures.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package example; 20 | 21 | import java.math.BigDecimal; 22 | import java.sql.SQLException; 23 | 24 | import org.firebirdsql.fbjava.CallableRoutineContext; 25 | import org.firebirdsql.fbjava.ExternalResultSet; 26 | import org.firebirdsql.fbjava.ProcedureContext; 27 | import org.firebirdsql.fbjava.Values; 28 | import org.firebirdsql.fbjava.ValuesMetadata; 29 | 30 | 31 | public class Procedures 32 | { 33 | public static void p1() 34 | { 35 | } 36 | 37 | public static void p2(int i) 38 | { 39 | } 40 | 41 | public static void p3(int i, int[] o) 42 | { 43 | o[0] = i; 44 | } 45 | 46 | public static ExternalResultSet p4(int i, int[] o) 47 | { 48 | o[0] = i; 49 | 50 | return new ExternalResultSet() { 51 | @Override 52 | public boolean fetch() throws Exception 53 | { 54 | return ++o[0] <= i + 5; 55 | } 56 | }; 57 | } 58 | 59 | public static ExternalResultSet p5(int start, int end, int[] o) 60 | { 61 | o[0] = start - 1; 62 | 63 | return new ExternalResultSet() { 64 | @Override 65 | public boolean fetch() throws Exception 66 | { 67 | return ++o[0] <= end; 68 | } 69 | }; 70 | } 71 | 72 | public static ExternalResultSet p6(int start, int end, int[] o) 73 | { 74 | o[0] = start - 1; 75 | 76 | return new ExternalResultSet() { 77 | @Override 78 | public boolean fetch() throws Exception 79 | { 80 | if (o[0] == 10) 81 | throw new Exception("Can't go beyond 10."); 82 | 83 | return ++o[0] <= end; 84 | } 85 | }; 86 | } 87 | 88 | public static ExternalResultSet p7(String property, String[] result) 89 | { 90 | return new ExternalResultSet() { 91 | boolean first = true; 92 | 93 | @Override 94 | public boolean fetch() throws Exception 95 | { 96 | if (first) 97 | { 98 | result[0] = System.getProperty(property); 99 | first = false; 100 | return true; 101 | } 102 | else 103 | return false; 104 | } 105 | }; 106 | } 107 | 108 | public static void p8(int i1, int i2, String[] o1, int[] o2, int[] o3) throws SQLException 109 | { 110 | CallableRoutineContext context = CallableRoutineContext.get(); 111 | o1[0] = context.getInputMetadata().getParameterCount() + ", " + context.getOutputMetadata().getParameterCount(); 112 | } 113 | 114 | public static void p9(int i1, Integer i2, String[] o1) throws SQLException 115 | { 116 | CallableRoutineContext context = CallableRoutineContext.get(); 117 | ValuesMetadata input = context.getInputMetadata(); 118 | ValuesMetadata output = context.getOutputMetadata(); 119 | 120 | o1[0] = Functions.getValuesInfo(input, 1) + ", " + Functions.getValuesInfo(input, 2) + ", " + 121 | Functions.getValuesInfo(output, 1); 122 | } 123 | 124 | public static void p10(Object i1, Object i2, String[] o1) throws SQLException 125 | { 126 | CallableRoutineContext context = CallableRoutineContext.get(); 127 | ValuesMetadata input = context.getInputMetadata(); 128 | ValuesMetadata output = context.getOutputMetadata(); 129 | 130 | o1[0] = Functions.getValuesInfo(input, 1) + ", " + Functions.getValuesInfo(input, 2) + ", " + 131 | Functions.getValuesInfo(output, 1); 132 | } 133 | 134 | public static void p11(Object i1, Object i2, String[] o1) throws SQLException 135 | { 136 | ProcedureContext context = ProcedureContext.get(); 137 | ValuesMetadata inputMetadata = context.getInputMetadata(); 138 | ValuesMetadata outputMetadata = context.getOutputMetadata(); 139 | Values input = context.getInputValues(); 140 | Values output = context.getOutputValues(); 141 | 142 | if (o1[0] != output.getObject(1)) 143 | throw new RuntimeException("Error"); 144 | 145 | o1[0] = "a"; 146 | 147 | if (o1[0] != output.getObject(1)) 148 | throw new RuntimeException("Error"); 149 | 150 | output.setObject(1, "b"); 151 | 152 | if (o1[0] != output.getObject(1)) 153 | throw new RuntimeException("Error"); 154 | 155 | output.setObject(1, 156 | Functions.getValues(inputMetadata, input) + " / " + Functions.getValues(outputMetadata, output)); 157 | } 158 | 159 | public static ExternalResultSet p12() 160 | { 161 | ProcedureContext context = ProcedureContext.get(); 162 | Values outValues = context.getOutputValues(); 163 | 164 | BigDecimal i = (BigDecimal) context.getInputValues().getObject(1); 165 | outValues.setObject(1, i); 166 | 167 | return new ExternalResultSet() { 168 | @Override 169 | public boolean fetch() throws Exception 170 | { 171 | BigDecimal o = ((BigDecimal) outValues.getObject(1)).add(BigDecimal.ONE); 172 | outValues.setObject(1, o); 173 | return o.subtract(i).intValue() <= 5; 174 | } 175 | }; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/fbjava-tests/src/main/java/example/Triggers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package example; 20 | 21 | import java.sql.SQLException; 22 | 23 | import org.firebirdsql.fbjava.TriggerContext; 24 | import org.firebirdsql.fbjava.Values; 25 | import org.firebirdsql.fbjava.ValuesMetadata; 26 | 27 | 28 | public class Triggers 29 | { 30 | public static void trigger1() throws SQLException 31 | { 32 | TriggerContext context = TriggerContext.get(); 33 | ValuesMetadata fieldsMetadata = context.getFieldsMetadata(); 34 | Values oldValues = context.getOldValues(); 35 | Values newValues = context.getNewValues(); 36 | 37 | System.out.println("--> " + context.getTableName() + ", " + context.getType() + ", " + 38 | context.getAction() + ", " + context.getFieldsMetadata() + ", " + 39 | context.getOldValues() + ", " + context.getNewValues()); 40 | 41 | if (fieldsMetadata != null) 42 | { 43 | int count = fieldsMetadata.getParameterCount(); 44 | 45 | for (int i = 1; i <= count; ++i) 46 | { 47 | System.out.println(">>> " + i + ", " + fieldsMetadata.getName(i) + ", " + 48 | (oldValues == null ? null : oldValues.getObject(i)) + ", " + 49 | (newValues == null ? null : newValues.getObject(i))); 50 | 51 | /*** 52 | if (newValues != null) 53 | newValues.set(2, BigDecimal.valueOf(((BigDecimal) newValues.get(2)).intValue() + 1)); 54 | ***/ 55 | } 56 | } 57 | 58 | System.out.flush(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/fbjava/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 4.0.0 6 | 7 | 8 | org.firebirdsql.fbjava 9 | fbjava-parent 10 | 1.0.0-beta-1 11 | ../pom.xml 12 | 13 | 14 | fbjava 15 | jar 16 | 17 | ${project.groupId}:${project.artifactId} 18 | Java plugin for Firebird Database 19 | https://github.com/FirebirdSQL/fbjava 20 | 21 | 22 | 23 | LGPL 24 | http://www.gnu.org/copyleft/lgpl.html 25 | 26 | 27 | 28 | 29 | 30 | Adriano dos Santos Fernandes 31 | adrianosf@gmail.com 32 | FirebirdSQL 33 | https://github.com/FirebirdSQL 34 | 35 | 36 | 37 | 38 | scm:git:git://github.com/FirebirdSQL/fbjava.git 39 | scm:git:ssh://github.com:FirebirdSQL/fbjava.git 40 | http://github.com/FirebirdSQL/fbjava/tree/master 41 | 42 | 43 | 44 | 45 | 46 | maven-source-plugin 47 | 48 | 49 | 50 | maven-javadoc-plugin 51 | 52 | 53 | 54 | maven-install-plugin 55 | 56 | 57 | 58 | maven-deploy-plugin 59 | 60 | 61 | 62 | org.apache.maven.plugins 63 | maven-gpg-plugin 64 | 65 | 66 | 67 | org.sonatype.plugins 68 | nexus-staging-maven-plugin 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/CallableRoutineContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird Function or Procedure Context. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface CallableRoutineContext extends Context 28 | { 29 | /** 30 | * Gets the Context instance associated with the current call. 31 | */ 32 | public static CallableRoutineContext get() 33 | { 34 | return (CallableRoutineContext) Context.get(); 35 | } 36 | 37 | /** 38 | * Gets the metadata package name that called the external routine. 39 | * For unpackaged routines, return null. 40 | */ 41 | public String getPackageName(); 42 | 43 | /** 44 | * Gets the input values metadata. 45 | */ 46 | public ValuesMetadata getInputMetadata(); 47 | 48 | /** 49 | * Gets the output values metadata. 50 | * For functions, it always returns a ValuesMetadata with a single entry. 51 | */ 52 | public ValuesMetadata getOutputMetadata(); 53 | 54 | /** 55 | * Gets the input values. 56 | */ 57 | public Values getInputValues(); 58 | } 59 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | import java.lang.reflect.Method; 22 | import java.security.AccessController; 23 | import java.security.PrivilegedAction; 24 | import java.sql.Connection; 25 | import java.sql.SQLException; 26 | 27 | 28 | /** 29 | * This interface represents a Firebird External Context. 30 | * 31 | * @author Adriano dos Santos Fernandes 32 | */ 33 | public interface Context 34 | { 35 | /** 36 | * Gets the Context instance associated with the current call. 37 | */ 38 | public static Context get() 39 | { 40 | // For security purposes, InternalContextImpl is not public, so get it by reflection. 41 | 42 | return AccessController.doPrivileged(new PrivilegedAction() { 43 | @Override 44 | public Context run() 45 | { 46 | try 47 | { 48 | final Class clazz = Class.forName("org.firebirdsql.fbjava.impl.InternalContext"); 49 | final Method method = clazz.getMethod("getContextImpl"); 50 | method.setAccessible(true); 51 | return (Context) method.invoke(null); 52 | } 53 | catch (final Exception e) 54 | { 55 | throw new RuntimeException(e); 56 | } 57 | } 58 | }); 59 | } 60 | 61 | /** 62 | * Gets the Connection object. 63 | * It's also possible to get a Connection object with 64 | * DriverManager.getConnection("jdbc:default:connection") 65 | */ 66 | public Connection getConnection() throws SQLException; 67 | 68 | /** 69 | * Gets the metadata object name that called the external routine. 70 | */ 71 | public String getObjectName(); 72 | 73 | /** 74 | * Gets info stored at entry point metadata. 75 | */ 76 | public String getNameInfo(); 77 | 78 | /** 79 | * Gets metadata body. 80 | */ 81 | public String getBody(); 82 | } 83 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/ExternalResultSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird External ResultSet for a selectable stored procedure. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface ExternalResultSet 28 | { 29 | /** 30 | * Called by Firebird to get records from the ExternalResultSet. 31 | * @return false to stop and true to continue. 32 | * @throws Exception 33 | */ 34 | public boolean fetch() throws Exception; 35 | 36 | /** 37 | * Called by Firebird after fetched all rows from the ExternalResultSet. 38 | */ 39 | public default void close() 40 | { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/FunctionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird Function Context. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface FunctionContext extends CallableRoutineContext 28 | { 29 | /** 30 | * Gets the Context instance associated with the current call. 31 | */ 32 | public static FunctionContext get() 33 | { 34 | return (FunctionContext) Context.get(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/ProcedureContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird Procedure Context. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface ProcedureContext extends CallableRoutineContext 28 | { 29 | /** 30 | * Gets the Context instance associated with the current call. 31 | */ 32 | public static ProcedureContext get() 33 | { 34 | return (ProcedureContext) Context.get(); 35 | } 36 | 37 | /** 38 | * Gets the output values. 39 | */ 40 | public Values getOutputValues(); 41 | } 42 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/TriggerContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird Trigger Context. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface TriggerContext extends Context 28 | { 29 | /** 30 | * Trigger Type. 31 | */ 32 | public static enum Type 33 | { 34 | BEFORE, 35 | AFTER, 36 | DATABASE 37 | } 38 | 39 | /** 40 | * Trigger Action. 41 | */ 42 | public static enum Action 43 | { 44 | INSERT, 45 | UPDATE, 46 | DELETE, 47 | CONNECT, 48 | DISCONNECT, 49 | TRANS_START, 50 | TRANS_COMMIT, 51 | TRANS_ROLLBACK, 52 | DDL 53 | } 54 | 55 | /** 56 | * Gets the Context instance associated with the current call. 57 | */ 58 | public static TriggerContext get() 59 | { 60 | return (TriggerContext) Context.get(); 61 | } 62 | 63 | /** 64 | * Gets the table that fired the trigger. 65 | * Returns null for database and DDL triggers. 66 | */ 67 | public String getTableName(); 68 | 69 | /** 70 | * Gets the type of the trigger. 71 | */ 72 | public Type getType(); 73 | 74 | /** 75 | * Gets the action that fired the trigger. 76 | */ 77 | public Action getAction(); 78 | 79 | /** 80 | * Gets the fields metadata. 81 | * Returns null for database/ddl triggers. 82 | */ 83 | public ValuesMetadata getFieldsMetadata(); 84 | 85 | /** 86 | * Gets the fields old values. 87 | * Returns null for database/ddl and insert triggers. 88 | */ 89 | public Values getOldValues(); 90 | 91 | /** 92 | * Gets the fields new values. 93 | * Returns null for database/ddl and delete triggers. 94 | */ 95 | public Values getNewValues(); 96 | } 97 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/Values.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | 22 | /** 23 | * This interface represents a Firebird Values (set of input/output parameters or trigger's old/new fields) data. 24 | * 25 | * @author Adriano dos Santos Fernandes 26 | */ 27 | public interface Values 28 | { 29 | /** 30 | * Gets the value for a given index. 31 | * Index starts from 1. 32 | */ 33 | public Object getObject(int index); 34 | 35 | /** 36 | * Sets the value for a given index. 37 | * Index starts from 1. 38 | */ 39 | public Object setObject(int index, Object value); 40 | } 41 | -------------------------------------------------------------------------------- /src/fbjava/src/main/java/org/firebirdsql/fbjava/ValuesMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * FB/Java plugin 3 | * 4 | * Distributable under LGPL license. 5 | * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * LGPL License for more details. 11 | * 12 | * This file was created by members of the Firebird development team. 13 | * All individual contributions remain the Copyright (C) of those 14 | * individuals. Contributors to this file are either listed here or 15 | * can be obtained from a git log command. 16 | * 17 | * All rights reserved. 18 | */ 19 | package org.firebirdsql.fbjava; 20 | 21 | import java.sql.ParameterMetaData; 22 | 23 | 24 | /** 25 | * This interface represents a Firebird Values (set of input/output parameters or trigger's old/new fields) metadata. 26 | * 27 | * @author Adriano dos Santos Fernandes 28 | */ 29 | public interface ValuesMetadata extends ParameterMetaData 30 | { 31 | /** 32 | * Gets the index for a given name. 33 | * Returns -1 if the name is not found. 34 | */ 35 | public int getIndex(String name); 36 | 37 | /** 38 | * Gets the name for a given value index. 39 | * Index starts from 1. 40 | * Returns null in function output metadata. 41 | */ 42 | public String getName(int index); 43 | 44 | /** 45 | * Gets the Java Class for a given value index. 46 | * Index starts from 1. 47 | */ 48 | public Class getJavaClass(int index); 49 | } 50 | -------------------------------------------------------------------------------- /src/native/fbjava/.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | out/ 3 | /CMakeSettings.json 4 | -------------------------------------------------------------------------------- /src/native/fbjava/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project(libfbjava CXX) 4 | 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_SHARED_LIBRARY_PREFIX "") 7 | set(CMAKE_VERBOSE_MAKEFILE ON) 8 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 9 | 10 | set(JAVA_AWT_LIBRARY NotNeeded) 11 | set(JAVA_JVM_LIBRARY NotNeeded) 12 | set(JAVA_AWT_INCLUDE_PATH NotNeeded) 13 | find_package(JNI REQUIRED) 14 | 15 | include_directories(${JNI_INCLUDE_DIRS} "include") 16 | 17 | add_library(${PROJECT_NAME} SHARED 18 | "fbjava.cpp" 19 | ) 20 | 21 | if (MSVC) 22 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 23 | 24 | target_compile_options(${PROJECT_NAME} PRIVATE 25 | "$<$:/MT>" 26 | "$<$:/MTd>" 27 | ) 28 | else() 29 | target_compile_options(${PROJECT_NAME} PRIVATE 30 | -fvisibility=hidden 31 | ) 32 | 33 | target_link_libraries(${PROJECT_NAME} 34 | -static-libgcc 35 | -static-libstdc++ 36 | -Wl,--exclude-libs,ALL 37 | ) 38 | endif() 39 | 40 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) 41 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/cat.hpp: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2001 2 | # * Housemarque Oy 3 | # * http://www.housemarque.com 4 | # * 5 | # * Distributed under the Boost Software License, Version 1.0. (See 6 | # * accompanying file LICENSE_1_0.txt or copy at 7 | # * http://www.boost.org/LICENSE_1_0.txt) 8 | # */ 9 | # 10 | # /* Revised by Paul Mensonides (2002) */ 11 | # 12 | # /* See http://www.boost.org for most recent version. */ 13 | # 14 | # ifndef FB_BOOST_PREPROCESSOR_CAT_HPP 15 | # define FB_BOOST_PREPROCESSOR_CAT_HPP 16 | # 17 | # include 18 | # 19 | # /* FB_BOOST_PP_CAT */ 20 | # 21 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 22 | # define FB_BOOST_PP_CAT(a, b) FB_BOOST_PP_CAT_I(a, b) 23 | # else 24 | # define FB_BOOST_PP_CAT(a, b) FB_BOOST_PP_CAT_OO((a, b)) 25 | # define FB_BOOST_PP_CAT_OO(par) FB_BOOST_PP_CAT_I ## par 26 | # endif 27 | # 28 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MSVC() 29 | # define FB_BOOST_PP_CAT_I(a, b) a ## b 30 | # else 31 | # define FB_BOOST_PP_CAT_I(a, b) FB_BOOST_PP_CAT_II(a ## b) 32 | # define FB_BOOST_PP_CAT_II(res) res 33 | # endif 34 | # 35 | # endif 36 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/config/config.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_CONFIG_CONFIG_HPP 13 | # define FB_BOOST_PREPROCESSOR_CONFIG_CONFIG_HPP 14 | # 15 | # /* FB_BOOST_PP_CONFIG_FLAGS */ 16 | # 17 | # define FB_BOOST_PP_CONFIG_STRICT() 0x0001 18 | # define FB_BOOST_PP_CONFIG_IDEAL() 0x0002 19 | # 20 | # define FB_BOOST_PP_CONFIG_MSVC() 0x0004 21 | # define FB_BOOST_PP_CONFIG_MWCC() 0x0008 22 | # define FB_BOOST_PP_CONFIG_BCC() 0x0010 23 | # define FB_BOOST_PP_CONFIG_EDG() 0x0020 24 | # define FB_BOOST_PP_CONFIG_DMC() 0x0040 25 | # 26 | # ifndef FB_BOOST_PP_CONFIG_FLAGS 27 | # if defined(__GCCXML__) 28 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_STRICT()) 29 | # elif defined(__WAVE__) 30 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_STRICT()) 31 | # elif defined(__MWERKS__) && __MWERKS__ >= 0x3200 32 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_STRICT()) 33 | # elif defined(__EDG__) || defined(__EDG_VERSION__) 34 | # if defined(_MSC_VER) && __EDG_VERSION__ >= 308 35 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_MSVC()) 36 | # else 37 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_EDG() | FB_BOOST_PP_CONFIG_STRICT()) 38 | # endif 39 | # elif defined(__MWERKS__) 40 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_MWCC()) 41 | # elif defined(__DMC__) 42 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_DMC()) 43 | # elif defined(__BORLANDC__) && __BORLANDC__ >= 0x581 44 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_STRICT()) 45 | # elif defined(__BORLANDC__) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) 46 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_BCC()) 47 | # elif defined(_MSC_VER) 48 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_MSVC()) 49 | # else 50 | # define FB_BOOST_PP_CONFIG_FLAGS() (FB_BOOST_PP_CONFIG_STRICT()) 51 | # endif 52 | # endif 53 | # 54 | # /* FB_BOOST_PP_CONFIG_EXTENDED_LINE_INFO */ 55 | # 56 | # ifndef FB_BOOST_PP_CONFIG_EXTENDED_LINE_INFO 57 | # define FB_BOOST_PP_CONFIG_EXTENDED_LINE_INFO 0 58 | # endif 59 | # 60 | # /* FB_BOOST_PP_CONFIG_ERRORS */ 61 | # 62 | # ifndef FB_BOOST_PP_CONFIG_ERRORS 63 | # ifdef NDEBUG 64 | # define FB_BOOST_PP_CONFIG_ERRORS 0 65 | # else 66 | # define FB_BOOST_PP_CONFIG_ERRORS 1 67 | # endif 68 | # endif 69 | # 70 | # endif 71 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/control/expr_if.hpp: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2001 2 | # * Housemarque Oy 3 | # * http://www.housemarque.com 4 | # * 5 | # * Distributed under the Boost Software License, Version 1.0. (See 6 | # * accompanying file LICENSE_1_0.txt or copy at 7 | # * http://www.boost.org/LICENSE_1_0.txt) 8 | # */ 9 | # 10 | # /* Revised by Paul Mensonides (2002) */ 11 | # 12 | # /* See http://www.boost.org for most recent version. */ 13 | # 14 | # ifndef FB_BOOST_PREPROCESSOR_CONTROL_EXPR_IF_HPP 15 | # define FB_BOOST_PREPROCESSOR_CONTROL_EXPR_IF_HPP 16 | # 17 | # include 18 | # include 19 | # include 20 | # 21 | # /* FB_BOOST_PP_EXPR_IF */ 22 | # 23 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 24 | # define FB_BOOST_PP_EXPR_IF(cond, expr) FB_BOOST_PP_EXPR_IIF(FB_BOOST_PP_BOOL(cond), expr) 25 | # else 26 | # define FB_BOOST_PP_EXPR_IF(cond, expr) FB_BOOST_PP_EXPR_IF_I(cond, expr) 27 | # define FB_BOOST_PP_EXPR_IF_I(cond, expr) FB_BOOST_PP_EXPR_IIF(FB_BOOST_PP_BOOL(cond), expr) 28 | # endif 29 | # 30 | # endif 31 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/control/expr_iif.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_CONTROL_EXPR_IIF_HPP 13 | # define FB_BOOST_PREPROCESSOR_CONTROL_EXPR_IIF_HPP 14 | # 15 | # include 16 | # 17 | # /* FB_BOOST_PP_EXPR_IIF */ 18 | # 19 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 20 | # define FB_BOOST_PP_EXPR_IIF(bit, expr) FB_BOOST_PP_EXPR_IIF_I(bit, expr) 21 | # else 22 | # define FB_BOOST_PP_EXPR_IIF(bit, expr) FB_BOOST_PP_EXPR_IIF_OO((bit, expr)) 23 | # define FB_BOOST_PP_EXPR_IIF_OO(par) FB_BOOST_PP_EXPR_IIF_I ## par 24 | # endif 25 | # 26 | # define FB_BOOST_PP_EXPR_IIF_I(bit, expr) FB_BOOST_PP_EXPR_IIF_ ## bit(expr) 27 | # 28 | # define FB_BOOST_PP_EXPR_IIF_0(expr) 29 | # define FB_BOOST_PP_EXPR_IIF_1(expr) expr 30 | # 31 | # endif 32 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/control/if.hpp: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2001 2 | # * Housemarque Oy 3 | # * http://www.housemarque.com 4 | # * 5 | # * Distributed under the Boost Software License, Version 1.0. (See 6 | # * accompanying file LICENSE_1_0.txt or copy at 7 | # * http://www.boost.org/LICENSE_1_0.txt) 8 | # */ 9 | # 10 | # /* Revised by Paul Mensonides (2002) */ 11 | # 12 | # /* See http://www.boost.org for most recent version. */ 13 | # 14 | # ifndef FB_BOOST_PREPROCESSOR_CONTROL_IF_HPP 15 | # define FB_BOOST_PREPROCESSOR_CONTROL_IF_HPP 16 | # 17 | # include 18 | # include 19 | # include 20 | # 21 | # /* FB_BOOST_PP_IF */ 22 | # 23 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 24 | # define FB_BOOST_PP_IF(cond, t, f) FB_BOOST_PP_IIF(FB_BOOST_PP_BOOL(cond), t, f) 25 | # else 26 | # define FB_BOOST_PP_IF(cond, t, f) FB_BOOST_PP_IF_I(cond, t, f) 27 | # define FB_BOOST_PP_IF_I(cond, t, f) FB_BOOST_PP_IIF(FB_BOOST_PP_BOOL(cond), t, f) 28 | # endif 29 | # 30 | # endif 31 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/control/iif.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_CONTROL_IIF_HPP 13 | # define FB_BOOST_PREPROCESSOR_CONTROL_IIF_HPP 14 | # 15 | # include 16 | # 17 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 18 | # define FB_BOOST_PP_IIF(bit, t, f) FB_BOOST_PP_IIF_I(bit, t, f) 19 | # else 20 | # define FB_BOOST_PP_IIF(bit, t, f) FB_BOOST_PP_IIF_OO((bit, t, f)) 21 | # define FB_BOOST_PP_IIF_OO(par) FB_BOOST_PP_IIF_I ## par 22 | # endif 23 | # 24 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MSVC() 25 | # define FB_BOOST_PP_IIF_I(bit, t, f) FB_BOOST_PP_IIF_ ## bit(t, f) 26 | # else 27 | # define FB_BOOST_PP_IIF_I(bit, t, f) FB_BOOST_PP_IIF_II(FB_BOOST_PP_IIF_ ## bit(t, f)) 28 | # define FB_BOOST_PP_IIF_II(id) id 29 | # endif 30 | # 31 | # define FB_BOOST_PP_IIF_0(t, f) f 32 | # define FB_BOOST_PP_IIF_1(t, f) t 33 | # 34 | # endif 35 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/debug/error.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_DEBUG_ERROR_HPP 13 | # define FB_BOOST_PREPROCESSOR_DEBUG_ERROR_HPP 14 | # 15 | # include 16 | # include 17 | # 18 | # /* FB_BOOST_PP_ERROR */ 19 | # 20 | # if FB_BOOST_PP_CONFIG_ERRORS 21 | # define FB_BOOST_PP_ERROR(code) FB_BOOST_PP_CAT(FB_BOOST_PP_ERROR_, code) 22 | # endif 23 | # 24 | # define FB_BOOST_PP_ERROR_0x0000 FB_BOOST_PP_ERROR(0x0000, FB_BOOST_PP_INDEX_OUT_OF_BOUNDS) 25 | # define FB_BOOST_PP_ERROR_0x0001 FB_BOOST_PP_ERROR(0x0001, FB_BOOST_PP_WHILE_OVERFLOW) 26 | # define FB_BOOST_PP_ERROR_0x0002 FB_BOOST_PP_ERROR(0x0002, FB_BOOST_PP_FOR_OVERFLOW) 27 | # define FB_BOOST_PP_ERROR_0x0003 FB_BOOST_PP_ERROR(0x0003, FB_BOOST_PP_REPEAT_OVERFLOW) 28 | # define FB_BOOST_PP_ERROR_0x0004 FB_BOOST_PP_ERROR(0x0004, FB_BOOST_PP_LIST_FOLD_OVERFLOW) 29 | # define FB_BOOST_PP_ERROR_0x0005 FB_BOOST_PP_ERROR(0x0005, FB_BOOST_PP_SEQ_FOLD_OVERFLOW) 30 | # define FB_BOOST_PP_ERROR_0x0006 FB_BOOST_PP_ERROR(0x0006, FB_BOOST_PP_ARITHMETIC_OVERFLOW) 31 | # define FB_BOOST_PP_ERROR_0x0007 FB_BOOST_PP_ERROR(0x0007, FB_BOOST_PP_DIVISION_BY_ZERO) 32 | # 33 | # endif 34 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/facilities/empty.hpp: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2001 2 | # * Housemarque Oy 3 | # * http://www.housemarque.com 4 | # * 5 | # * Distributed under the Boost Software License, Version 1.0. (See 6 | # * accompanying file LICENSE_1_0.txt or copy at 7 | # * http://www.boost.org/LICENSE_1_0.txt) 8 | # */ 9 | # 10 | # /* Revised by Paul Mensonides (2002) */ 11 | # 12 | # /* See http://www.boost.org for most recent version. */ 13 | # 14 | # ifndef FB_BOOST_PREPROCESSOR_FACILITIES_EMPTY_HPP 15 | # define FB_BOOST_PREPROCESSOR_FACILITIES_EMPTY_HPP 16 | # 17 | # /* FB_BOOST_PP_EMPTY */ 18 | # 19 | # define FB_BOOST_PP_EMPTY() 20 | # 21 | # endif 22 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/seq/for_each_i.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_SEQ_FOR_EACH_I_HPP 13 | # define FB_BOOST_PREPROCESSOR_SEQ_FOR_EACH_I_HPP 14 | # 15 | # include 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include 23 | # 24 | # /* FB_BOOST_PP_SEQ_FOR_EACH_I */ 25 | # 26 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 27 | # define FB_BOOST_PP_SEQ_FOR_EACH_I(macro, data, seq) FB_BOOST_PP_FOR((macro, data, seq (nil), 0), FB_BOOST_PP_SEQ_FOR_EACH_I_P, FB_BOOST_PP_SEQ_FOR_EACH_I_O, FB_BOOST_PP_SEQ_FOR_EACH_I_M) 28 | # else 29 | # define FB_BOOST_PP_SEQ_FOR_EACH_I(macro, data, seq) FB_BOOST_PP_SEQ_FOR_EACH_I_I(macro, data, seq) 30 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_I(macro, data, seq) FB_BOOST_PP_FOR((macro, data, seq (nil), 0), FB_BOOST_PP_SEQ_FOR_EACH_I_P, FB_BOOST_PP_SEQ_FOR_EACH_I_O, FB_BOOST_PP_SEQ_FOR_EACH_I_M) 31 | # endif 32 | # 33 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_P(r, x) FB_BOOST_PP_DEC(FB_BOOST_PP_SEQ_SIZE(FB_BOOST_PP_TUPLE_ELEM(4, 2, x))) 34 | # 35 | # if FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_STRICT() 36 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_O(r, x) FB_BOOST_PP_SEQ_FOR_EACH_I_O_I x 37 | # else 38 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_O(r, x) FB_BOOST_PP_SEQ_FOR_EACH_I_O_I(FB_BOOST_PP_TUPLE_ELEM(4, 0, x), FB_BOOST_PP_TUPLE_ELEM(4, 1, x), FB_BOOST_PP_TUPLE_ELEM(4, 2, x), FB_BOOST_PP_TUPLE_ELEM(4, 3, x)) 39 | # endif 40 | # 41 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_O_I(macro, data, seq, i) (macro, data, FB_BOOST_PP_SEQ_TAIL(seq), FB_BOOST_PP_INC(i)) 42 | # 43 | # if FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_STRICT() 44 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_M(r, x) FB_BOOST_PP_SEQ_FOR_EACH_I_M_IM(r, FB_BOOST_PP_TUPLE_REM_4 x) 45 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_M_IM(r, im) FB_BOOST_PP_SEQ_FOR_EACH_I_M_I(r, im) 46 | # else 47 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_M(r, x) FB_BOOST_PP_SEQ_FOR_EACH_I_M_I(r, FB_BOOST_PP_TUPLE_ELEM(4, 0, x), FB_BOOST_PP_TUPLE_ELEM(4, 1, x), FB_BOOST_PP_TUPLE_ELEM(4, 2, x), FB_BOOST_PP_TUPLE_ELEM(4, 3, x)) 48 | # endif 49 | # 50 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_M_I(r, macro, data, seq, i) macro(r, data, i, FB_BOOST_PP_SEQ_HEAD(seq)) 51 | # 52 | # /* FB_BOOST_PP_SEQ_FOR_EACH_I_R */ 53 | # 54 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 55 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_R(r, macro, data, seq) FB_BOOST_PP_FOR_ ## r((macro, data, seq (nil), 0), FB_BOOST_PP_SEQ_FOR_EACH_I_P, FB_BOOST_PP_SEQ_FOR_EACH_I_O, FB_BOOST_PP_SEQ_FOR_EACH_I_M) 56 | # else 57 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_R(r, macro, data, seq) FB_BOOST_PP_SEQ_FOR_EACH_I_R_I(r, macro, data, seq) 58 | # define FB_BOOST_PP_SEQ_FOR_EACH_I_R_I(r, macro, data, seq) FB_BOOST_PP_FOR_ ## r((macro, data, seq (nil), 0), FB_BOOST_PP_SEQ_FOR_EACH_I_P, FB_BOOST_PP_SEQ_FOR_EACH_I_O, FB_BOOST_PP_SEQ_FOR_EACH_I_M) 59 | # endif 60 | # 61 | # endif 62 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/seq/seq.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_SEQ_SEQ_HPP 13 | # define FB_BOOST_PREPROCESSOR_SEQ_SEQ_HPP 14 | # 15 | # include 16 | # include 17 | # 18 | # /* FB_BOOST_PP_SEQ_HEAD */ 19 | # 20 | # define FB_BOOST_PP_SEQ_HEAD(seq) FB_BOOST_PP_SEQ_ELEM(0, seq) 21 | # 22 | # /* FB_BOOST_PP_SEQ_TAIL */ 23 | # 24 | # if FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 25 | # define FB_BOOST_PP_SEQ_TAIL(seq) FB_BOOST_PP_SEQ_TAIL_1((seq)) 26 | # define FB_BOOST_PP_SEQ_TAIL_1(par) FB_BOOST_PP_SEQ_TAIL_2 ## par 27 | # define FB_BOOST_PP_SEQ_TAIL_2(seq) FB_BOOST_PP_SEQ_TAIL_I ## seq 28 | # elif FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MSVC() 29 | # define FB_BOOST_PP_SEQ_TAIL(seq) FB_BOOST_PP_SEQ_TAIL_ID(FB_BOOST_PP_SEQ_TAIL_I seq) 30 | # define FB_BOOST_PP_SEQ_TAIL_ID(id) id 31 | # elif FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 32 | # define FB_BOOST_PP_SEQ_TAIL(seq) FB_BOOST_PP_SEQ_TAIL_D(seq) 33 | # define FB_BOOST_PP_SEQ_TAIL_D(seq) FB_BOOST_PP_SEQ_TAIL_I seq 34 | # else 35 | # define FB_BOOST_PP_SEQ_TAIL(seq) FB_BOOST_PP_SEQ_TAIL_I seq 36 | # endif 37 | # 38 | # define FB_BOOST_PP_SEQ_TAIL_I(x) 39 | # 40 | # /* FB_BOOST_PP_SEQ_NIL */ 41 | # 42 | # define FB_BOOST_PP_SEQ_NIL(x) (x) 43 | # 44 | # endif 45 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/tuple/eat.hpp: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2001 2 | # * Housemarque Oy 3 | # * http://www.housemarque.com 4 | # * 5 | # * Distributed under the Boost Software License, Version 1.0. (See 6 | # * accompanying file LICENSE_1_0.txt or copy at 7 | # * http://www.boost.org/LICENSE_1_0.txt) 8 | # */ 9 | # 10 | # /* Revised by Paul Mensonides (2002) */ 11 | # 12 | # /* See http://www.boost.org for most recent version. */ 13 | # 14 | # ifndef FB_BOOST_PREPROCESSOR_TUPLE_EAT_HPP 15 | # define FB_BOOST_PREPROCESSOR_TUPLE_EAT_HPP 16 | # 17 | # include 18 | # 19 | # /* FB_BOOST_PP_TUPLE_EAT */ 20 | # 21 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 22 | # define FB_BOOST_PP_TUPLE_EAT(size) FB_BOOST_PP_TUPLE_EAT_I(size) 23 | # else 24 | # define FB_BOOST_PP_TUPLE_EAT(size) FB_BOOST_PP_TUPLE_EAT_OO((size)) 25 | # define FB_BOOST_PP_TUPLE_EAT_OO(par) FB_BOOST_PP_TUPLE_EAT_I ## par 26 | # endif 27 | # 28 | # define FB_BOOST_PP_TUPLE_EAT_I(size) FB_BOOST_PP_TUPLE_EAT_ ## size 29 | # 30 | # define FB_BOOST_PP_TUPLE_EAT_0() 31 | # define FB_BOOST_PP_TUPLE_EAT_1(a) 32 | # define FB_BOOST_PP_TUPLE_EAT_2(a, b) 33 | # define FB_BOOST_PP_TUPLE_EAT_3(a, b, c) 34 | # define FB_BOOST_PP_TUPLE_EAT_4(a, b, c, d) 35 | # define FB_BOOST_PP_TUPLE_EAT_5(a, b, c, d, e) 36 | # define FB_BOOST_PP_TUPLE_EAT_6(a, b, c, d, e, f) 37 | # define FB_BOOST_PP_TUPLE_EAT_7(a, b, c, d, e, f, g) 38 | # define FB_BOOST_PP_TUPLE_EAT_8(a, b, c, d, e, f, g, h) 39 | # define FB_BOOST_PP_TUPLE_EAT_9(a, b, c, d, e, f, g, h, i) 40 | # define FB_BOOST_PP_TUPLE_EAT_10(a, b, c, d, e, f, g, h, i, j) 41 | # define FB_BOOST_PP_TUPLE_EAT_11(a, b, c, d, e, f, g, h, i, j, k) 42 | # define FB_BOOST_PP_TUPLE_EAT_12(a, b, c, d, e, f, g, h, i, j, k, l) 43 | # define FB_BOOST_PP_TUPLE_EAT_13(a, b, c, d, e, f, g, h, i, j, k, l, m) 44 | # define FB_BOOST_PP_TUPLE_EAT_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) 45 | # define FB_BOOST_PP_TUPLE_EAT_15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) 46 | # define FB_BOOST_PP_TUPLE_EAT_16(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) 47 | # define FB_BOOST_PP_TUPLE_EAT_17(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) 48 | # define FB_BOOST_PP_TUPLE_EAT_18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) 49 | # define FB_BOOST_PP_TUPLE_EAT_19(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) 50 | # define FB_BOOST_PP_TUPLE_EAT_20(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) 51 | # define FB_BOOST_PP_TUPLE_EAT_21(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) 52 | # define FB_BOOST_PP_TUPLE_EAT_22(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) 53 | # define FB_BOOST_PP_TUPLE_EAT_23(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) 54 | # define FB_BOOST_PP_TUPLE_EAT_24(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) 55 | # define FB_BOOST_PP_TUPLE_EAT_25(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) 56 | # 57 | # endif 58 | -------------------------------------------------------------------------------- /src/native/fbjava/include/firebird/impl/boost/preprocessor/tuple/rem.hpp: -------------------------------------------------------------------------------- 1 | # /* ************************************************************************** 2 | # * * 3 | # * (C) Copyright Paul Mensonides 2002. 4 | # * Distributed under the Boost Software License, Version 1.0. (See 5 | # * accompanying file LICENSE_1_0.txt or copy at 6 | # * http://www.boost.org/LICENSE_1_0.txt) 7 | # * * 8 | # ************************************************************************** */ 9 | # 10 | # /* See http://www.boost.org for most recent version. */ 11 | # 12 | # ifndef FB_BOOST_PREPROCESSOR_TUPLE_REM_HPP 13 | # define FB_BOOST_PREPROCESSOR_TUPLE_REM_HPP 14 | # 15 | # include 16 | # 17 | # /* FB_BOOST_PP_TUPLE_REM */ 18 | # 19 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 20 | # define FB_BOOST_PP_TUPLE_REM(size) FB_BOOST_PP_TUPLE_REM_I(size) 21 | # else 22 | # define FB_BOOST_PP_TUPLE_REM(size) FB_BOOST_PP_TUPLE_REM_OO((size)) 23 | # define FB_BOOST_PP_TUPLE_REM_OO(par) FB_BOOST_PP_TUPLE_REM_I ## par 24 | # endif 25 | # 26 | # define FB_BOOST_PP_TUPLE_REM_I(size) FB_BOOST_PP_TUPLE_REM_ ## size 27 | # 28 | # define FB_BOOST_PP_TUPLE_REM_0() 29 | # define FB_BOOST_PP_TUPLE_REM_1(a) a 30 | # define FB_BOOST_PP_TUPLE_REM_2(a, b) a, b 31 | # define FB_BOOST_PP_TUPLE_REM_3(a, b, c) a, b, c 32 | # define FB_BOOST_PP_TUPLE_REM_4(a, b, c, d) a, b, c, d 33 | # define FB_BOOST_PP_TUPLE_REM_5(a, b, c, d, e) a, b, c, d, e 34 | # define FB_BOOST_PP_TUPLE_REM_6(a, b, c, d, e, f) a, b, c, d, e, f 35 | # define FB_BOOST_PP_TUPLE_REM_7(a, b, c, d, e, f, g) a, b, c, d, e, f, g 36 | # define FB_BOOST_PP_TUPLE_REM_8(a, b, c, d, e, f, g, h) a, b, c, d, e, f, g, h 37 | # define FB_BOOST_PP_TUPLE_REM_9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i 38 | # define FB_BOOST_PP_TUPLE_REM_10(a, b, c, d, e, f, g, h, i, j) a, b, c, d, e, f, g, h, i, j 39 | # define FB_BOOST_PP_TUPLE_REM_11(a, b, c, d, e, f, g, h, i, j, k) a, b, c, d, e, f, g, h, i, j, k 40 | # define FB_BOOST_PP_TUPLE_REM_12(a, b, c, d, e, f, g, h, i, j, k, l) a, b, c, d, e, f, g, h, i, j, k, l 41 | # define FB_BOOST_PP_TUPLE_REM_13(a, b, c, d, e, f, g, h, i, j, k, l, m) a, b, c, d, e, f, g, h, i, j, k, l, m 42 | # define FB_BOOST_PP_TUPLE_REM_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) a, b, c, d, e, f, g, h, i, j, k, l, m, n 43 | # define FB_BOOST_PP_TUPLE_REM_15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o 44 | # define FB_BOOST_PP_TUPLE_REM_16(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p 45 | # define FB_BOOST_PP_TUPLE_REM_17(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q 46 | # define FB_BOOST_PP_TUPLE_REM_18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r 47 | # define FB_BOOST_PP_TUPLE_REM_19(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s 48 | # define FB_BOOST_PP_TUPLE_REM_20(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t 49 | # define FB_BOOST_PP_TUPLE_REM_21(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u 50 | # define FB_BOOST_PP_TUPLE_REM_22(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v 51 | # define FB_BOOST_PP_TUPLE_REM_23(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w 52 | # define FB_BOOST_PP_TUPLE_REM_24(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x 53 | # define FB_BOOST_PP_TUPLE_REM_25(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y 54 | # 55 | # /* FB_BOOST_PP_TUPLE_REM_CTOR */ 56 | # 57 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_EDG() 58 | # define FB_BOOST_PP_TUPLE_REM_CTOR(size, tuple) FB_BOOST_PP_TUPLE_REM_CTOR_I(FB_BOOST_PP_TUPLE_REM(size), tuple) 59 | # else 60 | # define FB_BOOST_PP_TUPLE_REM_CTOR(size, tuple) FB_BOOST_PP_TUPLE_REM_CTOR_D(size, tuple) 61 | # define FB_BOOST_PP_TUPLE_REM_CTOR_D(size, tuple) FB_BOOST_PP_TUPLE_REM_CTOR_I(FB_BOOST_PP_TUPLE_REM(size), tuple) 62 | # endif 63 | # 64 | # if ~FB_BOOST_PP_CONFIG_FLAGS() & FB_BOOST_PP_CONFIG_MWCC() 65 | # define FB_BOOST_PP_TUPLE_REM_CTOR_I(ext, tuple) ext tuple 66 | # else 67 | # define FB_BOOST_PP_TUPLE_REM_CTOR_I(ext, tuple) FB_BOOST_PP_TUPLE_REM_CTOR_OO((ext, tuple)) 68 | # define FB_BOOST_PP_TUPLE_REM_CTOR_OO(par) FB_BOOST_PP_TUPLE_REM_CTOR_II ## par 69 | # define FB_BOOST_PP_TUPLE_REM_CTOR_II(ext, tuple) ext ## tuple 70 | # endif 71 | # 72 | # endif 73 | -------------------------------------------------------------------------------- /src/native/fbjava/include/ib_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PROGRAM: UDF and Blob filter Utilities library 3 | * MODULE: ib_util.h 4 | * DESCRIPTION: Prototype header file for ib_util.c 5 | * 6 | * The contents of this file are subject to the Interbase Public 7 | * License Version 1.0 (the "License"); you may not use this file 8 | * except in compliance with the License. You may obtain a copy 9 | * of the License at http://www.Inprise.com/IPL.html 10 | * 11 | * Software distributed under the License is distributed on an 12 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express 13 | * or implied. See the License for the specific language governing 14 | * rights and limitations under the License. 15 | * 16 | * The Original Code was created by Inprise Corporation 17 | * and its predecessors. Portions created by Inprise Corporation are 18 | * Copyright (C) Inprise Corporation. 19 | * 20 | * All Rights Reserved. 21 | * Contributor(s): ______________________________________. 22 | */ 23 | 24 | #ifndef _IB_UTIL_H 25 | #define _IB_UTIL_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern void *ib_util_malloc(long); 32 | 33 | #ifdef __cplusplus 34 | } /* extern "C" */ 35 | #endif 36 | 37 | #endif /* _IB_UTIL_H */ 38 | --------------------------------------------------------------------------------