2011年1月23日日曜日

Apache Derbyで指定された時間スリープする関数を作成する

Apache Derbyで指定された時間スリープする関数を作成するには、以下の手順を実行します。

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

public class SleepFunction
{
public static Long sleep(Long millis)
throws Exception
{
Thread.sleep(millis);
return millis;
}
}

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\SleepFunction.jar"
basedir="build"/>
</target>
<target name="clean">
<delete dir="build" />
</target>
</project>


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


3.クラスパスに通す
call syscs_util.syscs_set_database_property('derby.database.classpath', 'APP.func2');

※複数のjarの場合は'APP.func1:APP.func2'のように「:」で区切る。
4.関数を作成
create function sleep(millis bigint) returns bigint
parameter style java no sql language java
external name 'com.serverarekore.derby.SleepFunction.sleep';


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

0 件のコメント:

コメントを投稿