ラベル H2Database_JCIFS の投稿を表示しています。 すべての投稿を表示
ラベル H2Database_JCIFS の投稿を表示しています。 すべての投稿を表示

2010年11月18日木曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの共有セキュリティを列挙する関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの共有セキュリティを列挙する関数を作成するには、以下のスクリプトを実行します。

drop alias if exists jcifs_get_share_security;
create alias if not exists jcifs_get_share_security as $$
import java.io.*;
import java.sql.*;
import java.util.*;
import jcifs.smb.*;
import org.h2.tools.*;
@CODE
ResultSet jcifs_get_share_security(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 512, 0);
rs.addColumn("FILE_APPEND_DATA", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_DELETE", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_EXECUTE", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_READ_ATTRIBUTES", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_READ_DATA", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_READ_EA", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_WRITE_ATTRIBUTES", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_WRITE_DATA", Types.BOOLEAN, 1, 0);
rs.addColumn("FILE_WRITE_EA", Types.BOOLEAN, 1, 0);

SmbFile sfile = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename);
ACE ace[] = sfile.getShareSecurity(true);

for(int fi=0;fi<ace.length;fi++){
rs.addRow(ace[fi].getSID().toDisplayString(),
((ace[fi].getAccessMask() & ACE.FILE_APPEND_DATA) != 0),
((ace[fi].getAccessMask() & ACE.FILE_DELETE) != 0),
((ace[fi].getAccessMask() & ACE.FILE_EXECUTE) != 0),
((ace[fi].getAccessMask() & ACE.FILE_READ_ATTRIBUTES) != 0),
((ace[fi].getAccessMask() & ACE.FILE_READ_DATA) != 0),
((ace[fi].getAccessMask() & ACE.FILE_READ_EA) != 0),
((ace[fi].getAccessMask() & ACE.FILE_WRITE_ATTRIBUTES) != 0),
((ace[fi].getAccessMask() & ACE.FILE_WRITE_DATA) != 0),
((ace[fi].getAccessMask() & ACE.FILE_WRITE_EA) != 0)
);
}
return rs;
}
$$


実行例
call jcifs_get_share_security('LIFERAY1', 
'test1', 'test1', 'liferay1',
'share', 'acetest.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月17日水曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの読み取り専用を外す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの読み取り専用を外す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_set_readwrite as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_set_readwrite(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

file.setReadWrite();
return 0;
}
$$


実行例
call jcifs_set_readwrite(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月16日火曜日

H2 DatabaseとJCIFSでWindows共有上のファイルをリードオンリーに設定する関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルをリードオンリーに設定する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_set_readonly as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_set_readonly(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

file.setReadOnly();
return 0;
}
$$


実行例
call jcifs_set_readonly(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月15日月曜日

H2 DatabaseとJCIFSでWindows共有上のファイルがリードオンリーかどうかを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルがリードオンリーかどうかを返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_is_readonly as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Boolean jcifs_is_readonly(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Boolean(!file.canWrite());
}
$$


実行例
select jcifs_is_readonly(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'readonly.txt');
select jcifs_is_readonly(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月14日日曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの最終更新日時を設定する関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの最終更新日時を設定する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_set_last_modified as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_set_last_modified(String domain,
String user, String password, String server,
String path, String filename, Timestamp ts)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}
if( ts == null ){
throw new Exception("timestamp is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

file.setLastModified(ts.getTime());
return 0;
}
$$


実行例
select jcifs_set_last_modified(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt',
cast('2010-10-12 12:34:56' as timestamp));


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月13日土曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの作成時間を設定する関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの作成時間を設定する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_set_create_time as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_set_create_time(String domain,
String user, String password, String server,
String path, String filename, Timestamp ts)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}
if( ts == null ){
throw new Exception("timestamp is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

file.setCreateTime(ts.getTime());
return 0;
}
$$


実行例
select jcifs_set_create_time(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt',
cast('2010-10-12 12:34:56' as timestamp));


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月12日金曜日

H2 DatabaseとJCIFSでWindows共有上のファイルをリネームする関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルをリネームする関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_rename as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_rename(String domain,
String user, String password, String server,
String path, String filename, String filename2)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}
if( filename2 == null ){
throw new Exception("filename2 is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);
SmbFile file2 = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename2
);

file.renameTo(file2);
return 0;
}
$$


実行例
select jcifs_rename(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt', 'renamed_test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月11日木曜日

H2 DatabaseとJCIFSでWindows共有上にディレクトリを作成する関数を作成する

H2 DatabaseとJCIFSでWindows共有上にディレクトリを作成する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_mkdirs as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_mkdirs(String domain,
String user, String password, String server,
String path)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path
);

file.mkdirs();
return 0;
}
$$


実行例
call jcifs_mkdirs(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share/test_directory');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月10日水曜日

H2 DatabaseとJCIFSでWindows共有上のパスが隠しファイルかどうかを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のパスが隠しファイルかどうかを返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_is_hidden as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Boolean jcifs_is_hidden(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Boolean(file.isHidden());
}
$$


実行例
select jcifs_is_hidden(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'hidden.txt');
select jcifs_is_hidden(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月9日火曜日

H2 DatabaseとJCIFSでWindows共有上のパスがファイルかどうかを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のパスがファイルかどうかを返す関数を作成するには、以下のコードを実行します。

create alias if not exists jcifs_is_file as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Boolean jcifs_is_file(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Boolean(file.isFile());
}
$$


実行例
select jcifs_is_file(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'testdir');
select jcifs_is_file(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月8日月曜日

H2 DatabaseとJCIFSでWindows共有上のパスがディレクトリかどうかを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のパスがディレクトリかどうかを返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_is_directory as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Boolean jcifs_is_directory(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Boolean(file.isDirectory());
}
$$


実行例
select jcifs_is_directory(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'testdir');
select jcifs_is_directory(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'test.txt');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月7日日曜日

H2 DatabaseとJCIFSでWindows共有上のパスの親パスを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のパスの親パスを返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_get_parent as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
String jcifs_get_parent(String domain,
String user, String password, String server,
String path)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path
);

return file.getParent();
}
$$


実行例
select jcifs_get_parent(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share/H2');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月6日土曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの最終更新日時を返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの最終更新日時を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_get_last_modified as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Timestamp jcifs_get_last_modified(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Timestamp(file.getLastModified());
}
$$


実行例
select jcifs_get_last_modified(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF.JPG');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月5日金曜日

H2 DatabaseとJCIFSでWindows共有上の空きスペースを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上の空きスペースを返す関数を作成するには、以下のコードを実行します。

create alias if not exists jcifs_get_freesize as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
long jcifs_get_freesize(String domain,
String user, String password, String server,
String path)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path
);

return file.getDiskFreeSpace();
}
$$


実行例
select jcifs_get_freesize(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月4日木曜日

H2 DatabaseとJCIFSでWindows共有上のファイルのサイズを返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルのサイズを返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_get_filesize as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
long jcifs_get_filesize(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return file.length();
}
$$


実行例
select jcifs_get_filesize(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF.JPG');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月3日水曜日

H2 DatabaseとJCIFSでWindows共有上のファイルを削除する関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルを削除する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_delete_file as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_delete_file(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

file.delete();

return 0;
}
$$


実行例
call jcifs_delete_file(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF2.JPG');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月2日火曜日

H2 DatabaseとJCIFSでWindows共有上のファイルの作成日時を返す関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルの作成日時を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_get_create_time as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
Timestamp jcifs_get_create_time(String domain,
String user, String password, String server,
String path, String filename)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);

return new Timestamp(file.createTime());
}
$$


実行例
select jcifs_get_create_time(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF.JPG');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年11月1日月曜日

H2 DatabaseとJCIFSでWindows共有上のファイルをコピーする関数を作成する

H2 DatabaseとJCIFSでWindows共有上のファイルをコピーする関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_copy_file as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_copy_file(String domain,
String user, String password, String server,
String path, String filename,
String path2, String filename2)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}
if( path2 == null ){
throw new Exception("path2 is not specified.");
}
if( filename2 == null ){
throw new Exception("filename2 is not specified.");
}

SmbFile src = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename
);
SmbFile dst = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path2 + "/" + filename2
);
src.copyTo(dst);

return 0;
}
$$


実行例
call jcifs_copy_file(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF.JPG',
'share', 'SF2.JPG');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年10月31日日曜日

H2 DatabaseとJCIFSでBLOBをファイルとしてWindows共有上にアップロードする関数を作成する

H2 DatabaseとJCIFSでBLOBをファイルとしてWindows共有上にアップロードする関数を作成するには、以下のスクリプトを実行します。

drop alias jcifs_put_binary;
create alias if not exists jcifs_put_binary as $$
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_put_binary(String domain,
String user, String password, String server,
String path, String filename, Blob blob)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}


OutputStream os = null;
InputStream bis = null;
try
{
os = new SmbFileOutputStream(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename);
bis = blob.getBinaryStream();

byte buf[] = new byte[8192];
int rs = -1;
while( (rs = bis.read(buf)) != -1 ){
os.write(buf, 0, rs);
}
}
finally
{
if( os != null )os.close();
if( bis != null )bis.close();
}

return 0;
}
$$


実行例
drop table if exists blobtest;
create table blobtest (c1 numeric(4), c2 blob);
insert into blobtest values (1,
jcifs_get_binary('LIFERAY1',
'test1', 'test1', 'liferay1',
'share', 'SF.JPG')
);
select jcifs_put_binary('LIFERAY1',
'test1', 'test1', 'liferay1',
'share/h2', 'renamed_SF.JPG', c2)
from blobtest
where c1 = 1;


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

2010年10月30日土曜日

H2 DatabaseとJCIFSでCLOBをファイルとしてWindows共有上にアップロードする関数を作成する

H2 DatabaseとJCIFSでCLOBをファイルとしてWindows共有上にアップロードする関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_put_ascii as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_put_ascii(String domain,
String user, String password, String server,
String path, String filename, Clob clob)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}
if( filename == null ){
throw new Exception("filename is not specified.");
}


OutputStream os = null;
InputStream ais = null;
try
{
os = new SmbFileOutputStream(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path + "/" + filename);
ais = clob.getAsciiStream();

byte buf[] = new byte[8192];
int rs = -1;
while( (rs = ais.read(buf)) != -1 ){
os.write(buf, 0, rs);
}
}
finally
{
if( os != null )os.close();
if( ais != null )ais.close();
}

return 0;
}
$$


実行例
drop table if exists clobtest;
create table clobtest (c1 numeric(4), c2 clob);
insert into clobtest values (1,
jcifs_get_ascii('LIFERAY1',
'test1', 'test1', 'liferay1',
'share/h2', 'titles.txt')
);
select jcifs_put_ascii('LIFERAY1',
'test1', 'test1', 'liferay1',
'share/h2', 'renamed_titles.txt', c2)
from clobtest
where c1 = 1;


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。