Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
02faee5e
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
02faee5e
编写于
5月 05, 2000
作者:
P
Peter Mount
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ImageViewer transaction fixes
上级
2937bf0a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
66 addition
and
40 deletion
+66
-40
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/CHANGELOG
+6
-2
src/interfaces/jdbc/Makefile
src/interfaces/jdbc/Makefile
+31
-10
src/interfaces/jdbc/example/ImageViewer.java
src/interfaces/jdbc/example/ImageViewer.java
+29
-28
未找到文件。
src/interfaces/jdbc/CHANGELOG
浏览文件 @
02faee5e
Wed May 02 16:47:00 BST 2000 petermount@it.maidstone.gov.uk
Thu May 04 11:38:00 BST 2000 petermount@it.maidstone.gov.uk
- Corrected incorrect date in CHANGELOG
- Fixed the ImageViewer example
Wed May 03 16:47:00 BST 2000 petermount@it.maidstone.gov.uk
- Fixed the Makefile so that postgresql.jar is built everytime
the jdbc1 or jdbc2 rules are called.
- Fixed the threadsafe example. It had problems with autocommit
Wed May 0
2
14:32:00 BST 2000 petermount@it.maidstone.gov.uk
Wed May 0
3
14:32:00 BST 2000 petermount@it.maidstone.gov.uk
- Rewrote the README file (the old one was 18 months old!)
- Added @deprecated tags to org.postgresql.jdbc2.ResultSet
to clear some warnings issued during compilation.
...
...
src/interfaces/jdbc/Makefile
浏览文件 @
02faee5e
...
...
@@ -4,7 +4,7 @@
# Makefile for Java JDBC interface
#
# IDENTIFICATION
# $Id: Makefile,v 1.2
0 2000/05/03 15:58:08
peter Exp $
# $Id: Makefile,v 1.2
1 2000/05/05 07:35:29
peter Exp $
#
#-------------------------------------------------------------------------
...
...
@@ -68,10 +68,14 @@ msg:
@
echo
@
echo
------------------------------------------------------------
@
echo
To build the examples,
type
:
@
echo
" make examples"
@
echo
"JDBC1: make examples"
@
echo
"JDBC2: make examples2"
@
echo
@
echo
"To build the CORBA example (requires Java2):"
@
echo
" make corba"
@
echo
@
echo
"To make the tests, type:"
@
echo
" make tests"
@
echo
------------------------------------------------------------
@
echo
...
...
@@ -214,12 +218,18 @@ $(PGBASE)/util/UnixCrypt.class: $(PGBASE)/util/UnixCrypt.java
#######################################################################
# These classes are in the example directory, and form the examples
EX
=
example/basic.class
\
example/blobtest.class
\
example/datestyle.class
\
example/psql.class
\
example/ImageViewer.class
\
example/metadata.class
\
example/ImageViewer.class
# These are only valid for JDBC2
EX2
=
example/blobtest.class
# These are really test classes not true examples
TESTS
=
example/metadata.class
\
example/threadsafe.class
# Non functional/obsolete examples
# example/datestyle.class \
# example/Objects.class
# This rule builds the examples
...
...
@@ -229,20 +239,31 @@ examples: postgresql.jar $(EX)
@
echo
@
echo
For instructions on how to use them, simply run them. For example:
@
echo
@
echo
" java example.b
lobtest
"
@
echo
" java example.b
asic
"
@
echo
@
echo
This would display instructions on how to run the example.
@
echo
------------------------------------------------------------
@
echo
Available examples:
@
echo
@
echo
" example.basic Basic JDBC useage"
@
echo
" example.blobtest Binary Large Object tests"
@
echo
" example.datestyle Shows how datestyles are handled"
@
echo
" example.ImageViewer Example application storing images"
@
echo
" example.psql Simple java implementation of psql"
@
echo
" example.Objects Demonstrates Object Serialisation"
@
echo
" "
@
echo
These are not really examples, but tests various parts of the driver
@
echo
------------------------------------------------------------
@
echo
examples2
:
$(EX2) examples
@
echo
"The following JDBC2 only examples have also been built:"
@
echo
@
echo
" example.blobtest Binary Large Object tests"
@
echo
@
echo
------------------------------------------------------------
@
echo
tests
:
$(TESTS)
@
echo
------------------------------------------------------------
@
echo
The following tests have been built:
@
echo
" example.metadata Tests various metadata methods"
@
echo
" example.threadsafe Tests the driver's thread safety"
@
echo
------------------------------------------------------------
...
...
src/interfaces/jdbc/example/ImageViewer.java
浏览文件 @
02faee5e
...
...
@@ -186,15 +186,11 @@ public class ImageViewer implements ItemListener
Class
.
forName
(
"org.postgresql.Driver"
);
// Connect to database
System
.
out
.
println
(
"Connecting to Database URL = "
+
url
);
db
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
// Create a statement
stat
=
db
.
createStatement
();
// Set the connection to use transactions
db
.
setAutoCommit
(
false
);
// Also, get the LargeObjectManager for this connection
lom
=
((
org
.
postgresql
.
Connection
)
db
).
getLargeObjectAPI
();
...
...
@@ -210,7 +206,7 @@ public class ImageViewer implements ItemListener
public
void
init
()
{
try
{
db
.
setAutoCommit
(
true
);
//
db.setAutoCommit(true);
stat
.
executeUpdate
(
"create table images (imgname name,imgoid oid)"
);
label
.
setText
(
"Initialised database"
);
db
.
commit
();
...
...
@@ -219,11 +215,11 @@ public class ImageViewer implements ItemListener
}
// This must run outside the previous try{} catch{} segment
try
{
db
.
setAutoCommit
(
true
);
}
catch
(
SQLException
ex
)
{
label
.
setText
(
ex
.
toString
());
}
//
try {
//
db.setAutoCommit(true);
//
} catch(SQLException ex) {
//
label.setText(ex.toString());
//
}
}
/**
...
...
@@ -283,37 +279,29 @@ public class ImageViewer implements ItemListener
// fetch the large object manager
LargeObjectManager
lom
=
((
org
.
postgresql
.
Connection
)
db
).
getLargeObjectAPI
();
System
.
out
.
println
(
"Importing file"
);
db
.
setAutoCommit
(
false
);
// A temporary buffer - this can be as large as you like
byte
buf
[]
=
new
byte
[
2048
];
// Open the file
System
.
out
.
println
(
"Opening file "
+
dir
+
"/"
+
name
);
FileInputStream
fis
=
new
FileInputStream
(
new
File
(
dir
,
name
));
// Gain access to large objects
System
.
out
.
println
(
"Gaining LOAPI"
);
// Now create the large object
System
.
out
.
println
(
"creating blob"
);
int
oid
=
lom
.
create
();
System
.
out
.
println
(
"Opening "
+
oid
);
LargeObject
blob
=
lom
.
open
(
oid
);
// Now copy the file into the object.
//
// Note: we dont use write(buf), as the last block is rarely the same
// size as our buffer, so we have to use the amount read.
System
.
out
.
println
(
"Importing file"
);
int
s
,
t
=
0
;
while
((
s
=
fis
.
read
(
buf
,
0
,
buf
.
length
))>
0
)
{
System
.
out
.
println
(
"Block s="
+
s
+
" t="
+
t
);
t
+=
s
;
t
+=
s
;
blob
.
write
(
buf
,
0
,
s
);
}
// Close the object
System
.
out
.
println
(
"Closing blob"
);
blob
.
close
();
// Now store the entry into the table
...
...
@@ -323,6 +311,7 @@ public class ImageViewer implements ItemListener
stat
=
db
.
createStatement
();
stat
.
executeUpdate
(
"insert into images values ('"
+
name
+
"',"
+
oid
+
")"
);
db
.
commit
();
db
.
setAutoCommit
(
false
);
// Finally refresh the names list, and display the current image
ImageViewer
.
this
.
refreshList
();
...
...
@@ -370,26 +359,28 @@ public class ImageViewer implements ItemListener
public
void
removeImage
()
{
try
{
//
// Delete any large objects for the current name
//
// Note: We don't need to worry about being in a transaction
// here, because we are not opening any blobs, only deleting
// them
//
ResultSet
rs
=
stat
.
executeQuery
(
"select imgoid from images where imgname='"
+
currentImage
+
"'"
);
if
(
rs
!=
null
)
{
// Even though there should only be one image, we still have to
// cycle through the ResultSet
while
(
rs
.
next
())
{
System
.
out
.
println
(
"Got oid "
+
rs
.
getInt
(
1
));
lom
.
delete
(
rs
.
getInt
(
1
));
System
.
out
.
println
(
"Import complete"
);
}
}
rs
.
close
();
// Finally delete any entries for that name
stat
.
executeUpdate
(
"delete from images where imgname='"
+
currentImage
+
"'"
);
db
.
commit
();
label
.
setText
(
currentImage
+
" deleted"
);
currentImage
=
null
;
db
.
commit
();
refreshList
();
}
catch
(
SQLException
ex
)
{
label
.
setText
(
ex
.
toString
());
...
...
@@ -404,21 +395,30 @@ public class ImageViewer implements ItemListener
public
void
displayImage
(
String
name
)
{
try
{
System
.
out
.
println
(
"Selecting oid for "
+
name
);
//
// Now as we are opening and reading a large object we must
// turn on Transactions. This includes the ResultSet.getBytes()
// method when it's used on a field of type oid!
//
db
.
setAutoCommit
(
false
);
ResultSet
rs
=
stat
.
executeQuery
(
"select imgoid from images where imgname='"
+
name
+
"'"
);
if
(
rs
!=
null
)
{
// Even though there should only be one image, we still have to
// cycle through the ResultSet
while
(
rs
.
next
())
{
System
.
out
.
println
(
"Got oid "
+
rs
.
getInt
(
1
));
canvas
.
setImage
(
canvas
.
getToolkit
().
createImage
(
rs
.
getBytes
(
1
)));
System
.
out
.
println
(
"Import complete"
);
label
.
setText
(
currentImage
=
name
);
}
}
rs
.
close
();
}
catch
(
SQLException
ex
)
{
label
.
setText
(
ex
.
toString
());
}
finally
{
try
{
db
.
setAutoCommit
(
true
);
}
catch
(
SQLException
ex2
)
{
}
}
}
...
...
@@ -454,6 +454,7 @@ public class ImageViewer implements ItemListener
frame
.
setLayout
(
new
BorderLayout
());
ImageViewer
viewer
=
new
ImageViewer
(
frame
,
args
[
0
],
args
[
1
],
args
[
2
]);
frame
.
pack
();
frame
.
setLocation
(
0
,
50
);
frame
.
setVisible
(
true
);
}
catch
(
Exception
ex
)
{
System
.
err
.
println
(
"Exception caught.\n"
+
ex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录