001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader;
023:
024: import java.util.*;
025: import java.sql.*;
026:
027: /**
028: *
029: * QueryUpdateSet class creates the update sql statement
030: * @author Radoslav Dutina
031: * @version 1.0
032: */
033: public class QueryUpdateSet {
034:
035: private String strQueryUpdate = null;
036: private Vector indexDummyOverwrite = new Vector();
037: // private Vector indexDummyUpdate=new Vector();
038: private Vector indexDummySetNull = new Vector();
039: private String versionName = "version";
040:
041: /**
042: * Construct the object of QueryUpdateSet class with associated parameter
043: * @param vecColumnNames is vector which contain column names
044: * @param vecColumnTypes is vector which contain column types
045: * @param vecColumnMode is vector which contain column mode
046: * @param tableName is the current table name
047: * @param oid is boolean parameter
048: */
049: public QueryUpdateSet(Vector vecColumnNames, Vector vecColumnTypes,
050: Vector vecColumnMode, String tableName, boolean oid,
051: String versionName, ConfigReader configReaderTarget)
052: throws LoaderException {
053:
054: this .versionName = versionName;
055: // this.strQueryUpdate=strQueryUpdate;
056: strQueryUpdate = "update " + tableName + " set ";
057: int counter = 0;
058: for (int j = 0; j < vecColumnNames.size(); j++) {
059: counter = j;
060: if (vecColumnMode.get(j).toString().equalsIgnoreCase(
061: "Overwrite")) {
062: indexDummyOverwrite.add(String.valueOf(counter));
063: strQueryUpdate += vecColumnNames.get(j).toString()
064: + "=";
065: try {
066: if (!configReaderTarget.isNumber(vecColumnTypes
067: .get(j).toString())) {
068: if (configReaderTarget.isWithN(vecColumnTypes
069: .get(j).toString())) {
070: strQueryUpdate += "N";
071: }
072: strQueryUpdate += "'dummyOverwrite'" + ", ";
073: } else {
074: strQueryUpdate += "dummyOverwrite" + ", ";
075: }
076: } catch (LoaderException e) {
077: LoaderException le = new LoaderException(
078: "Exception:Type not present in conf file for target database, add it into conf file.",
079: (Throwable) e);
080: throw le;
081: }
082: } else if (vecColumnMode.get(j).toString()
083: .equalsIgnoreCase("SetNull")) {
084: strQueryUpdate += "dummySetNull" + ", ";
085: indexDummySetNull.add(String.valueOf(counter));
086: }
087: }
088: if (oid)
089: strQueryUpdate += " " + this .versionName + " = "
090: + "dummyVersionOverwrite" + " where ";
091: else {
092: int start = strQueryUpdate.lastIndexOf(",");
093: if (start < strQueryUpdate.length() - 1 && start != -1)
094: strQueryUpdate = strQueryUpdate.substring(0,
095: strQueryUpdate.lastIndexOf(","));
096: strQueryUpdate += " where ";
097: }
098: }
099:
100: /**
101: * This method read the value of strQueryUpdate parameter
102: * @return value of parameter
103: */
104: public String getQueryUpdate() {
105: return this .strQueryUpdate;
106: }
107:
108: /**
109: * This method read the value of indexDummyOverwrite parameter
110: * @return value of parameter
111: */
112: public Vector getIndexDummyOverwrite() {
113: return indexDummyOverwrite;
114: }
115:
116: /**
117: * This method read the value of indexDummySetNull parameter
118: * @return value of parameter
119: */
120: public Vector getIndexDummySetNull() {
121: return indexDummySetNull;
122: }
123:
124: }
|