`
liujunsong
  • 浏览: 77372 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

webdw.TableServlet

阅读更多

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   TableServlet.java

package com.webdw;

import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;

import javax.servlet.*;
import javax.servlet.http.*;


public class TableServlet extends HttpServlet {

 /**
  *
  */
 private static final long serialVersionUID = 1L;

 public TableServlet() {
  s_ok = "OK";
  s_error = "ERROR";
  s_oper_query = "1";
  s_oper_exec = "2";
  s_oper_tablelist = "3";
  s_oper_columnlist = "4";
  s_oper_beginTrans = "begintrans";
  s_oper_addcommand = "addcommand";
  s_oper_commit = "commit";
  s_oper_rollback = "rollback";
  s_oper_getdwdefine = "getdwdefine";
  ClassInfo = "";
 }

 public void init(ServletConfig config) throws ServletException {
  System.out.println("--------------com.webdw.TableServlet init--------------------");
 }

 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("GBK");
  int beginpos = 0;
  int readnum = 100;
  System.out.println("enter service TableServlet.Welcome.");
  String operType = request.getParameter("opertype");
  String command = request.getParameter("command");
  String param = request.getParameter("param");
  String strans = request.getParameter("transid");
  System.out.println("command=" + command);
  if (request.getParameter("beginpos") != null && request.getParameter("beginpos").trim().length() > 0)
   beginpos = Integer.parseInt(request.getParameter("beginpos"));
  if (request.getParameter("readnum") != null && request.getParameter("readnum").trim().length() > 0)
   readnum = Integer.parseInt(request.getParameter("readnum"));
  int col = 0;
  if (operType == null)
   operType = "";
  if (command == null)
   command = "";
  if (param == null)
   param = "";
  // response.setContentType("text/html;charset=GBK");
  response.setContentType("text/html;charset=utf-8");
  ServletOutputStream out = null;
  // response.getOutputStream();
  Connection conn = null;
  Statement stat = null;
  ResultSet rs = null;
  if (operType.equals("")) {
   out = response.getOutputStream();
   out.print(s_ok);
   return;
  }
  try {
   conn = getConnection();
   conn.setAutoCommit(false);
   stat = conn.createStatement();
  } catch (Exception e) {
   e.printStackTrace();
   out = response.getOutputStream();
   out.print("OK");
   return;
  }

  if (operType.equals(s_oper_tablelist))
   command = "select TNAME,TABTYPE from tab";
  if (operType.equals(s_oper_columnlist))
   command = "Select CNAME from col where TNAME='" + command + "'";
  if (operType.equals(s_oper_query) || operType.equals(s_oper_tablelist) || operType.equals(s_oper_columnlist))
   try {
    if (out == null) {
     out = response.getOutputStream();
    }
    doExecuteSelect(stat, rs, out, command, col, beginpos, readnum);
    conn.rollback();
   } catch (Exception e) {
    try {
     conn.rollback();
    } catch (Exception e1) {
     e1.printStackTrace();
    }
    e.printStackTrace();
    out.println(e.toString());
   }
  if (operType.equals(s_oper_exec))
   try {
    doExecuteUpdate(command, stat, conn);
   } catch (Exception e) {
    try {
     conn.rollback();
    } catch (Exception e1) {
     e1.printStackTrace();
    }
    e.printStackTrace();
    out.println(e.toString());
   }
  if (operType.equals(s_oper_beginTrans))
   try {
    if(out==null) {
     out = response.getOutputStream();
    }
    doBeginTransaction(out);
   } catch (Exception e) {
    e.printStackTrace();
   }
  if (operType.equals(s_oper_addcommand))
   doAddCommand(strans, command);
  if (operType.equals(s_oper_commit))
   try {
    doCommit(strans, conn, stat);
   } catch (Exception e) {
    try {
     e.printStackTrace();
     Integer transId = new Integer(strans);
     TransSql sql = (TransSql) transHash.get(transId);
     if (sql != null) {
      sql.result = "commit failed";
      sql.commitDt = (new Date()).toString();
     }
     conn.rollback();
     out.println(e.toString());
    } catch (Exception e1) {
     e1.printStackTrace();
    }
   }
  if (operType.equals(s_oper_rollback))
   doRollback(strans);
  if (operType.equals(s_oper_getdwdefine))
   try {
    doGetDWFile(command, response);
   } catch (Exception e) {
    e.printStackTrace();
   }
//  if (operType.equals(s_oper_getvbfile))
//   try {
//    doGetVBFile(command, out);
//   } catch (Exception e) {
//    e.printStackTrace();
//   }
  if(out==null) {
   out = response.getOutputStream();
  }
  out.print(s_ok);
  try {
   if (rs != null)
    rs.close();
   if (stat != null)
    stat.close();
   if (conn != null)
    conn.close();
  } catch (Exception e) {
   e.printStackTrace();
   System.out.println("Database connection close failed.");
  } finally {
   try {
    conn.close();
   } catch (Exception e2) {
    e2.printStackTrace();
   }
  }
  return;
 }

 private Connection getConnection() throws Exception {
  String configfile = "com/liu/database.properties";
  String url = "";
  String driver = "";
  String userid = "";
  String passwd = "";
  ClassLoader loader = (new TableServlet()).getClass().getClassLoader();
  java.io.InputStream stream = loader.getResourceAsStream(configfile);
  Properties prop = new Properties();
  prop.load(stream);
  url = prop.getProperty("url");
  driver = prop.getProperty("driver");
  userid = prop.getProperty("userid");
  passwd = prop.getProperty("passwd");
  Class.forName(driver);
  Connection conn = DriverManager.getConnection(url, userid, passwd);
  return conn;
 }

 private void doExecuteSelect(Statement stat, ResultSet rs, ServletOutputStream out, String command, int col,
   int beginpos, int readnum) throws Exception {
  System.out.println("Sql = " + command);
  rs = stat.executeQuery(command);
  ResultSetMetaData meta = rs.getMetaData();
  String sline = "";
  for (col = 1; col <= meta.getColumnCount(); col++)
   if (col < meta.getColumnCount())
    sline = sline + meta.getColumnName(col) + "\t";
   else
    sline = sline + meta.getColumnName(col);

  out.println(sline);
  System.out.println("colname=" + sline);
  for (; beginpos > 0; beginpos--)
   if (!rs.next())
    break;

  for (; rs.next() && beginpos == 0 && readnum > 0; out.println(sline)) {
   sline = "";
   for (col = 1; col <= meta.getColumnCount(); col++)
    if (col < meta.getColumnCount())
     sline = sline + rs.getString(col) + "\t";
    else
     sline = sline + rs.getString(col);

   readnum--;
  }

 }

 private void doExecuteUpdate(String command, Statement stat, Connection conn) throws Exception {
  System.out.println("Sql = " + command);
  if (command != null || command.trim().length() >= 1) {
   String sqls[] = command.split("----------");
   for (int i = 0; i < sqls.length; i++) {
    System.out.println("sqls[i]:" + sqls[i]);
    if (sqls[i] == null || sqls[i].trim().length() == 0)
     break;
    stat.executeUpdate(sqls[i]);
   }

   conn.commit();
  }
 }

 private void doBeginTransaction(ServletOutputStream out) throws Exception {
  System.out.println("enter begintrans");
  synchronized (transId) {
   int id = transId.intValue();
   if (++id >= 1000)
    id = 0;
   transId = new Integer(id);
  }
  TransSql sql = (TransSql) transHash.get(transId);
  if (sql != null)
   transHash.remove(transId);
  sql = new TransSql();
  sql.transId = transId.intValue();
  sql.beginDT = (new Date()).toString();
  transHash.put(transId, sql);
  System.out.println(transId.toString());
  out.println(transId.toString());
 }

 private void doAddCommand(String stransId, String command) {
  Integer transId = new Integer(stransId);
  TransSql sql = (TransSql) transHash.get(transId);
  if (sql != null && command != null && !command.trim().equals(""))
   if (sql.transSQL.equals(""))
    sql.transSQL = command;
   else
    sql.transSQL = sql.transSQL + "\r\n" + command;
 }

 private void doCommit(String stransId, Connection conn, Statement stat) throws Exception {
  Integer transId = new Integer(stransId);
  TransSql sql = (TransSql) transHash.get(transId);
  if (sql != null && sql.result.trim().length() <= 0) {
   sql.result = "commit begin";
   String sqls[] = sql.transSQL.split("\r\n");
   for (int i = 0; i < sqls.length; i++) {
    System.out.println("sqls[i]:" + sqls[i]);
    if (sqls[i] == null || sqls[i].trim().length() == 0)
     break;
    stat.executeUpdate(sqls[i]);
   }

   conn.commit();
   sql.commitDt = (new Date()).toString();
   sql.result = "commit finish";
  }
 }

 private void doRollback(String stransId) {
  Integer transId = new Integer(stransId);
  TransSql sql = (TransSql) transHash.get(transId);
  if (sql != null && sql.result.trim().length() <= 0) {
   sql.result = "rollback";
   sql.commitDt = (new Date()).toString();
  }
 }

 //read datawindow defile file from filesystem
 private void doGetDWFile(String command, HttpServletResponse response ) throws Exception {
  String filepath = "C://webdwfile//dwfile//";
  String filename = "";
  if (command.indexOf(".") > 0)
   filename = filepath + command;
  else
   filename = filepath + command + ".srd";
  System.out.println("Want file:" + filename);
  File dwfile = new File(filename);
  if (dwfile.exists()) {
   FileReader fstream = new FileReader(filename);
   BufferedReader in = new BufferedReader(fstream);
   String sout="";
   for (String record = ""; (record = in.readLine()) != null;) {
    sout += record;
   }
    response.getWriter().write(sout);
    response.getWriter().close();
    //out.println(record);

   in.close();
  }
 }

 private void doGetVBFile(String command, ServletOutputStream out) throws Exception {
  String filepath = "C://webdwfile//VBfile//";
  String filename = "";
  filename = filepath + command;
  System.out.println("Want VB file:" + filename);
  File vbfile = new File(filename);
  if (vbfile.exists()) {
   FileReader fstream = new FileReader(filename);
   BufferedReader in = new BufferedReader(fstream);
   for (String record = ""; (record = in.readLine()) != null;)
    out.println(record);

   in.close();
  }
 }

 public static Hashtable transHash = new Hashtable();
 private String s_ok;
 private String s_error;
 private String s_oper_query;
 private String s_oper_exec;
 private String s_oper_tablelist;
 private String s_oper_columnlist;
 private String s_oper_beginTrans;
 private String s_oper_addcommand;
 private String s_oper_commit;
 private String s_oper_rollback;
 private String s_oper_getdwdefine;
 private static Integer transId = new Integer(0);
 private String ClassInfo;

}

分享到:
评论

相关推荐

    webdw.rar_HTML 网页_html_webdw_网页_网页制作html

    在提供的"webdw.rar"压缩包中,包含了一个名为"webdw"的文件,这可能是用户使用WebDW软件创建的一个HTML网页项目。这个项目可能包含了HTML源代码、CSS样式表、JavaScript脚本,甚至可能有图片和其他媒体资源,所有...

    WebDW.zip_PowerBuilder_powerbuilder web_zip

    【标题】"WebDW.zip_PowerBuilder_powerbuilder web_zip" 提供的是关于 PowerBuilder 开发的 Web DataWindow 组件的相关资源。PowerBuilder 是一种流行的、基于事件驱动的编程环境,主要用于构建企业级的数据库应用...

    WebDW产品介绍202001211

    WebDW是一款旨在提升开发效率和简化后台接口结构的软件产品,尤其针对B/S架构的开发痛点进行了优化。其设计理念源于对传统PowerBuilder中DataWindow技术的现代化改造,以适应多种开发语言和运行环境。 在需求分析...

    webdw on vb version

    【标题】:“WebDW on VB 版本” 【描述】:虽然描述中给出的信息非常有限,但根据提供的博文链接(已不可用),我们可以推测这是一个关于使用Visual Basic(VB)开发Web应用程序的工具或教程。WebDW可能是Web设计...

    WebDW0.2版本隆重发布,敬请下载试用

    WebDW0.2版本的发布标志着一个新的里程碑在Web开发工具领域。这个版本的推出,旨在为开发者提供更高效、易用且功能丰富的源码编辑和管理工具。让我们深入了解一下WebDW0.2版本的主要特点和改进。 首先,作为一款...

    WebDW2代码说明1

    WebDW2.0 VB Demo 程序是一个用于展示如何在VB环境中与WebDW2.0后台服务(基于SpringBoot)交互的实例。这个程序主要包含三个关键步骤:调用、返回和界面绘制。 首先,VB客户端通过发送HTTP请求到后台服务器来启动...

    WebDW-API定义202001311

    【WebDW-API定义202001311】文档详细阐述了WebDW后台服务器提供的API接口,这些接口主要用于前端与后台数据交互,确保不同语言的前端工具能够有效地访问和调用数据窗口对象。以下是关于这些API的详细说明: 1. **...

    WebDW2.0的前端Web项目,介绍WebDW项目的相关资料,演示Demo功能。前端项目(毕设&课设&实训&大作业&竞赛&项目

    项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助...

    webdw源代码

    NULL 博文链接:https://liujunsong.iteye.com/blog/1338944

    WDW 2.0汉化版

    一个很棒的BBS脚本,结合了DHTML、JavaScrip、CSS技术,界面与MS IE浑然一体。由本人汉化。汉化过程中修正了几处错误,几个连接图形文件名错误,更重要的是,原来的程序没有区分cgi和nocgi目录,导致在许多系统上...

    提取Powerbuilder 12里自带的Code Samples,共12个

    总共12个Projects 包含: Advanced GUI Benchmark dotNET CAS DWGradientTransparency DWRichTextEditStyle Example App FeedReader Mobilink Treeview DataWindow and DatePicker Web Reports ...WebDW

Global site tag (gtag.js) - Google Analytics