2011年1月31日月曜日

Apache Derbyで指定されたパスの親ディレクトリを返す関数を作成する

Apache Derbyで指定されたパスの親ディレクトリを返す関数を作成するには、以下の手順を実行します。

1.以下のクラスをantでコンパイルします。
FsGetParentFunction.java
package com.serverarekore.derby;
import java.io.*;
import java.sql.*;
import java.net.*;

public class FsGetParentFunction
{
public static String fs_get_parent(String path)
{
if( path == null )return null;
File file = new File(path);
return file.getParent();
}
}

build.xmlファイル例
<project name="DerbyFunctions" default="compile" basedir=".">
<path id="lib.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile">
<echo message="project: ${ant.project.name}"/>
<mkdir dir="build/" />
<javac srcdir="src/" destdir="build/"
deprecation="on" debug="on">
<classpath>
<path refid="lib.classpath"/>
</classpath>
</javac>
<jar destfile="c:\share\derby_funcs\FsGetParentFunction.jar"
basedir="build"/>
</target>
<target name="clean">
<delete dir="build" />
</target>
</project>


2.derbyにjarをインストール
call sqlj.install_jar('c:\share\derby_funcs\FsGetParentFunction.jar', 'APP.func6', 0);


3.クラスパスに通す
call syscs_util.syscs_set_database_property('derby.database.classpath', 'APP.func6');
※複数のjarの場合は'APP.func1:APP.func2'のように「:」で区切る。

4.関数を作成
create function fs_get_parent(path varchar(1024)) 
returns varchar(1024)
parameter style java no sql language java
external name 'com.serverarekore.derby.FsGetParentFunction.fs_get_parent';


5.実行
select fs_get_parent('c:\windows\windows.ini') from sysibm.sysdummy1;
○関連情報
・Apache Derbyに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿