1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-21 15:54:08 +03:00
postgres/src/interfaces/jdbc/example/corba/StockDispenserImpl.java
Marc G. Fournier 2ee522954d 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 ;-)
1999-01-25 21:22:06 +00:00

84 lines
1.9 KiB
Java

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;
}
}
}