Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ee5229

Browse files
committed
From: Peter T Mount <peter@retep.org.uk>This implements some of the JDBC2 methods, fixes a bug introduced into theJDBC1 portion of the driver, and introduces a new example, showing how touse the CORBA ORB thats in Java2 with JDBC.The Tar file contains the new files, the diff the changes to the others.CHANGELOG is separate as I forgot to make a .orig ;-)
1 parent1401f63 commit2ee5229

File tree

12 files changed

+879
-10
lines changed

12 files changed

+879
-10
lines changed

‎src/interfaces/jdbc/CHANGELOG

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Mon Jan 25 19:45:00 GMT 1999
2+
- created subfolders example/corba and example/corba/idl to hold the
3+
new example showing how to hook CORBA and PostgreSQL via JDBC
4+
- implemented some JDBC2 methods curtesy of Joachim.Gabler@t-online.de
5+
6+
Sat Jan 23 10:30:00 GMT 1999
7+
- Changed imports in postgresql.jdbc1.ResultSetMetaData as for some
8+
reason it didn't want to compile under jdk1.1.6
9+
110
Tue Dec 29 15:45:00 GMT 1998
211
- Refreshed the README (which was way out of date)
312

‎src/interfaces/jdbc/Makefile

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
# Makefile for Java JDBC interface
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.11 1999/01/17 04:51:49 momjian Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.12 1999/01/25 21:22:02 scrappy Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
FIND= find
12+
IDL2JAVA= idltojava -fno-cpp -fno-tie
1213
JAR= jar
1314
JAVA= java
1415
JAVAC= javac
1516
JAVADOC= javadoc
1617
RM= rm -f
18+
TOUCH= touch
1719

1820
# This defines how to compile a java class
1921
.java.class:
@@ -44,6 +46,9 @@ all:makeVersion.class
4446
@echo ------------------------------------------------------------
4547
@echo To build the examples, type:
4648
@echo" make examples"
49+
@echo
50+
@echo"To build the CORBA example (requires Java2):"
51+
@echo" make corba"
4752
@echo ------------------------------------------------------------
4853
@echo
4954

@@ -142,7 +147,8 @@ clean:
142147
$(FIND). -name"*~" -exec$(RM) {}\;
143148
$(FIND). -name"*.class" -exec$(RM) {}\;
144149
$(FIND). -name"*.html" -exec$(RM) {}\;
145-
$(RM) postgresql.jar
150+
-$(RM) -rf stock example/corba/stock.built
151+
-$(RM) postgresql.jar
146152
-$(RM) -rf Package-postgresql*output
147153

148154
#######################################################################
@@ -219,7 +225,37 @@ example/blobtest.class:example/blobtest.java
219225
example/datestyle.class:example/datestyle.java
220226
example/psql.class:example/psql.java
221227
example/ImageViewer.class:example/ImageViewer.java
222-
#example/Objects.class:example/Objects.java
223228
example/threadsafe.class:example/threadsafe.java
224229
example/metadata.class:example/metadata.java
230+
231+
#######################################################################
232+
#
233+
# CORBAThis extensive example shows how to integrate PostgreSQL
234+
#JDBC & CORBA.
235+
236+
CORBASRC =$(wildcard example/corba/*.java)
237+
CORBAOBJ =$(subst .java,.class,$(CORBASRC))
238+
239+
corba: jdbc2 example/corba/stock.built$(CORBAOBJ)
240+
@echo -------------------------------------------------------
241+
@echo The corba example has been built. Before running, you
242+
@echo will need toread the example/corba/readme file on how
243+
@echo to run the example.
244+
@echo
245+
246+
#
247+
# This compiles our idl file and the stubs
248+
#
249+
# Note: The idl file is in example/corba, but it builds a directory under
250+
# the current one. For safety, we delete that directory before running
251+
# idltojava
252+
#
253+
example/corba/stock.built: example/corba/stock.idl
254+
-rm -rf stock
255+
$(IDL2JAVA)$<
256+
$(JAVAC) stock/*.java
257+
$(TOUCH)$@
258+
259+
# tip: we cant use $(wildcard stock/*.java) in the above rule as a race
260+
# condition occurs, where javac is passed no arguments
225261
#######################################################################
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
packageexample.corba;
2+
3+
importjava.io.*;
4+
importjava.sql.*;
5+
importorg.omg.CosNaming.*;
6+
7+
/**
8+
* This class is the frontend to our mini CORBA application.
9+
*
10+
* It has no GUI, just a text frontend to keep it simple.
11+
*
12+
* $Id: StockClient.java,v 1.1 1999/01/25 21:22:03 scrappy Exp $
13+
*/
14+
publicclassStockClient
15+
{
16+
org.omg.CosNaming.NamingContextnameService;
17+
18+
stock.StockDispenserdispenser;
19+
stock.StockItemitem;
20+
21+
BufferedReaderin;
22+
23+
publicStockClient(String[]args) {
24+
try {
25+
// We need this for our IO
26+
in =newBufferedReader(newInputStreamReader(System.in));
27+
28+
// Initialize the orb
29+
org.omg.CORBA.ORBorb =org.omg.CORBA.ORB.init(args,null);
30+
31+
// Get a reference to the Naming Service
32+
org.omg.CORBA.ObjectnameServiceObj =orb.resolve_initial_references("NameService");
33+
if(nameServiceObj==null) {
34+
System.err.println("nameServiceObj == null");
35+
return;
36+
}
37+
38+
nameService =org.omg.CosNaming.NamingContextHelper.narrow(nameServiceObj);
39+
if(nameService==null) {
40+
System.err.println("nameService == null");
41+
return;
42+
}
43+
44+
// Resolve the dispenser
45+
NameComponent[]dispName = {
46+
newNameComponent("StockDispenser","Stock")
47+
};
48+
dispenser =stock.StockDispenserHelper.narrow(nameService.resolve(dispName));
49+
if(dispenser==null) {
50+
System.err.println("dispenser == null");
51+
return;
52+
}
53+
54+
// Now run the front end.
55+
run();
56+
}catch(Exceptione) {
57+
System.out.println(e.toString());
58+
e.printStackTrace();
59+
System.exit(1);
60+
}
61+
}
62+
63+
publicstaticvoidmain(String[]args) {
64+
newStockClient(args);
65+
}
66+
67+
publicvoidrun() {
68+
// First reserve a StockItem
69+
try {
70+
item =dispenser.reserveItem();
71+
}catch(Exceptione) {
72+
System.out.println(e.toString());
73+
e.printStackTrace();
74+
System.exit(1);
75+
}
76+
77+
mainMenu();
78+
79+
// finally free the StockItem
80+
try {
81+
dispenser.releaseItem(item);
82+
}catch(Exceptione) {
83+
System.out.println(e.toString());
84+
e.printStackTrace();
85+
System.exit(1);
86+
}
87+
}
88+
89+
privatevoidmainMenu() {
90+
booleanrun=true;
91+
while(run) {
92+
System.out.println("\nCORBA Stock System\n");
93+
System.out.println(" 1 Display stock item");
94+
System.out.println(" 2 Remove item from stock");
95+
System.out.println(" 3 Put item into stock");
96+
System.out.println(" 4 Order item");
97+
System.out.println(" 5 Display all items");
98+
System.out.println(" 0 Exit");
99+
inti =getMenu("Main",5);
100+
switch(i)
101+
{
102+
case0:
103+
run=false;
104+
break;
105+
106+
case1:
107+
displayItem();
108+
break;
109+
110+
case2:
111+
bookOut();
112+
break;
113+
114+
case3:
115+
bookIn();
116+
break;
117+
118+
case4:
119+
order(0);
120+
break;
121+
122+
case5:
123+
displayAll();
124+
break;
125+
}
126+
}
127+
}
128+
129+
privatevoiddisplayItem() {
130+
try {
131+
intid =getMenu("\nStockID to display",item.getLastID());
132+
if(id>0) {
133+
item.fetchItem(id);
134+
System.out.println("========================================");
135+
136+
Stringstatus ="";
137+
if(!item.isItemValid())
138+
status=" ** Superceded **";
139+
140+
intav =item.getAvailable();
141+
142+
System.out.println(" Stock ID: "+id+status+
143+
"\nItems Available: "+av+
144+
"\nItems on order: "+item.getOrdered()+
145+
"\n Description: "+item.getDescription());
146+
System.out.println("========================================");
147+
148+
if(av>0)
149+
if(yn("Take this item out of stock?")) {
150+
intrem=1;
151+
if(av>1)
152+
rem=getMenu("How many?",av);
153+
if(rem>0)
154+
item.removeStock(rem);
155+
}
156+
157+
}
158+
}catch(Exceptione) {
159+
System.out.println(e.toString());
160+
e.printStackTrace();
161+
}
162+
}
163+
164+
privatevoidbookOut() {
165+
try {
166+
intid =getMenu("\nStockID to take out",item.getLastID());
167+
if(id>0) {
168+
item.fetchItem(id);
169+
intav =item.getAvailable();
170+
if(av>0)
171+
if(yn("Take this item out of stock?")) {
172+
intrem=1;
173+
if(av>1)
174+
rem=getMenu("How many?",av);
175+
if(rem>0)
176+
item.removeStock(rem);
177+
}
178+
else {
179+
System.out.println("This item is not in stock.");
180+
intorder =item.getOrdered();
181+
if(order>0)
182+
System.out.println("There are "+item.getOrdered()+" items on order.");
183+
else {
184+
if(item.isItemValid()) {
185+
System.out.println("You will need to order some more "+item.getDescription());
186+
order(id);
187+
}else
188+
System.out.println("This item is now obsolete");
189+
}
190+
}
191+
}else
192+
System.out.println(item.getDescription()+"\nThis item is out of stock");
193+
}catch(Exceptione) {
194+
System.out.println(e.toString());
195+
e.printStackTrace();
196+
}
197+
}
198+
199+
// book an item into stock
200+
privatevoidbookIn() {
201+
try {
202+
intid =getMenu("\nStockID to book in",item.getLastID());
203+
item.fetchItem(id);
204+
System.out.println(item.getDescription());
205+
206+
if(item.getOrdered()>0) {
207+
intam =getMenu("How many do you want to book in",item.getOrdered());
208+
if(am>0)
209+
item.addNewStock(am);
210+
}else
211+
System.out.println("You don't have any of this item on ordered");
212+
213+
}catch(Exceptione) {
214+
System.out.println(e.toString());
215+
e.printStackTrace();
216+
}
217+
}
218+
219+
// Order an item
220+
privatevoidorder(intid) {
221+
try {
222+
if(id==0)
223+
id =getMenu("\nStockID to order",item.getLastID());
224+
item.fetchItem(id);
225+
System.out.println(item.getDescription());
226+
intam =getMenu("How many do you want to order",999);
227+
if(am>0)
228+
item.orderStock(am);
229+
}catch(Exceptione) {
230+
System.out.println(e.toString());
231+
e.printStackTrace();
232+
}
233+
}
234+
235+
privatevoiddisplayAll() {
236+
try {
237+
booleancont=true;
238+
intnr=item.getLastID();
239+
Stringheader ="\nId\tAvail\tOrdered\tDescription";
240+
System.out.println(header);
241+
for(inti=1;i<=nr &&cont;i++) {
242+
item.fetchItem(i);
243+
System.out.println(""+i+"\t"+item.getAvailable()+"\t"+item.getOrdered()+"\t"+item.getDescription());
244+
if((i%20)==0) {
245+
if((cont=yn("Continue?")))
246+
System.out.println(header);
247+
}
248+
}
249+
}catch(Exceptione) {
250+
System.out.println(e.toString());
251+
e.printStackTrace();
252+
}
253+
}
254+
255+
privateintgetMenu(Stringtitle,intmax) {
256+
intv=-1;
257+
while(v<0 ||v>max) {
258+
System.out.print(title);
259+
System.out.print(" [0-"+max+"]: ");
260+
System.out.flush();
261+
try {
262+
v =Integer.parseInt(in.readLine());
263+
}catch(Exceptionnfe) {
264+
v=-1;
265+
}
266+
}
267+
returnv;
268+
}
269+
270+
privatebooleanyn(Stringtitle) {
271+
try {
272+
while(true) {
273+
System.out.print(title);
274+
System.out.flush();
275+
Strings =in.readLine();
276+
if(s.startsWith("y") ||s.startsWith("Y"))
277+
returntrue;
278+
if(s.startsWith("n") ||s.startsWith("N"))
279+
returnfalse;
280+
}
281+
}catch(Exceptionnfe) {
282+
System.out.println(nfe.toString());
283+
nfe.printStackTrace();
284+
System.exit(1);
285+
}
286+
returnfalse;
287+
}
288+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp