├── .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 |
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 |
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 |
43 |
70 |
71 |
75 |
76 |
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 |
43 |
70 |
71 |
75 |
76 |
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 |
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 |
43 |
70 |
71 |
74 | No usage of org.firebirdsql.fbjava.ExternalResultSet
75 |
76 |
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 |
43 |
70 |
71 |
74 |
102 |
103 |
120 |
121 |
122 | - Prev
123 | - Next
124 |
125 |
129 |
132 |
133 |
143 |
144 |
145 |
146 |
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 |
43 |
70 |
71 |
74 |
102 |
103 |
120 |
121 |
122 | - Prev
123 | - Next
124 |
125 |
129 |
132 |
133 |
143 |
144 |
145 |
146 |
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 |
43 |
70 |
71 |
74 |
102 |
103 |
120 |
121 |
122 | - Prev
123 | - Next
124 |
125 |
129 |
132 |
133 |
143 |
144 |
145 |
146 |
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 |
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