基于Oracle的数据缓存实现
1,在Oracle上建立一个Java source程序,用于更新本地文件:
create or replace and compile java source named javaupdatefile as
import java.io.*;
public class UpdFile
{
public static void updateFile(String filename)
{
try{
File f = new File(filename);
f.delete();
f.createNewFile();
}catch{IOException e){
//log exception
}
}
};
2,建立一个PL/SQL包,用于调用Java程序:
create or replace package cacheTest
as
procedure upd_File(p_filename varchar2)
is language Java name 'UpdFile.updateFile(java.lang.String)';
end catcheTest;
3,在表上建立触发器(表名为test):
create or replace trigger cacheTest
after update on test
for each row
declare
begin
cacheTest.upd_File('d:\\Cache_testing.txt');
end cacheTest;
4,给数据库用户赋于执行更新文件的权限(这里的数据库连接用户为TEST):
execute dbms_java.grant_permission('TEST','SYS:java.io.FilePermission','d:\Cache_testing.txt','delete');
execute dbms_java.grant_permission('TEST','SYS:java.io.FilePermission','d:\Cache_testing.txt','write');