aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/example/corba/StockDispenserImpl.java
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1999-01-25 21:22:06 +0000
committerMarc G. Fournier <scrappy@hub.org>1999-01-25 21:22:06 +0000
commit2ee522954d0d634d520e6f10454a8c63ef004a00 (patch)
tree2b1b3b0756fb3ad81d689008dd5465cbd1c56389 /src/interfaces/jdbc/example/corba/StockDispenserImpl.java
parent1401f63dd15fbc073775fb0279c3b7153ef95f66 (diff)
downloadpostgresql-2ee522954d0d634d520e6f10454a8c63ef004a00.tar.gz
postgresql-2ee522954d0d634d520e6f10454a8c63ef004a00.zip
From: Peter T Mount <peter@retep.org.uk>
This implements some of the JDBC2 methods, fixes a bug introduced into the JDBC1 portion of the driver, and introduces a new example, showing how to use 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 ;-)
Diffstat (limited to 'src/interfaces/jdbc/example/corba/StockDispenserImpl.java')
-rw-r--r--src/interfaces/jdbc/example/corba/StockDispenserImpl.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/example/corba/StockDispenserImpl.java b/src/interfaces/jdbc/example/corba/StockDispenserImpl.java
new file mode 100644
index 00000000000..2d961a6dc7b
--- /dev/null
+++ b/src/interfaces/jdbc/example/corba/StockDispenserImpl.java
@@ -0,0 +1,83 @@
+package example.corba;
+
+import org.omg.CosNaming.*;
+
+/**
+ * This class implements the server side of the example.
+ *
+ * $Id: StockDispenserImpl.java,v 1.1 1999/01/25 21:22:03 scrappy Exp $
+ */
+public class StockDispenserImpl extends stock._StockDispenserImplBase
+{
+ private int maxObjects = 10;
+ private int numObjects = 0;
+ private StockItemStatus[] stock = new StockItemStatus[maxObjects];
+
+ public StockDispenserImpl(String[] args,String name,int num)
+ {
+ super();
+
+ try {
+ // get reference to orb
+ org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
+
+ // prestart num objects
+ if(num>=maxObjects)
+ num=maxObjects;
+ numObjects = num;
+ for(int i=0;i<numObjects;i++) {
+ stock[i] = new StockItemStatus();
+ stock[i].ref = new StockItemImpl(args,"StockItem"+(i+1));
+ orb.connect(stock[i].ref);
+ }
+ } catch(org.omg.CORBA.SystemException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * This method, defined in stock.idl, reserves a slot in the dispenser
+ */
+ public stock.StockItem reserveItem() throws stock.StockException
+ {
+ for(int i=0;i<numObjects;i++) {
+ if(!stock[i].inUse) {
+ stock[i].inUse = true;
+ System.out.println("Reserving slot "+i);
+ return stock[i].ref;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * This releases a slot from the dispenser
+ */
+ public void releaseItem(stock.StockItem item) throws stock.StockException
+ {
+ for(int i=0;i<numObjects;i++) {
+ if(stock[i].ref.getInstanceName().equals(item.getInstanceName())) {
+ stock[i].inUse = false;
+ System.out.println("Releasing slot "+i);
+ return;
+ }
+ }
+ System.out.println("Reserved object not a member of this dispenser");
+ return;
+ }
+
+ /**
+ * This class defines a slot in the dispenser
+ */
+ class StockItemStatus
+ {
+ StockItemImpl ref;
+ boolean inUse;
+
+ StockItemStatus() {
+ ref = null;
+ inUse = false;
+ }
+ }
+
+}