0001: /*
0002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
0003: C/Oña, 107 1º2 28050 Madrid (Spain)
0004:
0005: Redistribution and use in source and binary forms, with or without
0006: modification, are permitted provided that the following conditions
0007: are met:
0008:
0009: 1. Redistributions of source code must retain the above copyright
0010: notice, this list of conditions and the following disclaimer.
0011:
0012: 2. The end-user documentation included with the redistribution,
0013: if any, must include the following acknowledgment:
0014: "This product includes software parts from hipergate
0015: (http://www.hipergate.org/)."
0016: Alternately, this acknowledgment may appear in the software itself,
0017: if and wherever such third-party acknowledgments normally appear.
0018:
0019: 3. The name hipergate must not be used to endorse or promote products
0020: derived from this software without prior written permission.
0021: Products derived from this software may not be called hipergate,
0022: nor may hipergate appear in their name, without prior written
0023: permission.
0024:
0025: This library is distributed in the hope that it will be useful,
0026: but WITHOUT ANY WARRANTY; without even the implied warranty of
0027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0028:
0029: You should have received a copy of hipergate License with this code;
0030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
0031: */
0032:
0033: package com.knowgate.datacopy;
0034:
0035: import java.sql.DriverManager;
0036: import java.sql.Connection;
0037: import java.sql.Timestamp;
0038: import java.sql.SQLException;
0039: import java.sql.CallableStatement;
0040: import java.sql.Statement;
0041: import java.sql.PreparedStatement;
0042: import java.sql.ResultSet;
0043: import java.sql.ResultSetMetaData;
0044:
0045: import java.io.IOException;
0046: import java.io.File;
0047: import java.io.FileReader;
0048: import java.io.BufferedReader;
0049: import java.io.StringBufferInputStream;
0050: import java.io.FileInputStream;
0051: import java.io.FileWriter;
0052: import java.io.StringReader;
0053:
0054: import java.lang.ArrayIndexOutOfBoundsException;
0055: import java.lang.ClassNotFoundException;
0056: import java.math.BigDecimal;
0057: import java.util.Vector;
0058: import java.util.LinkedList;
0059: import java.util.ListIterator;
0060: import java.util.HashMap;
0061: import java.util.Properties;
0062: import java.util.Enumeration;
0063: import java.util.Set;
0064: import java.util.Iterator;
0065: import org.xml.sax.*;
0066: import org.xml.sax.helpers.*;
0067:
0068: import org.apache.oro.text.regex.*;
0069:
0070: import com.knowgate.debug.DebugFile;
0071:
0072: /**
0073: * <p>Copier for Complex Data Structures stored at database.</p>
0074: * This is not a general purpose module, but a custom class tailored to the
0075: * design constraints of hipergate standard datamodel.
0076: * @author Sergio Montoro Ten
0077: * @version 0.6 alpha
0078: */
0079: public class DataStruct extends DefaultHandler implements
0080: ContentHandler {
0081:
0082: public DataStruct() {
0083: initMembers();
0084: } // DataStruct()
0085:
0086: // ----------------------------------------------------------
0087:
0088: public DataStruct(String sPathXMLFile)
0089: throws ClassNotFoundException, IllegalAccessException,
0090: InstantiationException, IOException, SAXException {
0091: initMembers();
0092: parse(sPathXMLFile);
0093: } // DataStruct()
0094:
0095: // ----------------------------------------------------------
0096:
0097: public DataStruct(String sPathXMLFile, Properties oProps)
0098: throws ClassNotFoundException, IllegalAccessException,
0099: InstantiationException, IOException, SAXException {
0100: initMembers();
0101: parse(sPathXMLFile, oProps);
0102: } // DataStruct()
0103:
0104: // ----------------------------------------------------------
0105:
0106: private void initMembers() {
0107: // Cuenta de tablas en la estructura de datos
0108: cTables = 0;
0109:
0110: // Indicador de si están los cursores preparados
0111: bOrPrepared = false;
0112: bTrPrepared = false;
0113:
0114: // Indicador de estado de las conexiones { DISCONNECTED, CONNECTED, REFERENCED }
0115: iTrStatus = iOrStatus = DISCONNECTED;
0116:
0117: // Vector para los DataRowSets
0118: DataRowSets = new Vector();
0119: // Vector de HashMaps con mapeos de nombres de campos
0120: FieldMaps = new Vector();
0121: // Vector de HashMaps con valores por defecto para campos que no existan en Origen
0122: FieldDefs = new Vector();
0123: // Transformaciones de datos para reemplazo de nulos y nuevos valores
0124: Transformations = new Vector();
0125: // Vector con acciones para efectuar antes de empezar la copia de cada Rowset
0126: Before = new Vector();
0127: // Vector con acciones para efectuar después de terminar la copia de cada Rowset
0128: After = new Vector();
0129: // Mapeo entre valores GUID en origen y campos autonuméricos en destino
0130: // GuidToIdentityMap = new HashMap(103);
0131: } // initMembers()
0132:
0133: // ----------------------------------------------------------
0134:
0135: public void setAutoCommit(boolean bAutoCommit) throws SQLException {
0136: oTrConn.setAutoCommit(bAutoCommit);
0137: }
0138:
0139: // ----------------------------------------------------------
0140:
0141: public void commit() throws SQLException {
0142: oTrConn.commit();
0143: }
0144:
0145: // ----------------------------------------------------------
0146:
0147: public void rollback() throws SQLException {
0148: oTrConn.rollback();
0149: }
0150:
0151: // ----------------------------------------------------------
0152:
0153: public void connectOrigin(String sDriver, String sURL, String sUsr,
0154: String sPwd, String sSchema) throws SQLException,
0155: ClassNotFoundException {
0156: // Conecta la conexión Origen
0157: if (DebugFile.trace)
0158: DebugFile.writeln("Begin DataStruct.connectOrigin("
0159: + sDriver + "," + sURL + "," + sUsr + "," + sPwd
0160: + ")");
0161:
0162: // Carga el driver JDBC
0163: Class oDriver = Class.forName(sDriver);
0164:
0165: if (DebugFile.trace)
0166: DebugFile.writeln(" " + sDriver + " JDBC driver loaded");
0167:
0168: oOrConn = DriverManager.getConnection(sURL, sUsr, sPwd);
0169: iOrStatus = CONNECTED;
0170:
0171: if (DebugFile.trace)
0172: DebugFile.writeln("End DataStruct.connectOrigin()");
0173: } // connectOrigin()
0174:
0175: // ----------------------------------------------------------
0176:
0177: public void connectTarget(String sDriver, String sURL, String sUsr,
0178: String sPwd, String sSchema) throws SQLException,
0179: ClassNotFoundException {
0180: // Conecta la conexión Destino
0181: if (DebugFile.trace)
0182: DebugFile.writeln("Begin DataStruct.connectTarget("
0183: + sDriver + "," + sURL + "," + sUsr + "," + sPwd
0184: + ")");
0185:
0186: // Carga el driver JDBC
0187: Class oDriver = Class.forName(sDriver);
0188:
0189: if (DebugFile.trace)
0190: DebugFile.writeln(" " + sDriver + " JDBC driver loaded");
0191:
0192: oTrConn = DriverManager.getConnection(sURL, sUsr, sPwd);
0193: iTrStatus = CONNECTED;
0194:
0195: if (DebugFile.trace)
0196: DebugFile.writeln("End DataStruct.connectTarget()");
0197: }
0198:
0199: // ----------------------------------------------------------
0200:
0201: public Connection getOriginConnection() {
0202: return oOrConn;
0203: }
0204:
0205: // ----------------------------------------------------------
0206:
0207: public Connection getTargetConnection() {
0208: return oTrConn;
0209: }
0210:
0211: // ----------------------------------------------------------
0212:
0213: public void setOriginConnection(Connection oConn) {
0214: // Establece una referencia a una conexión Origen ya existente
0215: oOrConn = oConn;
0216: iOrStatus = REFERENCED;
0217: }
0218:
0219: // ----------------------------------------------------------
0220:
0221: public void setTargetConnection(Connection oConn) {
0222: // Establece una referencia a una conexión Destino ya existente
0223: oTrConn = oConn;
0224: iTrStatus = REFERENCED;
0225: }
0226:
0227: // ----------------------------------------------------------
0228:
0229: public void clear() throws SQLException {
0230: // Limpia todas las estructuras internas de datos del DataStruct
0231: int t;
0232:
0233: if (DebugFile.trace)
0234: DebugFile.writeln("Begin DataStruct.clear()");
0235:
0236: if (bOrPrepared) {
0237: for (t = 0; t < cTables; t++) {
0238: if (null != OrStatements[t])
0239: OrStatements[t].close();
0240: OrStatements[t] = null;
0241: if (null != UpStatements[t])
0242: UpStatements[t].close();
0243: UpStatements[t] = null;
0244: }
0245: OrMetaData = null;
0246: bOrPrepared = false;
0247: }
0248:
0249: if (bTrPrepared) {
0250: for (t = 0; t < cTables; t++) {
0251: if (null != TrStatements[t])
0252: TrStatements[t].close();
0253: TrStatements[t] = null;
0254: if (null != DlStatements[t])
0255: DlStatements[t].close();
0256: DlStatements[t] = null;
0257: }
0258: TrMetaData = null;
0259: bTrPrepared = false;
0260: }
0261:
0262: // Cuenta de tablas en la estructura de datos
0263: cTables = 0;
0264:
0265: if (null != After)
0266: After.clear();
0267: if (null != Before)
0268: Before.clear();
0269: if (null != Transformations)
0270: Transformations.clear();
0271: if (null != FieldDefs)
0272: FieldDefs.clear();
0273: if (null != FieldMaps)
0274: FieldMaps.clear();
0275: if (null != DataRowSets)
0276: DataRowSets.clear();
0277:
0278: if (DebugFile.trace)
0279: DebugFile.writeln("End DataStruct.clear()");
0280:
0281: } // clear()
0282:
0283: // ----------------------------------------------------------
0284:
0285: public void disconnectAll() throws SQLException {
0286: // Cierra todos los cursores y las conexiones
0287: int t;
0288:
0289: if (DebugFile.trace)
0290: DebugFile.writeln("Begin DataStruct.disconnectAll()");
0291:
0292: clear();
0293:
0294: // Sólo hay que cerrar las conexiones si no son referencias externas
0295: if (CONNECTED == iOrStatus) {
0296: oOrConn.close();
0297: iOrStatus = DISCONNECTED;
0298: }
0299: if (CONNECTED == iTrStatus) {
0300: oTrConn.close();
0301: iTrStatus = DISCONNECTED;
0302: }
0303:
0304: if (DebugFile.trace)
0305: DebugFile.writeln("End DataStruct.disconnectAll()");
0306: } // close()
0307:
0308: // ----------------------------------------------------------
0309:
0310: protected DataRowSet getRowSet(int i) {
0311: return (DataRowSet) DataRowSets.get(i);
0312: }
0313:
0314: // ----------------------------------------------------------
0315:
0316: protected Object getResult(int iRow, int iCol) {
0317: return ((Vector) oResults.get(iRow)).get(iCol);
0318: }
0319:
0320: // ----------------------------------------------------------
0321:
0322: private boolean isEmpty(String sStr) {
0323: // Devuelve true si sStr=="" ó sStr==null
0324: if (null == sStr)
0325: return true;
0326: else if (0 == sStr.length())
0327: return true;
0328: else
0329: return false;
0330: } // isEmpty()
0331:
0332: // ----------------------------------------------------------
0333:
0334: protected void execCommands(String sTime, int iTable, Object PK[],
0335: int cParams) throws SQLException, NullPointerException {
0336: // Ejecuta los comandos <INIT>, <TERM>, <BEFORE> o <AFTER> definidos para este DataStruct
0337: CallableStatement oCall;
0338: Statement oStmt;
0339: ResultSet rCount;
0340: int cAffected;
0341: String sSQL;
0342: String sTable;
0343: ListIterator oIter;
0344:
0345: if (DebugFile.trace) {
0346: if (iTable != -1)
0347: sTable = getRowSet(iTable).OriginTable;
0348: else
0349: sTable = "";
0350: DebugFile.writeln("Begin DataStruct.execCommands(" + sTime
0351: + ", " + sTable + ", ..., "
0352: + String.valueOf(cParams) + ")");
0353: DebugFile.incIdent();
0354: }
0355:
0356: // Seleccionar el iterador para la lista adecudada de comandos
0357: if (-1 == iTable) {
0358: if (sTime.equals("INIT")) {
0359: if (null == InitStmts)
0360: throw new NullPointerException(
0361: "DataStruct.execCommands() InitStmts list not initialized");
0362: oIter = InitStmts.listIterator();
0363: } else {
0364: if (null == TermStmts)
0365: throw new NullPointerException(
0366: "DataStruct.execCommands() TermStmts list not initialized");
0367: oIter = TermStmts.listIterator();
0368: }
0369: } else {
0370: if (sTime.equals("BEFORE"))
0371: oIter = ((LinkedList) Before.get(iTable))
0372: .listIterator();
0373: else
0374: oIter = ((LinkedList) After.get(iTable)).listIterator();
0375: }
0376:
0377: while (oIter.hasNext()) {
0378: sSQL = oIter.next().toString();
0379:
0380: // Si el SQL empieza por "{" entonces se ejecuta como un procedimiento almacenado
0381: if (sSQL.startsWith("{") || sSQL.startsWith("k_sp")) {
0382: if (DebugFile.trace)
0383: DebugFile.writeln("Connection.prepareCall(" + sSQL
0384: + ")");
0385: oCall = oTrConn.prepareCall(sSQL);
0386: for (int p = 0; p < cParams; p++) {
0387: if (DebugFile.trace)
0388: DebugFile
0389: .writeln("CallableStatement.setObject("
0390: + String.valueOf(p + 1) + ","
0391: + PK[p].toString() + ")");
0392: oCall.setObject(p + 1, PK[p]);
0393: } // next (p)
0394: if (DebugFile.trace)
0395: DebugFile.writeln("Connection.execute(" + sSQL
0396: + ")");
0397: oCall.execute();
0398: oCall.close();
0399: oCall = null;
0400: }
0401: // Si el SQL NO empieza por "{" entonces se ejecuta como un comando sin ResultSet de vuelta
0402: else {
0403: oStmt = oTrConn.createStatement();
0404: if (DebugFile.trace)
0405: DebugFile.writeln("Connection.execute(" + sSQL
0406: + ")");
0407: oStmt.execute(sSQL);
0408: oStmt.close();
0409: oStmt = null;
0410: }
0411: } // wend
0412:
0413: if (DebugFile.trace) {
0414: DebugFile.decIdent();
0415: DebugFile.writeln("End DataStruct.execCommands()");
0416: }
0417: } // execCommands()
0418:
0419: // ----------------------------------------------------------
0420:
0421: public void prepareStatements() throws SQLException {
0422: // Método para dejar todos los cursores de lectura y escritura preparados
0423: // Se llama internamente al inicio de los método inser, update o delete
0424:
0425: HashMap oMap;
0426: String sSQL;
0427: boolean bIsMapped;
0428: boolean bHasDefault;
0429: int iTrCols;
0430: String sCol;
0431: int iCol;
0432: int c;
0433:
0434: if (DebugFile.trace) {
0435: DebugFile.writeln("Begin DataStruct.prepareStatements()");
0436: DebugFile.incIdent();
0437: }
0438:
0439: oInsertTexts = new HashMap(2 * cTables); // Texto SQL de las sentencias Insert
0440: oSelectTexts = new HashMap(2 * cTables); // Texto SQL de las sentencias Select
0441:
0442: OrStatements = new PreparedStatement[cTables]; // Sentencias de lectura
0443: TrStatements = new PreparedStatement[cTables]; // Sentencias de escritura
0444: UpStatements = new PreparedStatement[cTables]; // Sentencias de actualización
0445: DlStatements = new PreparedStatement[cTables]; // Sentencias de borrado
0446:
0447: OrMetaData = new DataTblDef[cTables]; // Metadatos de las tablas de Origen
0448: TrMetaData = new DataTblDef[cTables]; // Metadatos de las tablas de Destino
0449:
0450: // Recorrer la lista de tablas y preparar los cursores de lectura, escritura y borrado
0451: for (int s = 0; s < cTables; s++) {
0452:
0453: if (CONNECTED == iTrStatus || REFERENCED == iTrStatus) {
0454:
0455: // **************************************
0456: // Leer la estructura de la tabla destino
0457: TrMetaData[s] = new DataTblDef();
0458: if (DebugFile.trace)
0459: DebugFile
0460: .writeln("DataTblDef.readMetaData (TargetConnection, "
0461: + getRowSet(s).TargetTable
0462: + ", "
0463: + (String) oToPKs
0464: .get(getRowSet(s).TargetTable)
0465: + ")");
0466:
0467: // Evitar una excepción Java NullPointerException si no hay PKs en destino
0468: if (oToPKs.get(getRowSet(s).TargetTable) != null)
0469: TrMetaData[s].readMetaData(oTrConn,
0470: getRowSet(s).TargetTable, oToPKs.get(
0471: getRowSet(s).TargetTable)
0472: .toString());
0473: else
0474: TrMetaData[s].readMetaData(oTrConn,
0475: getRowSet(s).TargetTable, null);
0476: // ***
0477:
0478: // **********************************
0479: // Preparar las sentencias de borrado
0480: sSQL = "DELETE FROM " + getRowSet(s).TargetTable;
0481: if (!isEmpty(getRowSet(s).EraseClause))
0482: sSQL += " WHERE " + getRowSet(s).EraseClause;
0483: else if (!isEmpty(getRowSet(s).WhereClause))
0484: sSQL += " WHERE " + getRowSet(s).WhereClause;
0485:
0486: if (DebugFile.trace)
0487: DebugFile.writeln("Connection.prepareStatement("
0488: + sSQL + ")");
0489: DlStatements[s] = oTrConn.prepareStatement(sSQL);
0490: // ***
0491:
0492: iTrCols = TrMetaData[s].ColCount;
0493:
0494: // ************************************
0495: // Preparar las sentencias de inserción
0496: sSQL = "INSERT INTO " + getRowSet(s).TargetTable
0497: + " VALUES (";
0498: for (c = iTrCols; c >= 1; c--)
0499: sSQL += (c != 1) ? "?," : "?)";
0500:
0501: if (DebugFile.trace)
0502: DebugFile.writeln("Connection.prepareStatement("
0503: + sSQL + ")");
0504:
0505: // Guardar el texto de SQL generado en un HashMap por si luego
0506: // es preciso recuperarlo usando la tabla de Origen como PK
0507: oInsertTexts.put(getRowSet(s).OriginTable, sSQL);
0508:
0509: TrStatements[s] = oTrConn.prepareStatement(sSQL);
0510: // ***
0511:
0512: // ****************************************
0513: // Preparar las sentencias de actualización
0514: sSQL = "UPDATE " + getRowSet(s).TargetTable + " SET ";
0515: for (c = 0; c < iTrCols; c++)
0516: if (!TrMetaData[s].isPrimaryKey(c))
0517: sSQL += TrMetaData[s].ColNames[c] + "=?,";
0518: sSQL = sSQL.substring(0, sSQL.length() - 1) + " WHERE ";
0519: for (c = 0; c < TrMetaData[s].cPKs; c++)
0520: sSQL += TrMetaData[s].PrimaryKeys[c] + "=? AND ";
0521: sSQL = sSQL.substring(0, sSQL.length() - 5);
0522:
0523: if (DebugFile.trace)
0524: DebugFile.writeln("Connection.prepareStatement("
0525: + sSQL + ")");
0526: UpStatements[s] = oTrConn.prepareStatement(sSQL);
0527: // ***
0528: } // fi (CONNECTED==iTrStatus)
0529:
0530: if (CONNECTED == iOrStatus || REFERENCED == iOrStatus) {
0531:
0532: // *************************************
0533: // Leer la estructura de la tabla origen
0534: OrMetaData[s] = new DataTblDef();
0535: if (DebugFile.trace)
0536: DebugFile
0537: .writeln("DataTblDef.readMetaData (OriginConnection, "
0538: + getRowSet(s).OriginTable
0539: + ", "
0540: + (String) oToPKs
0541: .get(getRowSet(s).OriginTable)
0542: + ")");
0543: OrMetaData[s].readMetaData(oOrConn,
0544: getRowSet(s).OriginTable, (String) oFromPKs
0545: .get(getRowSet(s).OriginTable));
0546:
0547: if (CONNECTED == iTrStatus || REFERENCED == iTrStatus)
0548: iTrCols = TrMetaData[s].ColCount;
0549: else
0550: iTrCols = OrMetaData[s].ColCount;
0551:
0552: if (DebugFile.trace)
0553: DebugFile.writeln("Column count = "
0554: + String.valueOf(iTrCols));
0555:
0556: // Preparar las sentencias de lectura
0557: if (getRowSet(s).FieldList.compareTo("*") != 0) {
0558: sSQL = "SELECT " + getRowSet(s).FieldList + " ";
0559: } else {
0560: sSQL = "SELECT ";
0561: for (c = 0; c < iTrCols; c++) {
0562: // Obtener el nombre en destino de la columna a leer
0563: sCol = TrMetaData[s].ColNames[c];
0564:
0565: try {
0566: oMap = (HashMap) FieldMaps.get(s);
0567: // Si existe un mapeo de nombres,
0568: // traducir el nombre en destino al que tenga en origen.
0569: // Tener en cuenta el caso en que la columna destino está
0570: // definida como autoincremental
0571: bIsMapped = oMap.containsKey(sCol);
0572: if (bIsMapped)
0573: sCol = (String) oMap.get(sCol);
0574: else {
0575: bIsMapped = oMap.containsKey(sCol
0576: .toUpperCase());
0577: if (bIsMapped)
0578: sCol = (String) oMap.get(sCol
0579: .toUpperCase());
0580: else {
0581: bIsMapped = oMap.containsKey(sCol
0582: .toLowerCase());
0583: if (bIsMapped)
0584: sCol = (String) oMap.get(sCol
0585: .toLowerCase());
0586: }
0587: }
0588: } catch (ArrayIndexOutOfBoundsException e) {
0589: bIsMapped = false;
0590: }
0591:
0592: // Obtener la posición de la columna en origen
0593: iCol = OrMetaData[s].findColumnPosition(sCol);
0594: if (iCol != -1)
0595: sSQL += sCol
0596: + ((c < iTrCols - 1) ? "," : " ");
0597: else {
0598: try {
0599: oMap = (HashMap) FieldDefs.get(s);
0600: bHasDefault = oMap.containsKey(sCol);
0601: } catch (ArrayIndexOutOfBoundsException e) {
0602: // Si el XML no tiene una sección <DEFVALS>
0603: // la llamada FieldDefs.get(s) provocará una
0604: // excepción ArrayIndexOutOfBoundsException
0605: bHasDefault = false;
0606: oMap = null;
0607: }
0608: if (bHasDefault)
0609: // Si la columna no existe en origen mirar si tiene definido valor por defecto
0610: sSQL += (String) oMap.get(sCol)
0611: + " AS "
0612: + TrMetaData[s].ColNames[c]
0613: + ((c < iTrCols - 1) ? ","
0614: : " ");
0615: else if (bIsMapped)
0616: sSQL += sCol
0617: + " AS "
0618: + TrMetaData[s].ColNames[c]
0619: + ((c < iTrCols - 1) ? ","
0620: : " ");
0621: else
0622: // Si no tiene valor por defecto leer NULL para luego grabarlo a posteriori
0623: sSQL += "NULL AS "
0624: + TrMetaData[s].ColNames[c]
0625: + ((c < iTrCols - 1) ? ","
0626: : " ");
0627: } // fi (iCol!=-1)
0628: } // next (c)
0629: } // fi (DataRowSets[s].FieldList=="*")
0630:
0631: sSQL += "FROM " + getRowSet(s).OriginTable;
0632: if (!isEmpty(getRowSet(s).WhereClause)) {
0633: if (getRowSet(s).WhereClause.trim().toUpperCase()
0634: .startsWith("START"))
0635: sSQL += " " + getRowSet(s).WhereClause;
0636: else
0637: sSQL += " WHERE " + getRowSet(s).WhereClause;
0638: } // fi (isEmpty(getRowSet(s).WhereClause)
0639:
0640: if (DebugFile.trace)
0641: DebugFile.writeln("Connection.prepareStatement("
0642: + sSQL + ")");
0643:
0644: oSelectTexts.put(getRowSet(s).OriginTable, sSQL);
0645:
0646: OrStatements[s] = oOrConn.prepareStatement(sSQL,
0647: ResultSet.TYPE_FORWARD_ONLY,
0648: ResultSet.CONCUR_READ_ONLY);
0649: // ***
0650: } // end if (CONNECTED==iOrStatus)
0651: } // end for (s)
0652:
0653: if (CONNECTED == iOrStatus || REFERENCED == iOrStatus)
0654: bOrPrepared = true;
0655: if (CONNECTED == iTrStatus || REFERENCED == iTrStatus)
0656: bTrPrepared = true;
0657:
0658: if (DebugFile.trace) {
0659: DebugFile.decIdent();
0660: DebugFile.writeln("End DataStruct.prepareStatements()");
0661: }
0662: } // prepareStatements()
0663:
0664: // ----------------------------------------------------------
0665:
0666: public Object convert(Object oValue, int iSQLType) {
0667: // Función de soporte para hacer castings de tipos entre bases de datos
0668:
0669: Object oRetVal;
0670: String sClass;
0671:
0672: if (null == oValue) {
0673: oRetVal = null;
0674: } else {
0675: sClass = oValue.getClass().getName();
0676:
0677: if (sClass.equals("java.lang.Short")
0678: || sClass.equals("java.lang.Integer")
0679: || sClass.equals("java.math.BigDecimal")) {
0680: if (java.sql.Types.VARCHAR == iSQLType
0681: || java.sql.Types.CHAR == iSQLType
0682: || java.sql.Types.LONGVARCHAR == iSQLType)
0683: oRetVal = oValue.toString();
0684: else if (java.sql.Types.DECIMAL == iSQLType
0685: || java.sql.Types.NUMERIC == iSQLType)
0686: oRetVal = new BigDecimal(oValue.toString());
0687: else if (java.sql.Types.INTEGER == iSQLType)
0688: oRetVal = new Integer(oValue.toString());
0689: else if (java.sql.Types.SMALLINT == iSQLType)
0690: oRetVal = new Short(oValue.toString());
0691: else
0692: oRetVal = oValue;
0693: } else if (sClass.equals("java.lang.String")) {
0694: if (java.sql.Types.DECIMAL == iSQLType
0695: || java.sql.Types.NUMERIC == iSQLType)
0696: oRetVal = new BigDecimal(oValue.toString());
0697: else if (java.sql.Types.SMALLINT == iSQLType)
0698: oRetVal = new Short(oValue.toString());
0699: else if (java.sql.Types.INTEGER == iSQLType) {
0700: String str = oValue.toString();
0701: oRetVal = new Integer(str);
0702: } else
0703: oRetVal = oValue;
0704: } else if (sClass.equals("java.sql.Timestamp")) {
0705: oRetVal = new java.sql.Date(((Timestamp) oValue)
0706: .getTime());
0707: } else
0708: oRetVal = oValue;
0709: }
0710: return oRetVal;
0711: } // convert()
0712:
0713: // ----------------------------------------------------------
0714:
0715: public int mapType(int iSQLType) {
0716: // Mapeo de tipos,
0717: // actualmente sólo sirve para convertir los TIMESTAMP en DATETIME
0718:
0719: int iRetType;
0720:
0721: switch (iSQLType) {
0722: case java.sql.Types.TIMESTAMP:
0723: iRetType = java.sql.Types.DATE;
0724: break;
0725: default:
0726: iRetType = iSQLType;
0727: }
0728: return iRetType;
0729: } // mapType()
0730:
0731: // ----------------------------------------------------------
0732:
0733: /* ESTA FUNCION NO ESTA TESTEADA Y NO FUNCIONA!!!
0734: public void delete(Object[] TrPK, int cParams) throws SQLException {
0735:
0736: PreparedStatement oStmt;
0737: DataTblDef oMDat;
0738: HashMap oMap;
0739: int iErsd;
0740:
0741: if (DebugFile.trace) {
0742: DebugFile.writeln ("Begin DataStruct.delete(TrPK[], " + String.valueOf(cParams) + ")");
0743: DebugFile.incIdent();
0744: }
0745:
0746: execCommands("INIT", -1, TrPK, cParams);
0747:
0748: for (int s=cTables-1; s>=0; s++) {
0749: oMDat = TrMetaData[s];
0750: oStmt = TrStatements[s];
0751: for (int p=0;p<cParams; p++)
0752: oStmt.setObject(p+1, TrPK[p], oMDat.findColumnType(oMDat.PrimaryKeys[p]));
0753: iErsd = oStmt.executeUpdate();
0754: if (DebugFile.trace) DebugFile.writeln (String.valueOf(iErsd) + " rows deleted from " + getRowSet(s).TargetTable);
0755: } // end for (s)
0756:
0757: execCommands("TERM", -1, TrPK, cParams);
0758:
0759: if (DebugFile.trace) {
0760: DebugFile.decIdent();
0761: DebugFile.writeln ("End DataStruct.delete()");
0762: }
0763: } // delete()
0764: */
0765:
0766: // ----------------------------------------------------------
0767: protected void getRows(Object[] OrPK, Object[] TrPK, int cParams,
0768: int iTable) throws SQLException {
0769: // Método interno de soporte para leer un conjunto de final y almacenarlo
0770: // en una matriz bidimensional de objetos
0771:
0772: int iPK;
0773: int iFetchBurst = 500; // Tamaño de ráfaga de lectura
0774: int iSQLType;
0775: int cTransforms;
0776: Vector oRow;
0777: HashMap oTransforms;
0778: Object oOriginalValue;
0779: Object oTransformedValue;
0780: ResultSet oRSet;
0781: ResultSetMetaData oRDat;
0782: DataRowSet oDatR;
0783: String sColName;
0784: DataTblDef oMDat = OrMetaData[iTable];
0785: DataTransformation oDatT;
0786: PreparedStatement oStmt = OrStatements[iTable];
0787: PreparedStatement oStmt2;
0788:
0789: // Asignar los parametros de la clave primaria para leer valores en origen
0790:
0791: oDatR = getRowSet(iTable);
0792: // Comprobar primero si existen parámetros en la cláusula WHERE
0793: if (oDatR.WhereClause != null) {
0794: if (oDatR.WhereClause.indexOf("?") > 0) {
0795: for (int p = 0; p < cParams; p++) {
0796: if (DebugFile.trace)
0797: DebugFile
0798: .writeln("binding query input parameter "
0799: + String.valueOf(p + 1));
0800: oStmt.setObject(p + 1, OrPK[p]);
0801: } // next (p)
0802: } // fi (oDatR.WhereClause.indexOf("?")>0)
0803: } // fi (oDatR.WhereClause!=null)
0804:
0805: if (DebugFile.trace)
0806: DebugFile.writeln("PreparedStatement.executeQuery()");
0807:
0808: oRSet = oStmt.executeQuery(); // Ejecutar la query de lectura de registros
0809:
0810: /* Not supported under PostgreSQL 7.3.4
0811: if (DebugFile.trace) DebugFile.writeln ("ResultSet.setFetchSize(" + String.valueOf(iFetchBurst) + ")");
0812:
0813: oRSet.setFetchSize (iFetchBurst); // Asignar el tamaño de ráfaga de vuelta
0814: */
0815:
0816: oDatR = null;
0817:
0818: if (DebugFile.trace) {
0819: if (DataRowSets.get(iTable) != null)
0820: DebugFile.writeln("FieldList="
0821: + getRowSet(iTable).FieldList);
0822: else
0823: DebugFile.writeln("ERROR: getRowSet("
0824: + String.valueOf(iTable) + ") == null");
0825: }
0826:
0827: // Si se especificó explícitamente una lista de campos a leer,
0828: // entonces tomar como número de columnas la del Origen,
0829: // en otro caso tomar como número de columnas las del Destino.
0830: if (getRowSet(iTable).FieldList.compareTo("*") != 0)
0831: iCols = oRSet.getMetaData().getColumnCount();
0832: else
0833: iCols = TrMetaData[iTable].ColCount;
0834:
0835: if (DebugFile.trace)
0836: DebugFile.writeln("reading " + String.valueOf(iCols)
0837: + " columns");
0838:
0839: // Guardar los resultados en una matriz bidimensional almacenada como un vector de filas
0840: oResults = new Vector(iFetchBurst, iFetchBurst);
0841:
0842: if (DebugFile.trace)
0843: DebugFile.writeln("new Vector("
0844: + String.valueOf(iFetchBurst) + ")");
0845:
0846: iRows = 0;
0847:
0848: try {
0849: // Obtener una referencia a las transformaciones de datos para el RowSet actual
0850: oTransforms = (HashMap) Transformations.get(iTable);
0851: cTransforms = oTransforms.size();
0852: } catch (ArrayIndexOutOfBoundsException e) {
0853: if (DebugFile.trace)
0854: DebugFile
0855: .writeln("table has no transformation replacements");
0856: oTransforms = null;
0857: cTransforms = 0;
0858: }
0859:
0860: if (0 == cTransforms) {
0861: // Si no hay transformaciones para campos, usar un algoritmo más rápido con menos condiciones
0862: while (oRSet.next() && iRows < iFetchBurst) {
0863: iRows++;
0864: if (DebugFile.trace)
0865: DebugFile.writeln("caching row "
0866: + String.valueOf(iRows));
0867: oRow = new Vector(iCols);
0868: for (int c = 1; c <= iCols; c++)
0869: oRow.add(oRSet.getObject(c));
0870: oResults.add(oRow);
0871: } // wend ()
0872: } else { // Algoritmo con más condiciones para el caso de reemplazo de transformación de datos
0873: oRDat = oRSet.getMetaData(); // Alias rápido a los metadatos del ResultSet
0874: while (oRSet.next() && iRows < iFetchBurst) {
0875: iRows++;
0876: if (DebugFile.trace)
0877: DebugFile.writeln("caching row "
0878: + String.valueOf(iRows));
0879: // Crear un vector para la fila
0880: oRow = new Vector(iCols);
0881: // Recorer cada columna y almacenar su valor en el vector fila
0882: iPK = 0;
0883: for (int c = 1; c <= iCols; c++) {
0884: try {
0885: // Obtener una referencia a la transformación para la columna actual
0886: // si no hay transformación saltará una excepción y el valor de la
0887: // columna se asignará en la sección catch()
0888: sColName = oRDat.getColumnName(c);
0889:
0890: oDatT = (DataTransformation) oTransforms
0891: .get(sColName);
0892:
0893: // Asignar el valor transformado del campo
0894: if (null == oDatT)
0895: oRow.add(oRSet.getObject(c));
0896: else {
0897: oOriginalValue = oRSet.getObject(c);
0898:
0899: oTransformedValue = oDatT.transform(
0900: getOriginConnection(),
0901: getTargetConnection(),
0902: oOriginalValue);
0903:
0904: if (DebugFile.trace)
0905: DebugFile
0906: .writeln(sColName
0907: + " "
0908: + oOriginalValue
0909: + " transformed to "
0910: + (oTransformedValue != null ? oTransformedValue
0911: : "NULL"));
0912:
0913: oRow.add(oTransformedValue);
0914: }
0915: } catch (ArrayIndexOutOfBoundsException e) {
0916: oRow.add(oRSet.getObject(c));
0917: }
0918: } // next (c)
0919: oResults.add(oRow);
0920: } // wend ()
0921: oRDat = null;
0922: } // end if (FieldNils[s].size()==0)
0923:
0924: if (DebugFile.trace)
0925: DebugFile.writeln("row count = " + String.valueOf(iRows));
0926:
0927: oRSet.close();
0928: oRSet = null;
0929: } // getRows()
0930:
0931: // ----------------------------------------------------------
0932:
0933: public void insert(Object[] OrPK, Object[] TrPK, int cParams)
0934: throws SQLException, NullPointerException {
0935: // Inserta registros del Origen en el Destino,
0936: // si encuentra un registro duplicado lo actualiza sin dar ningún error,
0937: // si el registro no está, lo inserta
0938:
0939: String sField;
0940: DataTblDef oMDat;
0941: PreparedStatement oInsrt;
0942: StringReader oReader;
0943: Object oValue;
0944: String sValue;
0945: int r;
0946: int q;
0947: int iPK;
0948: int iSQLType;
0949:
0950: if (DebugFile.trace) {
0951: DebugFile
0952: .writeln("Begin DataStruct.insert(OrPK[], TrPK[], "
0953: + String.valueOf(cParams) + ")");
0954: DebugFile.incIdent();
0955: }
0956:
0957: execCommands("INIT", -1, OrPK, cParams);
0958:
0959: // Preparar todos los cursores
0960: if (!bTrPrepared || !bTrPrepared)
0961: prepareStatements();
0962:
0963: // Iterar sobre las tablas: para cada una de ellas leer sus registros e insertarlos en destino
0964: for (int s = 0; s < cTables; s++) {
0965: if (DebugFile.trace)
0966: DebugFile.writeln("processing rowset from "
0967: + getRowSet(s).OriginTable + " to "
0968: + getRowSet(s).TargetTable);
0969:
0970: execCommands("BEFORE", s, OrPK, cParams);
0971:
0972: getRows(OrPK, TrPK, cParams, s); // Modifica {iRows, iCols} como efecto lateral
0973:
0974: oMDat = TrMetaData[s];
0975: oInsrt = TrStatements[s];
0976:
0977: // Iterar sobre cada fila leida en origen y actualizarla en destino
0978: for (r = 0; r < iRows; r++) {
0979: iPK = 0;
0980: // Iterador de parametros de entrada
0981: for (q = 0; q < iCols; q++) {
0982: sField = oMDat.ColNames[q];
0983: iSQLType = oMDat.ColTypes[q];
0984: oValue = getResult(r, q);
0985:
0986: if (oMDat.isPrimaryKey(q)) {
0987: if (iPK < cParams
0988: && oMDat.inheritsPK(TrMetaData[0]))
0989: if (null != TrPK[iPK]) {
0990: if (oValue.getClass().equals(
0991: TrPK[iPK].getClass())
0992: && oMDat.bestMatch(q,
0993: TrMetaData[0], iPK)) {
0994: if (DebugFile.trace)
0995: DebugFile.writeln("swaping PK "
0996: + oValue.toString()
0997: + " to "
0998: + TrPK[iPK].toString()
0999: + " before insert");
1000: oValue = TrPK[iPK];
1001: } // fi (oValue.getClass() == TrPK[iPK].getClass())
1002: } // fi (null!=TrPK[iPK])
1003: iPK++;
1004: } // fi (oMDat.isPrimaryKey(q))
1005:
1006: if (DebugFile.trace)
1007: if (oValue != null)
1008: DebugFile.writeln("binding " + sField + "="
1009: + oValue.toString()
1010: + " as SQLType "
1011: + String.valueOf(iSQLType));
1012: else
1013: DebugFile.writeln("binding " + sField
1014: + "=NULL as SQLType "
1015: + String.valueOf(iSQLType));
1016:
1017: if (iSQLType == java.sql.Types.LONGVARCHAR) {
1018: sValue = oValue.toString() + " ";
1019: oReader = new StringReader(sValue);
1020: oInsrt.setCharacterStream(q + 1, oReader,
1021: sValue.length() - 1);
1022: } else
1023: oInsrt.setObject(q + 1, convert(oValue,
1024: iSQLType), mapType(iSQLType));
1025: } // end for (q)
1026:
1027: if (DebugFile.trace)
1028: DebugFile.writeln("PreparedStatement.execute()");
1029: oInsrt.execute();
1030: } // end for (r)
1031:
1032: oResults.clear();
1033: oResults = null;
1034:
1035: execCommands("AFTER", s, OrPK, cParams);
1036: } // end for (s)
1037:
1038: execCommands("TERM", -1, OrPK, cParams);
1039:
1040: if (DebugFile.trace) {
1041: DebugFile.decIdent();
1042: DebugFile.writeln("End DataStruct.insert()");
1043: }
1044: } // insert
1045:
1046: // ----------------------------------------------------------
1047:
1048: public void update(Object[] OrPK, Object[] TrPK, int cParams)
1049: throws SQLException {
1050: // Inserta registros del Origen en el Destino,
1051: // si encuentra un registro duplicado lo actualiza sin dar ningún error,
1052: // si el registro no está, lo inserta
1053:
1054: String sField;
1055: DataTblDef oMDat;
1056: PreparedStatement oInsrt;
1057: PreparedStatement oUpdt;
1058: Object oValue;
1059: String sValue;
1060: StringReader oReader;
1061: int r;
1062: int q;
1063: int iPK;
1064: int cUpdated;
1065: int iSQLType;
1066:
1067: if (DebugFile.trace) {
1068: DebugFile
1069: .writeln("Begin DataStruct.update(OrPK[], TrPK[], "
1070: + String.valueOf(cParams) + ")");
1071: DebugFile.incIdent();
1072: }
1073:
1074: execCommands("INIT", -1, OrPK, cParams);
1075:
1076: // Preparar todos los cursores
1077: if (!bTrPrepared || !bTrPrepared)
1078: prepareStatements();
1079:
1080: // Iterar sobre las tablas: para cada una de ellas leer sus registros e insertarlos en destino
1081: for (int s = 0; s < cTables; s++) {
1082: if (DebugFile.trace)
1083: DebugFile.writeln("processing rowset from "
1084: + getRowSet(s).OriginTable + " to "
1085: + getRowSet(s).TargetTable);
1086:
1087: execCommands("BEFORE", s, OrPK, cParams);
1088:
1089: getRows(OrPK, TrPK, cParams, s); // Modifica {iRows, iCols} como efecto lateral
1090:
1091: oMDat = TrMetaData[s];
1092: oUpdt = UpStatements[s];
1093:
1094: // Iterar sobre cada fila leida en origen y actualizarla en destino
1095: for (r = 0; r < iRows; r++) {
1096: iPK = 0; // Cuenta de parametros de clave primaria con valor asignado
1097:
1098: if (oMDat.ColCount > oMDat.cPKs) {
1099:
1100: // Iterador de parametros de entrada
1101: for (q = 0; q < iCols; q++) {
1102: sField = oMDat.ColNames[q]; // Nombre del campo en destino
1103: iSQLType = oMDat.ColTypes[q]; // Tipo del campo en destino
1104:
1105: if (oMDat.isPrimaryKey(q)) {
1106: if (iPK < cParams
1107: && oMDat.inheritsPK(TrMetaData[0])) {
1108: if (null != TrPK[iPK]) {
1109: if (getResult(r, q)
1110: .getClass()
1111: .equals(
1112: TrPK[iPK]
1113: .getClass())
1114: && oMDat.bestMatch(q,
1115: TrMetaData[0], iPK)) {
1116: if (DebugFile.trace)
1117: DebugFile
1118: .writeln("swaping PK "
1119: + getResult(
1120: r,
1121: q)
1122: .toString()
1123: + " to "
1124: + TrPK[iPK]
1125: .toString()
1126: + " before update");
1127: oValue = TrPK[iPK];
1128: } else {
1129: oValue = getResult(r, q);
1130: } // fi (getResult(r,q).getClass() == TrPK[iPK].getClass())
1131: } else {
1132: oValue = getResult(r, q);
1133: } // fi (null!=TrPK[iPK])
1134: } else {
1135: oValue = getResult(r, q);
1136: } // fi (iPK<cParams && oMDat.inheritsPK(TrMetaData[0])))
1137:
1138: if (DebugFile.trace)
1139: if (oValue == null)
1140: DebugFile.writeln("binding "
1141: + sField
1142: + "=null as SQLType "
1143: + String.valueOf(iSQLType)
1144: + " at parameter "
1145: + String.valueOf(iCols
1146: - oMDat.cPKs + iPK
1147: + 1));
1148: else
1149: DebugFile.writeln("binding "
1150: + sField
1151: + "="
1152: + oValue.toString()
1153: + " as SQLType "
1154: + String.valueOf(iSQLType)
1155: + " at parameter "
1156: + String.valueOf(iCols
1157: - oMDat.cPKs + iPK
1158: + 1));
1159:
1160: oUpdt.setObject(iCols - oMDat.cPKs + iPK
1161: + 1, convert(oValue, iSQLType),
1162: mapType(iSQLType));
1163: iPK++;
1164: } else {
1165: if (DebugFile.trace)
1166: DebugFile.writeln("binding " + sField
1167: + " as SQLType "
1168: + String.valueOf(iSQLType)
1169: + " at parameter "
1170: + String.valueOf(q + 1 - iPK));
1171:
1172: if (iSQLType == java.sql.Types.LONGVARCHAR) {
1173: sValue = getResult(r, q).toString()
1174: + " ";
1175: oReader = new StringReader(sValue);
1176: oUpdt.setCharacterStream(q + 1 - iPK,
1177: oReader, sValue.length() - 1);
1178: } else
1179: oUpdt.setObject(q + 1 - iPK, convert(
1180: getResult(r, q), iSQLType),
1181: mapType(iSQLType));
1182: }
1183: } // next (q)
1184:
1185: if (DebugFile.trace)
1186: DebugFile
1187: .writeln("PreparedStatement.executeUpdate()");
1188: cUpdated = oUpdt.executeUpdate();
1189:
1190: if (DebugFile.trace)
1191: DebugFile.writeln(String.valueOf(cUpdated)
1192: + " rows updated");
1193: } else {
1194: cUpdated = 0;
1195: if (DebugFile.trace)
1196: DebugFile
1197: .writeln("pk count="
1198: + String.valueOf(oMDat.cPKs)
1199: + " column count="
1200: + String
1201: .valueOf(oMDat.ColCount)
1202: + " row not updated because no non-pk columns found");
1203: }
1204: // fi (oMDat.cPKs>oMDat.ColCount)
1205:
1206: if (0 == cUpdated) {
1207: oInsrt = TrStatements[s];
1208: iPK = 0;
1209: // Iterador de parametros de entrada
1210: for (q = 0; q < iCols; q++) {
1211: sField = oMDat.ColNames[q];
1212: iSQLType = oMDat.ColTypes[q];
1213: oValue = getResult(r, q);
1214:
1215: if (oMDat.isPrimaryKey(q)) {
1216: if (iPK < cParams
1217: && oMDat.inheritsPK(TrMetaData[0])) {
1218: if (null != TrPK[iPK]) {
1219: if (oValue.getClass().equals(
1220: TrPK[iPK].getClass())
1221: && oMDat.bestMatch(q,
1222: TrMetaData[0], iPK)) {
1223: if (DebugFile.trace)
1224: DebugFile
1225: .writeln("swaping PK "
1226: + oValue
1227: .toString()
1228: + " to "
1229: + TrPK[iPK]
1230: .toString());
1231: oValue = TrPK[iPK];
1232: }
1233: }
1234: } // fi (iPK<cParams && oMDat.hasSamePK(TrMetaData[0]))
1235: iPK++;
1236: } // fi (oMDat.isPrimaryKey(q))
1237:
1238: if (DebugFile.trace)
1239: DebugFile.writeln("binding " + sField
1240: + " as SQLType "
1241: + String.valueOf(iSQLType));
1242:
1243: if (iSQLType == java.sql.Types.LONGVARCHAR) {
1244: sValue = oValue.toString() + " ";
1245: oReader = new StringReader(sValue);
1246: oInsrt.setCharacterStream(q + 1, oReader,
1247: sValue.length() - 1);
1248: } else
1249: oInsrt.setObject(q + 1, convert(oValue,
1250: iSQLType), mapType(iSQLType));
1251: } // end for (q)
1252:
1253: if (DebugFile.trace)
1254: DebugFile
1255: .writeln("PreparedStatement.execute()");
1256: oInsrt.execute();
1257: } // end if (cUpdated==0)
1258: } // end for (r)
1259:
1260: oResults.clear();
1261: oResults = null;
1262:
1263: execCommands("AFTER", s, OrPK, cParams);
1264: } // end for (s)
1265:
1266: execCommands("TERM", -1, OrPK, cParams);
1267:
1268: if (DebugFile.trace) {
1269: DebugFile.decIdent();
1270: DebugFile.writeln("End DataStruct.update()");
1271: }
1272: } // update
1273:
1274: // ----------------------------------------------------------
1275:
1276: protected void seekReferal(DataTransformation oTransform) {
1277: DataTransformation oTransformRef;
1278: HashMap oTransformsRef;
1279: Set oTransformSet;
1280: Iterator oSetIterator;
1281: String sChildTable;
1282: String sReferedTable = oTransform.ReferedTable;
1283:
1284: if (DebugFile.trace) {
1285: DebugFile
1286: .writeln("Begin DataStruct.seekReferal(ReferedTable="
1287: + sReferedTable
1288: + ", ReferedField="
1289: + oTransform.ReferedField + ")");
1290: DebugFile.incIdent();
1291: }
1292:
1293: for (int r = 0; r < DataRowSets.size(); r++) {
1294: // Si el nombre de la tabla de origen del RowSet explorado
1295: // coincide con el nombre de la tabla referencia, entonces
1296: // buscar el campo asociado.
1297: sChildTable = getRowSet(r).OriginTable;
1298:
1299: if (sChildTable.equalsIgnoreCase(sReferedTable)) {
1300: oTransformsRef = (HashMap) Transformations.get(r);
1301: // Recorrer la lista de valores
1302: oTransformSet = oTransformsRef.keySet();
1303: oSetIterator = oTransformSet.iterator();
1304: while (oSetIterator.hasNext()) {
1305: oTransformRef = (DataTransformation) oTransformsRef
1306: .get(oSetIterator.next());
1307: if (oTransformRef.OriginField
1308: .equalsIgnoreCase(oTransform.ReferedField)) {
1309: oTransform.setReferedValues(oTransformRef);
1310: if (DebugFile.trace)
1311: DebugFile.writeln(oTransform.OriginTable
1312: + " references "
1313: + oTransform.ReferedTable + "."
1314: + oTransform.ReferedField);
1315: } // fi (oTransformRef.OriginField == oTransform.ReferedField)
1316: } // wend()
1317: } // fi (DataRowSets[r].OriginTable == oTransform.ReferedTable)
1318: } // next (r)
1319:
1320: if (DebugFile.trace) {
1321: DebugFile.decIdent();
1322: DebugFile.writeln("End DataStruct.seekReferal()");
1323: }
1324: } // seekReferal
1325:
1326: // ==========================================================
1327:
1328: //
1329: // ContentHandler methods
1330: //
1331:
1332: /** Start document. */
1333: public void startDocument() throws SAXException {
1334:
1335: if (DebugFile.trace) {
1336: DebugFile.writeln("Begin DataStruct.startDocument()");
1337: DebugFile.incIdent();
1338: }
1339:
1340: fElements = 0;
1341: fCharacters = 0;
1342: sContext = "";
1343: sNode = "";
1344: oFromPKs = new HashMap(5, 3);
1345: oToPKs = new HashMap(5, 3);
1346:
1347: InitStmts = new LinkedList();
1348: TermStmts = new LinkedList();
1349:
1350: if (DebugFile.trace) {
1351: DebugFile.decIdent();
1352: DebugFile.writeln("End DataStruct.startDocument()");
1353: }
1354: } // startDocument()
1355:
1356: // ----------------------------------------------------------
1357:
1358: public void startElement(String uri, String local, String raw,
1359: Attributes attrs) throws SAXException {
1360: fElements++;
1361: sChars = "";
1362:
1363: if (local.equalsIgnoreCase("ROWSET")) {
1364: oCurrRowSet = new DataRowSet();
1365: DataRowSets.add(oCurrRowSet);
1366: cTables++;
1367:
1368: oCurrMap = new HashMap(13, 5);
1369: FieldMaps.add(oCurrMap);
1370:
1371: oCurrTransform = new HashMap(5, 3);
1372: Transformations.add(oCurrTransform);
1373:
1374: oCurrDef = new HashMap(13, 5);
1375: FieldDefs.add(oCurrDef);
1376:
1377: oCurrBef = new LinkedList();
1378: Before.add(oCurrBef);
1379:
1380: oCurrAft = new LinkedList();
1381: After.add(oCurrAft);
1382: } // fi (local.equalsIgnoreCase("ROWSET"))
1383:
1384: if (local.equalsIgnoreCase("ACTION")
1385: || local.equalsIgnoreCase("MAPPINGS")
1386: || local.equalsIgnoreCase("DEFVALS")
1387: || local.equalsIgnoreCase("NULLVALS")
1388: || local.equalsIgnoreCase("BEFORE")
1389: || local.equalsIgnoreCase("AFTER")
1390: || local.equalsIgnoreCase("INIT")
1391: || local.equalsIgnoreCase("TERM"))
1392: sNode = sContext = local.toUpperCase();
1393: else
1394: sNode = local.toUpperCase();
1395:
1396: if ((sNode.equals("MAPPING") && attrs.getLength() > 0)
1397: || (sNode.equals("DEFVAL") && attrs.getLength() > 0))
1398: sTransform = attrs.getValue(0);
1399: else
1400: sTransform = null;
1401:
1402: } // startElement(String,String,StringAttributes)
1403:
1404: // ----------------------------------------------------------
1405:
1406: public void endElement(String uri, String localName, String qname)
1407: throws SAXException {
1408: int iComma;
1409: String sOrFld;
1410: String sOrVal;
1411: String sTrFld;
1412: DataTransformation oTransform;
1413:
1414: if (sContext.equalsIgnoreCase("ACTION")) {
1415: if (sNode.equalsIgnoreCase("FROM"))
1416: oCurrRowSet.OriginTable = sChars.trim();
1417: else if (sNode.equalsIgnoreCase("TO"))
1418: oCurrRowSet.TargetTable = sChars.trim();
1419: else if (sNode.equalsIgnoreCase("JOIN"))
1420: oCurrRowSet.JoinTables = sChars;
1421: else if (sNode.equalsIgnoreCase("WHERE"))
1422: oCurrRowSet.WhereClause = sChars;
1423: else if (sNode.equalsIgnoreCase("ERASE"))
1424: oCurrRowSet.EraseClause = sChars;
1425: else if (sNode.equalsIgnoreCase("FIELDLIST"))
1426: oCurrRowSet.FieldList = sChars;
1427: else if (sNode.equalsIgnoreCase("FROM_PK"))
1428: oFromPKs.put(oCurrRowSet.OriginTable, sChars.trim());
1429: else if (sNode.equalsIgnoreCase("TO_PK"))
1430: oToPKs.put(oCurrRowSet.TargetTable, sChars.trim());
1431: } // end if (sContext=="ACTION")
1432: else if (sContext.equalsIgnoreCase("MAPPINGS")) {
1433: if (sNode.equalsIgnoreCase("MAPPING")) {
1434: iComma = sChars.lastIndexOf(",");
1435: sOrFld = sChars.substring(0, iComma).trim();
1436: sTrFld = sChars.substring(iComma + 1).trim();
1437: oCurrMap.put(sTrFld, sOrFld);
1438:
1439: // Si el elemento <MAPPING> contiene un atributo llamado TRANSFORM
1440: // entonces crear un nuevo objeto de transformación de datos para este mapeo
1441: if (null != sTransform) {
1442: // Crear un nuevo servicio de transformación de datos para el campo
1443: oTransform = new DataTransformation(sTransform,
1444: oCurrRowSet.OriginTable, sOrFld,
1445: oCurrRowSet.TargetTable, sTrFld);
1446:
1447: // Asociar el nombre del campo con su transformación de datos
1448: oCurrTransform.put(sOrFld, oTransform);
1449:
1450: // Si la transformacion es de tipo REFER,
1451: // buscar el mapa de valores para la tabla referenciada
1452: if (oTransform.OperationCode == DataTransformation.Operations.REFER)
1453: seekReferal(/* inout */oTransform);
1454: } // end if (null!=sTransform)
1455: } // end if (sNode=="MAPPING")
1456: } // end if (sContext=="MAPPINGS")
1457: else if (sContext.equalsIgnoreCase("DEFVALS")) {
1458: if (sNode.equalsIgnoreCase("DEFVAL")) {
1459: iComma = sChars.indexOf(",");
1460: sTrFld = sChars.substring(0, iComma).trim();
1461: sOrFld = sChars.substring(iComma + 1).trim();
1462: oCurrDef.put(sTrFld, sOrFld);
1463: // Crear un nuevo servicio de transformación de datos para el campo por defecto
1464: if (null != sTransform) {
1465: oTransform = new DataTransformation(sTransform,
1466: oCurrRowSet.OriginTable, sTrFld,
1467: oCurrRowSet.TargetTable, sTrFld);
1468: // Asociar el nombre del campo con su transformación de datos
1469: oCurrTransform.put(sTrFld, oTransform);
1470: // Si la transformacion es de tipo REFER,
1471: // buscar el mapa de valores para la tabla referenciada
1472: if (oTransform.OperationCode == DataTransformation.Operations.REFER)
1473: seekReferal(/* inout */oTransform);
1474: } // end if (null!=sTransform)
1475: } // end if (sNode=="DEFVAL")
1476: } // end if (sContext=="DEFVALS")
1477: else if (sContext.equalsIgnoreCase("BEFORE")) {
1478: if (localName.equalsIgnoreCase("EXEC")
1479: || localName.equalsIgnoreCase("CALL"))
1480: oCurrBef.addLast(sChars);
1481: } // end if (sContext=="BEFORE")
1482: else if (sContext.equalsIgnoreCase("AFTER")) {
1483: if (localName.equalsIgnoreCase("EXEC")
1484: || localName.equalsIgnoreCase("CALL"))
1485: oCurrAft.addLast(sChars);
1486: } // end if (sContext=="AFTER")
1487: else if (sContext.equalsIgnoreCase("INIT")) {
1488: if (localName.equalsIgnoreCase("EXEC")
1489: || localName.equalsIgnoreCase("CALL"))
1490: InitStmts.addLast(sChars);
1491: } // end if (sContext=="INIT")
1492: else if (sContext.equalsIgnoreCase("TERM")) {
1493: if (localName.equalsIgnoreCase("EXEC")
1494: || localName.equalsIgnoreCase("CALL"))
1495: TermStmts.addLast(sChars);
1496: } // end if (sContext=="TERM")
1497: } // endElement()
1498:
1499: // ----------------------------------------------------------
1500:
1501: /** Characters. */
1502: public void characters(char ch[], int start, int length)
1503: throws SAXException {
1504: fCharacters += length;
1505: sChars += new String(ch, start, length);
1506: } // characters(char[],int,int);
1507:
1508: // ----------------------------------------------------------
1509:
1510: //
1511: // ErrorHandler methods
1512: //
1513:
1514: /** Warning. */
1515: public void warning(SAXParseException ex) throws SAXException {
1516: if (DebugFile.trace)
1517: DebugFile.write(composeError("Warning", ex));
1518: } // warning(SAXParseException)
1519:
1520: /** Error. */
1521: public void error(SAXParseException ex) throws SAXException {
1522: if (DebugFile.trace)
1523: DebugFile.write(composeError("Error", ex));
1524: throw ex;
1525: } // error(SAXParseException)
1526:
1527: /** Fatal error. */
1528: public void fatalError(SAXParseException ex) throws SAXException {
1529: if (DebugFile.trace)
1530: DebugFile.write(composeError("Fatal Error", ex));
1531: throw ex;
1532: } // fatalError(SAXParseException)
1533:
1534: // ----------------------------------------------------------
1535:
1536: //
1537: // Protected methods
1538: //
1539:
1540: /** Compose the error message. */
1541: protected String composeError(String type, SAXParseException ex) {
1542: String sErrDesc = "";
1543: String systemId = null;
1544: int index;
1545:
1546: sErrDesc += "[SAX " + type + "] ";
1547:
1548: if (ex == null)
1549: sErrDesc += "!!!";
1550: else
1551: systemId = ex.getSystemId();
1552:
1553: if (systemId != null) {
1554: index = systemId.lastIndexOf('/');
1555: if (index != -1)
1556: systemId = systemId.substring(index + 1);
1557: sErrDesc += systemId;
1558: }
1559:
1560: sErrDesc += " Line:" + ex.getLineNumber();
1561: sErrDesc += " Column:" + ex.getColumnNumber();
1562: sErrDesc += " Cause: " + ex.getMessage();
1563: sErrDesc += "\n";
1564:
1565: return sErrDesc;
1566: } // composeError(String,SAXParseException)
1567:
1568: // ----------------------------------------------------------
1569:
1570: //
1571: // Public methods
1572: //
1573:
1574: public void parse(String sXMLFile) throws InstantiationException,
1575: IllegalAccessException, ClassNotFoundException,
1576: IOException, SAXException {
1577: Properties oProps = new Properties();
1578: parse(sXMLFile, oProps);
1579: }
1580:
1581: public void parse(String sXMLFile, Properties oProps)
1582: throws InstantiationException, IllegalAccessException,
1583: ClassNotFoundException, IOException, SAXException {
1584: // This method parses an XML document into a DataStruct instace
1585:
1586: // local variables
1587: XMLReader parser;
1588: Parser sax1Parser;
1589: File oFile;
1590: FileReader oFileRead;
1591: BufferedReader oBuff;
1592: StringBufferInputStream oStrBuff;
1593: InputSource ioSrc;
1594: FileInputStream oStream;
1595: String sXMLSource;
1596: String sParam;
1597: Enumeration oEnum;
1598: Pattern oPattern;
1599: PatternMatcher oMatcher = new Perl5Matcher();
1600: PatternCompiler oCompiler = new Perl5Compiler();
1601: byte byBuffer[];
1602:
1603: if (DebugFile.trace) {
1604: DebugFile.writeln("Begin DataStruct.parse(" + sXMLFile
1605: + ")");
1606: DebugFile.incIdent();
1607: }
1608:
1609: try {
1610: if (DebugFile.trace)
1611: DebugFile.writeln("XMLReaderFactory.createXMLReader("
1612: + DEFAULT_PARSER_NAME + ")");
1613:
1614: parser = XMLReaderFactory
1615: .createXMLReader(DEFAULT_PARSER_NAME);
1616: } catch (Exception e) {
1617: if (DebugFile.trace)
1618: DebugFile.writeln("ParserFactory.makeParser("
1619: + DEFAULT_PARSER_NAME + ")");
1620:
1621: sax1Parser = ParserFactory.makeParser(DEFAULT_PARSER_NAME);
1622:
1623: parser = new ParserAdapter(sax1Parser);
1624: if (DebugFile.trace)
1625: DebugFile
1626: .writeln("warning: Features and properties not supported on SAX1 parsers.");
1627: }
1628: try {
1629: parser
1630: .setFeature(NAMESPACES_FEATURE_ID,
1631: DEFAULT_NAMESPACES);
1632: parser
1633: .setFeature(VALIDATION_FEATURE_ID,
1634: DEFAULT_VALIDATION);
1635: } catch (SAXException e) {
1636: }
1637:
1638: // parse file
1639: parser.setContentHandler(this );
1640: parser.setErrorHandler(this );
1641:
1642: oEnum = oProps.keys();
1643: if (sXMLFile.startsWith("<?xml")) {
1644: // replace input parameters
1645: while (oEnum.hasMoreElements()) {
1646: sParam = (String) oEnum.nextElement();
1647: try {
1648: oPattern = oCompiler.compile("{#" + sParam + "}");
1649: } catch (MalformedPatternException e) {
1650: oPattern = null;
1651: }
1652:
1653: sXMLFile = Util.substitute(oMatcher, oPattern,
1654: new Perl5Substitution(oProps
1655: .getProperty(sParam),
1656: Perl5Substitution.INTERPOLATE_ALL),
1657: sXMLFile, Util.SUBSTITUTE_ALL);
1658: } // wend()
1659:
1660: oStrBuff = new StringBufferInputStream(sXMLFile);
1661: ioSrc = new InputSource(oStrBuff);
1662: parser.parse(ioSrc);
1663: oStrBuff.close();
1664: } else {
1665: if (oProps.isEmpty()) {
1666: oFileRead = new FileReader(sXMLFile);
1667: oBuff = new BufferedReader(oFileRead, 32767);
1668: ioSrc = new InputSource(oBuff);
1669: parser.parse(ioSrc);
1670: oBuff.close();
1671: oFileRead.close();
1672: } else {
1673: oFile = new File(sXMLFile);
1674: byBuffer = new byte[new Long(oFile.length()).intValue()];
1675:
1676: oStream = new FileInputStream(oFile);
1677: oStream.read(byBuffer);
1678: sXMLSource = new String(byBuffer);
1679: oStream.close();
1680:
1681: while (oEnum.hasMoreElements()) {
1682: sParam = (String) oEnum.nextElement();
1683: try {
1684: oPattern = oCompiler.compile("{#" + sParam
1685: + "}");
1686: } catch (MalformedPatternException e) {
1687: oPattern = null;
1688: }
1689:
1690: sXMLSource = Util.substitute(oMatcher, oPattern,
1691: new Perl5Substitution(oProps
1692: .getProperty(sParam),
1693: Perl5Substitution.INTERPOLATE_ALL),
1694: sXMLSource, Util.SUBSTITUTE_ALL);
1695: } // wend()
1696:
1697: oStrBuff = new StringBufferInputStream(sXMLSource);
1698: ioSrc = new InputSource(oStrBuff);
1699: parser.parse(ioSrc);
1700: oStrBuff.close();
1701: }
1702: }
1703:
1704: if (DebugFile.trace) {
1705: DebugFile.decIdent();
1706: DebugFile.writeln("End DataStruct.parse()");
1707: }
1708: } // parse()
1709:
1710: // ----------------------------------------------------------
1711:
1712: public void createClassSource(String sPackage,
1713: String sSubClassName, String sFile) throws IOException {
1714: FileWriter oFile = new FileWriter(sFile);
1715: DataTransformation oDatT;
1716: Iterator oIter;
1717: LinkedList oList;
1718: Object oPKs;
1719: String sItem;
1720:
1721: oFile.write("package " + sPackage + ";\n");
1722: oFile.write("import java.util.Vector;\n");
1723: oFile.write("import java.util.LinkedList;\n");
1724: oFile.write("import java.util.ListIterator;\n");
1725: oFile.write("import java.util.HashMap;\n");
1726: oFile.write("import java.util.Iterator;\n");
1727: oFile.write("import com.knowgate.datacopy.DataRowSet;\n");
1728: oFile.write("import com.knowgate.datacopy.DataStruct;\n");
1729: oFile
1730: .write("import com.knowgate.datacopy.DataTransformation;\n");
1731: oFile.write("\n");
1732:
1733: oFile.write("public class " + sSubClassName
1734: + " extends DataStruct {\n");
1735: oFile.write(" public " + sSubClassName + "() {\n");
1736: oFile.write(" DataRowSet oRowSet;\n");
1737: oFile.write(" DataTransformation oTransForm;\n");
1738: oFile.write(" LinkedList oBefore;\n");
1739: oFile.write(" LinkedList oAfter;\n");
1740: oFile.write(" HashMap oMappings;\n");
1741: oFile.write(" HashMap oDefaults;\n");
1742: oFile.write(" HashMap oTransforms;\n\n");
1743: oFile.write(" InitStmts = new LinkedList();\n");
1744: oFile.write(" TermStmts = new LinkedList();\n");
1745: oFile.write(" oToPKs = new HashMap();\n");
1746: oFile.write(" oFromPKs = new HashMap();\n");
1747: oFile.write(" cTables = "
1748: + String.valueOf(DataRowSets.size()) + ";\n");
1749: oFile.write("\n");
1750:
1751: oIter = InitStmts.listIterator();
1752: while (oIter.hasNext())
1753: oFile.write(" InitStmts.addLast(\""
1754: + oIter.next().toString() + "\");\n");
1755: oFile.write("\n");
1756:
1757: oIter = TermStmts.listIterator();
1758: while (oIter.hasNext())
1759: oFile.write(" TermStmts.addLast(\""
1760: + oIter.next().toString() + "\");\n");
1761: oFile.write("\n");
1762:
1763: for (int c = 0; c < cTables; c++) {
1764: oCurrRowSet = getRowSet(c);
1765:
1766: oFile.write(" oRowSet = new DataRowSet(\""
1767: + oCurrRowSet.OriginTable + "\",\""
1768: + oCurrRowSet.TargetTable + "\",\""
1769: + oCurrRowSet.JoinTables + "\",\""
1770: + oCurrRowSet.WhereClause + "\",\""
1771: + oCurrRowSet.EraseClause + "\");\n");
1772: oFile.write(" oRowSet.FieldList = \""
1773: + oCurrRowSet.FieldList.trim() + "\";\n");
1774: oFile.write(" DataRowSets.add(oRowSet);\n");
1775: oFile.write(" oBefore = new LinkedList();\n");
1776: oFile.write(" oAfter = new LinkedList();\n");
1777: oFile.write(" oMappings = new HashMap();\n");
1778: oFile.write(" oDefaults = new HashMap();\n");
1779: oFile.write(" oTransforms = new HashMap();\n");
1780:
1781: oPKs = oFromPKs.get(oCurrRowSet.OriginTable);
1782: if (null != oPKs)
1783: oFile.write(" oFromPKs.put(\""
1784: + oCurrRowSet.OriginTable + "\",\""
1785: + oPKs.toString() + "\");\n");
1786: oPKs = oToPKs.get(oCurrRowSet.TargetTable);
1787: if (null != oPKs)
1788: oFile.write(" oToPKs.put(\""
1789: + oCurrRowSet.TargetTable + "\",\""
1790: + oPKs.toString() + "\");\n\n");
1791:
1792: oList = (LinkedList) Before.get(c);
1793: if (oList.size() > 0) {
1794: oIter = oList.iterator();
1795: while (oIter.hasNext())
1796: oFile.write(" oBefore.addLast(\""
1797: + oIter.next().toString() + "\");\n");
1798: oIter = null;
1799: } // fi (oList.size()>0)
1800: oList = null;
1801: oFile.write(" Before.add(oBefore);\n");
1802:
1803: oList = (LinkedList) After.get(c);
1804: if (oList.size() > 0) {
1805: oIter = oList.iterator();
1806: while (oIter.hasNext())
1807: oFile.write(" oAfter.addLast(\""
1808: + oIter.next().toString() + "\");\n");
1809: oIter = null;
1810: } // fi (oList.size()>0)
1811: oList = null;
1812: oFile.write(" After.add(oAfter);\n");
1813:
1814: try {
1815: oCurrMap = (HashMap) FieldMaps.get(c);
1816: oIter = oCurrMap.keySet().iterator();
1817: while (oIter.hasNext()) {
1818: sItem = (String) oIter.next();
1819: oFile.write(" oMappings.put(\"" + sItem
1820: + "\",\"" + oCurrMap.get(sItem).toString()
1821: + "\");\n");
1822: } // wend
1823: } catch (ArrayIndexOutOfBoundsException e) {
1824: }
1825:
1826: oFile.write(" FieldMaps.add(oMappings);\n");
1827:
1828: try {
1829: oFile.write(" Transformations.add(oTransforms);\n");
1830: oCurrTransform = (HashMap) Transformations.get(c);
1831: oIter = oCurrTransform.keySet().iterator();
1832: while (oIter.hasNext()) {
1833: sItem = oIter.next().toString();
1834: oDatT = (DataTransformation) oCurrTransform
1835: .get(sItem);
1836: oFile
1837: .write(" oTransForm = new DataTransformation("
1838: + String
1839: .valueOf(oDatT.OperationCode)
1840: + ","
1841: + "\""
1842: + oDatT.OriginTable
1843: + "\",\""
1844: + oDatT.OriginField
1845: + "\","
1846: + "\""
1847: + oDatT.TargetTable
1848: + "\",\""
1849: + oDatT.TargetField
1850: + "\","
1851: + (null == oDatT.ReferedTable ? "null"
1852: : "\"" + oDatT.ReferedTable
1853: + "\"")
1854: + ","
1855: + (null == oDatT.ReferedField ? "null"
1856: : "\"" + oDatT.ReferedField
1857: + "\"")
1858: + ","
1859: + (null == oDatT.IfNullValue ? "null"
1860: : "\"" + oDatT.IfNullValue
1861: + "\"") + ");\n");
1862: oFile.write(" oTransforms.put(\"" + sItem
1863: + "\", oTransForm);\n");
1864: if (oDatT.OperationCode == DataTransformation.Operations.REFER)
1865: oFile.write(" seekReferal(oTransForm);\n");
1866: } // wend
1867: } catch (ArrayIndexOutOfBoundsException e) {
1868: }
1869:
1870: try {
1871: oCurrDef = (HashMap) FieldDefs.get(c);
1872: oIter = oCurrDef.keySet().iterator();
1873: while (oIter.hasNext()) {
1874: sItem = (String) oIter.next();
1875: oFile.write(" oMappings.put(\"" + sItem
1876: + "\",\"" + oCurrDef.get(sItem).toString()
1877: + "\");\n");
1878: } // wend
1879: } catch (ArrayIndexOutOfBoundsException e) {
1880: }
1881:
1882: oFile.write(" FieldDefs.add(oDefaults);\n");
1883:
1884: oFile.write("\n");
1885: } // end for (c)
1886:
1887: oFile.write(" }\n}");
1888:
1889: oFile.close();
1890: oFile = null;
1891: } // createClassSource ()
1892:
1893: // ----------------------------------------------------------
1894:
1895: private boolean bOrPrepared; // Switch que indica si están preparados los cursores en Origen
1896: private boolean bTrPrepared; // Switch que indica si están preparados los cursores en Destino
1897: private Connection oOrConn; // Conexión de Origen
1898: private Connection oTrConn; // Conexión de Destino
1899: private int iOrStatus; // Estado de la Conexión de Origen {CONNECTED|DISCONNECTED|REFERENCED}
1900: private int iTrStatus; // Estado de la Conexión de Destino {CONNECTED|DISCONNECTED|REFERENCED}
1901:
1902: protected Vector oResults; // ResultSet de lectura de registros del Origen
1903: protected int iCols; // Variable intermedia para pasar estado del método getRows() a insert() y update()
1904: protected int iRows; // Variable intermedia para pasar estado del método getRows() a insert()
1905:
1906: // ---------------------------------------------------------
1907: // Estructuras de datos cargadas al llamar al método parse()
1908:
1909: protected int cTables; // Cuenta de tablas en el conjunto de RowSets
1910: protected Vector FieldMaps; // Vector de HashMaps con los mapeos de campos para cada tabla
1911: protected Vector FieldDefs; // Vector de HashMaps con los valores por defecto para cada tabla
1912: protected Vector DataRowSets; // Vector de objetos DataRowSet (uno por tabla)
1913: protected Vector Before; // Vector de Acciones BEFORE para cada tabla
1914: protected Vector After; // Vector de Acciones AFTER para cada tabla
1915: protected LinkedList InitStmts; // Vector de Acciones Inicializacion
1916: protected LinkedList TermStmts; // Vector de Acciones Terminacion
1917: protected Vector Transformations; // Vector con las transformaciones de valores de campos
1918: protected HashMap oFromPKs;
1919: protected HashMap oToPKs;
1920:
1921: // ---------------------------------------------------------------------
1922: // Estructuras de datos cargadas al llamar al método prepareStatements()
1923:
1924: protected PreparedStatement OrStatements[]; // Cursores de lectura en origen
1925: protected PreparedStatement TrStatements[]; // Cursores de inserción en destino
1926: protected PreparedStatement UpStatements[]; // Cursores de actualización en destino
1927: protected PreparedStatement DlStatements[]; // Cursores de borrado en destino
1928: protected DataTblDef OrMetaData[]; // Definición de metadatos en origen
1929: protected DataTblDef TrMetaData[]; // Definición de metadatos en destino
1930: public HashMap oInsertTexts;
1931: public HashMap oSelectTexts;
1932:
1933: // ---------------------------------------------------------
1934: // Variables temporales para el procesamiento de eventos SAX
1935:
1936: private String sChars; // Buffer de lectura de caracteres para SAX
1937: private long fElements;
1938: private long fCharacters;
1939: private String sTransform;
1940: private String sContext;
1941: private String sNode;
1942: private DataRowSet oCurrRowSet;
1943: private HashMap oCurrMap;
1944: private HashMap oCurrDef;
1945: private HashMap oCurrTransform;
1946: private LinkedList oCurrBef;
1947: private LinkedList oCurrAft;
1948:
1949: private static final int DISCONNECTED = 0;
1950: private static final int CONNECTED = 1;
1951: private static final int REFERENCED = 2;
1952:
1953: // feature ids
1954:
1955: protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces";
1956: protected static final String NAMESPACE_PREFIXES_FEATURE_ID = "http://xml.org/sax/features/namespace-prefixes";
1957: protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation";
1958: protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema";
1959: protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking";
1960: protected static final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic";
1961:
1962: // default settings
1963:
1964: protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
1965: protected static final int DEFAULT_REPETITION = 1;
1966: protected static final boolean DEFAULT_NAMESPACES = true;
1967: protected static final boolean DEFAULT_NAMESPACE_PREFIXES = false;
1968: protected static final boolean DEFAULT_VALIDATION = false;
1969: protected static final boolean DEFAULT_SCHEMA_VALIDATION = false;
1970: protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false;
1971: protected static final boolean DEFAULT_DYNAMIC_VALIDATION = false;
1972: protected static final boolean DEFAULT_MEMORY_USAGE = false;
1973: protected static final boolean DEFAULT_TAGGINESS = false;
1974: }
|