📄 remoteindyserver.java
字号:
/*
* @(#)RemoteIndyServer
*
* Copyright (c) 1998 Karl Moss. All Rights Reserved.
*
* You may study, use, modify, and distribute this software for any
* purpose provided that this copyright notice appears in all copies.
*
* This software is provided WITHOUT WARRANTY either expressed or
* implied.
*
* @author Karl Moss
* @version 1.0
* @date 17Apr98
*
*/
package javaservlets.tunnel;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javaservlets.tunnel.server.*;
import javaservlets.db.*;
import javaservlets.jdbc.*;
import javaservlets.timer.*;
import java.util.List;
import java.util.ArrayList;
/**
* <p>This class implements the server for tunneling
* remote Indy method calls
*/
public class RemoteIndyServer
extends TunnelServer
{ List array=new ArrayList();
/**
* <p>Creates a new instance of the server object.
*
* @return Instance of the server object
*/
public Object _getNewInstance()
throws ServletException
{
return new Indy();
}
/**
* <p>Invokes the method for the ordinal given. If the method
* throws an exception it will be sent to the client.
*
* @param Object Server object
* @param ordinal Method ordinal
* @param in Input stream to read additional parameters
* @param out Output stream to write return values
*/
public void _invokeMethod(Object serverObject, int ordinal,
DataInput in, DataOutput out)
throws Exception
{
ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
Object o = context.getAttribute(ConnectionServlet_21.KEY);
if (o == null) {
throw new ServletException("ConnectionServlet not started");
}
ConnectionServlet_21 conServlet = (ConnectionServlet_21) o;
// Cast the server object
Indy indy = (Indy) serverObject;
// Cast the input/output streams
ObjectInputStream objectIn = (ObjectInputStream) in;
ObjectOutputStream objectOut = (ObjectOutputStream) out;
// Evaluate the ordinal
switch (ordinal) {
case 0: // connect
System.out.println("case 0");
boolean b0 = indy.connect();
objectOut.writeObject(new Boolean(b0));
break;
case 1: // close
System.out.println("case 1");
indy.close();
break;
case 2: // query
System.out.println("case 2");
//////////////////////////////////////////////////
// Integer i2 = (Integer) objectIn.readObject();
// There are problems!!!!
IndyRecord record[] = indy.query();
System.out.println("at RemoteIndyServer:"+record[0].taskID);
objectOut.writeObject(record);
break;
case 3: // delete
System.out.println("case 3");
String s = (String) objectIn.readObject();
System.out.println("I want to delete: "+s);
indy.delete(s);
break;
case 4: // insert
System.out.println("case 4");
IndyRecord records = (IndyRecord)objectIn.readObject();
System.out.println("I want to insert: "+records.taskID);
indy.insert(records);
break;
case 5: // update
System.out.println("case 5");
IndyRecord re = (IndyRecord)objectIn.readObject();
System.out.println("I want to update: "+re.taskID);
indy.update(re);
break;
////////////////////////////////////////////////////////////
// Get the ConnectionServlet that holds the
// connection pool
case 6://schedule
boolean isshedu=true;
List list=new ArrayList();
String[] output;
Connection con1=null;//联结对象
Statement stmt1=null;//语句对象
ResultSet rs=null; //纪录集对象
try{//连接数据库
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//con1=DriverManager.getConnection("jdbc:odbc:MyAccessDataSource1");
//stmt1=con1.createStatement();
con1 = conServlet.getConnection();
stmt1=con1.createStatement();
try
{
array.clear();
}
catch(UnsupportedOperationException exc)
{ System.out.println("can't clear the list!!!");
}
record[] res=find();
insert(res);
while(!array.isEmpty())
{ String id=((record)array.get(0)).taskID;
List nextid=((record)array.get(0)).nextID;
list.add((record)array.get(0));
delete(nextid);
array.remove(0);
record[] res1=find();
if(res.length!=0)
insert(res1);
}
output=new String[list.size()];
for(int i=0;i<list.size();i++)
{ output[i]=((record)list.get(i)).taskID;
}
//print output
System.out.println("Toop include: ");
for(int i=0;i<output.length;i++)
{ System.out.print(output[i]);
if(i!=output.length-1)
System.out.print(",");
}
String query="select taskID from toop where isnew=true";
rs=stmt1.executeQuery(query);
List loop=new ArrayList();
while(rs.next())
{ String a=rs.getString(1);
loop.add(a);
}
if(loop.size()!=0)
{ isshedu=false;
System.out.println();
System.out.print("Error, There are loop whose id: ");
for(int i=0;i<loop.size();i++)
{ System.out.print((String)loop.get(i));
if(i!=loop.size()-1)
System.out.print(",");
}
}
String update="update toop set isnew=true,newdu=0";
rs.close();
stmt1.executeUpdate(update);
}catch(Exception ex)
{ ex.printStackTrace();
}
finally {
try {
// Always close properly
if (stmt1 != null) {
stmt1.close();
}
if (con1 != null) {
// Put the connection back into the pool
// con1.close();
conServlet.close(con1);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
if(isshedu)
{
schedul(list);
}
break;
/////////////////////////////////////////////////////////////
default:
throw new Exception("Invalid ordinal: " + ordinal);
}
}
private record[] find()
{ List rec=new ArrayList();
int locate=-1;
record[] re;
Connection con=null;//联结对象
Statement stmt=null;//语句对象
ResultSet rs=null; //纪录集对象
ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
Object o = context.getAttribute(ConnectionServlet_21.KEY);
if (o == null) {
// throw new ServletException("ConnectionServlet not started");
}
ConnectionServlet_21 conServlet = (ConnectionServlet_21) o;
try{//连接数据库
con=conServlet.getConnection();
stmt=con.createStatement();
String query1="select taskID,nextID,relation,lag,indu from toop"+
" where indu=newdu and isnew=true";
rs=stmt.executeQuery(query1);
while(rs.next())
{
String a=rs.getString(1);
String b=rs.getString(2);
String relation=rs.getString(3);
int lag=rs.getInt(4);
int indu=rs.getInt(5);
boolean isinsert=false;
for(int i=0;i<rec.size();i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -