0001: /**
0002: Copyright (C) 2002-2003 Together
0003:
0004: This library is free software; you can redistribute it and/or
0005: modify it under the terms of the GNU Lesser General Public
0006: License as published by the Free Software Foundation; either
0007: version 2.1 of the License, or (at your option) any later version.
0008:
0009: This library is distributed in the hope that it will be useful,
0010: but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012: Lesser General Public License for more details.
0013:
0014: You should have received a copy of the GNU Lesser General Public
0015: License along with this library; if not, write to the Free Software
0016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017:
0018: */package org.webdocwf.util.i18njdbc;
0019:
0020: import java.io.File;
0021: import java.io.FileInputStream;
0022: import java.io.InputStream;
0023: import java.io.Reader;
0024: import java.math.BigDecimal;
0025: import java.net.URL;
0026: import java.sql.Array;
0027: import java.sql.Blob;
0028: import java.sql.Clob;
0029: import java.sql.Connection;
0030: import java.sql.Date;
0031: import java.sql.DriverManager;
0032: import java.sql.NClob;
0033: import java.sql.ParameterMetaData;
0034: import java.sql.PreparedStatement;
0035: import java.sql.Ref;
0036: import java.sql.ResultSet;
0037: import java.sql.ResultSetMetaData;
0038: import java.sql.RowId;
0039: import java.sql.SQLException;
0040: import java.sql.SQLWarning;
0041: import java.sql.SQLXML;
0042: import java.sql.Time;
0043: import java.sql.Timestamp;
0044: import java.util.ArrayList;
0045: import java.util.Calendar;
0046: import java.util.Enumeration;
0047: import java.util.Vector;
0048:
0049: /**
0050: * This class implements the PreparedStatement interface for the I18nJdbc driver.
0051: *
0052: * @author Zoran Milakovic
0053: * @author Zeljko Kovacevic
0054: */
0055: public class I18nPreparedStatement implements PreparedStatement {
0056:
0057: private I18nConnection connection;
0058: private Vector resultSets = new Vector();
0059: private String sqlForPrepare = "";
0060: private String sqlPrepared = "";
0061: private int paramCount = 0;
0062: private ArrayList parameters = new ArrayList();
0063: private ArrayList binaryStreamParameters = new ArrayList();
0064: /** Name used for prepared statement parameters */
0065: public static String PREPARE_SEPARATOR = "~@#NEXTPARAMETER#@~";
0066: private String sql;
0067:
0068: public I18nPreparedStatement(I18nConnection connection,
0069: String preparedSql) {
0070: DriverManager
0071: .println("I18nJdbc - I18nStatement() - connection="
0072: + connection);
0073: this .sqlForPrepare = preparedSql;
0074: this .sqlPrepared = preparedSql;
0075: this .paramCount = countParameters(preparedSql);
0076: for (int i = 0; i < paramCount; i++)
0077: parameters.add(null);
0078: this .connection = connection;
0079: }
0080:
0081: private int countParameters(String sql) {
0082: int count = 0;
0083: int index = sql.indexOf(PREPARE_SEPARATOR);
0084: while (index != -1) {
0085: count++;
0086: sql = sql.substring(index + 1);
0087: index = sql.indexOf(PREPARE_SEPARATOR);
0088: }
0089: return count;
0090: }
0091:
0092: private boolean prepareSql() throws SQLException {
0093: boolean retVal = true;
0094: for (int i = 0; i < parameters.size(); i++) {
0095: int index = sqlPrepared.indexOf(PREPARE_SEPARATOR);
0096: String val;
0097: if (index != -1) {
0098: if (parameters.get(i) == null)
0099: val = "null";
0100: else
0101: val = parameters.get(i).toString();
0102: sqlPrepared = sqlPrepared.substring(0, index)
0103: + val
0104: + sqlPrepared.substring(index
0105: + PREPARE_SEPARATOR.length());
0106: }
0107: }
0108: if (sqlPrepared.indexOf(PREPARE_SEPARATOR) != -1)
0109: throw new SQLException(
0110: "All ? in prepared query has to be replaced with values.");
0111: else if (parameters.size() < this .paramCount)
0112: throw new SQLException(
0113: "Number of setted parameters is less than number of parameters in statement.");
0114: else if (parameters.size() > this .paramCount)
0115: throw new SQLException(
0116: "Number of setted parameters is greater than number of parameters in statement.");
0117: return retVal;
0118: }
0119:
0120: /**
0121: *Sets the maxFieldSize attribute of the I18nStatement object
0122: *
0123: * @param p0 The new maxFieldSize value
0124: * @exception SQLException Description of Exception
0125: * @since
0126: */
0127: public void setMaxFieldSize(int p0) throws SQLException {
0128: throw new SQLException("Not Supported !");
0129: }
0130:
0131: /**
0132: *Sets the maxRows attribute of the I18nStatement object
0133: *
0134: * @param p0 The new maxRows value
0135: * @exception SQLException Description of Exception
0136: * @since
0137: */
0138: public void setMaxRows(int p0) throws SQLException {
0139: throw new SQLException("Not Supported !");
0140: }
0141:
0142: /**
0143: *Sets the escapeProcessing attribute of the I18nStatement object
0144: *
0145: * @param p0 The new escapeProcessing value
0146: * @exception SQLException Description of Exception
0147: * @since
0148: */
0149: public void setEscapeProcessing(boolean p0) throws SQLException {
0150: throw new SQLException("Not Supported !");
0151: }
0152:
0153: /**
0154: *Sets the queryTimeout attribute of the I18nStatement object
0155: *
0156: * @param p0 The new queryTimeout value
0157: * @exception SQLException Description of Exception
0158: * @since
0159: */
0160: public void setQueryTimeout(int p0) throws SQLException {
0161: throw new SQLException("Not Supported !");
0162: }
0163:
0164: /**
0165: *Sets the cursorName attribute of the I18nStatement object
0166: *
0167: * @param p0 The new cursorName value
0168: * @exception SQLException Description of Exception
0169: * @since
0170: */
0171: public void setCursorName(String p0) throws SQLException {
0172: throw new SQLException("Not Supported !");
0173: }
0174:
0175: /**
0176: *Sets the fetchDirection attribute of the I18nStatement object
0177: *
0178: * @param p0 The new fetchDirection value
0179: * @exception SQLException Description of Exception
0180: * @since
0181: */
0182: public void setFetchDirection(int p0) throws SQLException {
0183: throw new SQLException("Not Supported !");
0184: }
0185:
0186: /**
0187: *Sets the fetchSize attribute of the I18nStatement object
0188: *
0189: * @param p0 The new fetchSize value
0190: * @exception SQLException Description of Exception
0191: * @since
0192: */
0193: public void setFetchSize(int p0) throws SQLException {
0194: throw new SQLException("Not Supported !");
0195: }
0196:
0197: /**
0198: *Gets the maxFieldSize attribute of the I18nStatement object
0199: *
0200: * @return The maxFieldSize value
0201: * @exception SQLException Description of Exception
0202: * @since
0203: */
0204: public int getMaxFieldSize() throws SQLException {
0205: throw new SQLException("Not Supported !");
0206: }
0207:
0208: /**
0209: *Gets the maxRows attribute of the I18nStatement object
0210: *
0211: * @return The maxRows value
0212: * @exception SQLException Description of Exception
0213: * @since
0214: */
0215: public int getMaxRows() throws SQLException {
0216: throw new SQLException("Not Supported !");
0217: }
0218:
0219: /**
0220: *Gets the queryTimeout attribute of the I18nStatement object
0221: *
0222: * @return The queryTimeout value
0223: * @exception SQLException Description of Exception
0224: * @since
0225: */
0226: public int getQueryTimeout() throws SQLException {
0227: throw new SQLException("Not Supported !");
0228: }
0229:
0230: /**
0231: *Gets the warnings attribute of the I18nStatement object
0232: *
0233: * @return The warnings value
0234: * @exception SQLException Description of Exception
0235: * @since
0236: */
0237: public SQLWarning getWarnings() throws SQLException {
0238: throw new SQLException("Not Supported !");
0239: }
0240:
0241: /**
0242: *Gets the resultSet attribute of the I18nStatement object
0243: *
0244: * @return The resultSet value
0245: * @exception SQLException Description of Exception
0246: * @since
0247: */
0248: public ResultSet getResultSet() throws SQLException {
0249: throw new SQLException("Not Supported !");
0250: }
0251:
0252: /**
0253: *Gets the updateCount attribute of the I18nStatement object
0254: *
0255: * @return The updateCount value
0256: * @exception SQLException Description of Exception
0257: * @since
0258: */
0259: public int getUpdateCount() throws SQLException {
0260: throw new SQLException("Not Supported !");
0261: }
0262:
0263: /**
0264: *Gets the moreResults attribute of the I18nStatement object
0265: *
0266: * @return The moreResults value
0267: * @exception SQLException Description of Exception
0268: * @since
0269: */
0270: public boolean getMoreResults() throws SQLException {
0271: throw new SQLException("Not Supported !");
0272: }
0273:
0274: /**
0275: *Gets the fetchDirection attribute of the I18nStatement object
0276: *
0277: * @return The fetchDirection value
0278: * @exception SQLException Description of Exception
0279: * @since
0280: */
0281: public int getFetchDirection() throws SQLException {
0282: throw new SQLException("Not Supported !");
0283: }
0284:
0285: /**
0286: *Gets the fetchSize attribute of the I18nStatement object
0287: *
0288: * @return The fetchSize value
0289: * @exception SQLException Description of Exception
0290: * @since
0291: */
0292: public int getFetchSize() throws SQLException {
0293: throw new SQLException("Not Supported !");
0294: }
0295:
0296: /**
0297: *Gets the resultSetConcurrency attribute of the I18nStatement object
0298: *
0299: * @return The resultSetConcurrency value
0300: * @exception SQLException Description of Exception
0301: * @since
0302: */
0303: public int getResultSetConcurrency() throws SQLException {
0304: throw new SQLException("Not Supported !");
0305: }
0306:
0307: /**
0308: *Gets the resultSetType attribute of the I18nStatement object
0309: *
0310: * @return The resultSetType value
0311: * @exception SQLException Description of Exception
0312: * @since
0313: */
0314: public int getResultSetType() throws SQLException {
0315: throw new SQLException("Not Supported !");
0316: }
0317:
0318: /**
0319: *Gets the connection attribute of the I18nStatement object
0320: *
0321: * @return The connection value
0322: * @exception SQLException Description of Exception
0323: * @since
0324: */
0325: public Connection getConnection() throws SQLException {
0326: return connection;
0327: }
0328:
0329: /**
0330: *Description of the Method
0331: *
0332: * @param sql Description of Parameter
0333: * @return Description of the Returned Value
0334: * @exception SQLException Description of Exception
0335: * @since
0336: */
0337: public ResultSet executeQuery(String sql) throws SQLException {
0338: DriverManager
0339: .println("I18nJdbc - I18nStatement:executeQuery() - sql= "
0340: + sql);
0341: I18nSqlParser parser = new I18nSqlParser();
0342: this .sql = sql;
0343: try {
0344: parser.parse(this );
0345: } catch (Exception e) {
0346: throw new SQLException("Syntax Error. " + e.getMessage());
0347: }
0348:
0349: String fileName = connection.getPath() + parser.getTableName()
0350: + connection.getExtension();
0351: File checkFile = new File(fileName);
0352: if (!checkFile.exists()) {
0353: throw new SQLException("Cannot open data file '" + fileName
0354: + "' !");
0355: }
0356:
0357: if (!checkFile.canRead()) {
0358: throw new SQLException("Data file '" + fileName
0359: + "' not readable !");
0360: }
0361:
0362: try {
0363:
0364: String[] xxx = parser.getColumnNames();
0365: String[] yyy = connection.getColumnNames();
0366: boolean isOK = true;
0367: for (int i = 0; i < xxx.length; i++) {
0368: if (!xxx[i].endsWith("*")) {
0369: out: for (int j = 0; j < yyy.length; j++) {
0370: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0371: isOK = true;
0372: break out;
0373: } else
0374: isOK = false;
0375: }
0376: if (!isOK)
0377: throw new SQLException("Column '" + xxx[i]
0378: + "' not found.");
0379: }
0380: }
0381: } catch (Exception e) {
0382: if (I18nDriver.DEBUG)
0383: e.printStackTrace();
0384: throw new SQLException(
0385: "Error reading data file. Message was: " + e);
0386: }
0387:
0388: this .connection.setCurrentTableName(parser.getTableName());
0389:
0390: //load properties file
0391: try {
0392: if (connection.getAutoCommit()) {
0393: connection.getProperties().load(
0394: new FileInputStream(checkFile));
0395: }
0396: } catch (Exception e) {
0397: throw new SQLException("Error while loading properties");
0398: }
0399:
0400: I18nResultSet resultSet = new I18nResultSet(this , parser
0401: .getTableName(), parser.getColumnNames(), parser
0402: .getWhereColumnNames(), parser.getWhereColumnValues());
0403: resultSets.add(resultSet);
0404: return resultSet;
0405: }
0406:
0407: /**
0408: *Description of the Method
0409: *
0410: * @param sql Description of Parameter
0411: * @return Description of the Returned Value
0412: * @exception SQLException Description of Exception
0413: * @since
0414: */
0415: public int executeUpdate(String sql) throws SQLException {
0416: int updated = 0;
0417: DriverManager
0418: .println("I18nJdbc - I18nStatement:executeUpdate() - sql= "
0419: + sql);
0420: I18nSqlParser parser = new I18nSqlParser();
0421: this .sql = sql;
0422: try {
0423: parser.parse(this );
0424: } catch (Exception e) {
0425: throw new SQLException("Syntax Error. " + e.getMessage());
0426: }
0427: if (parser.sqlType.equals(I18nSqlParser.SELECT))
0428: throw new SQLException(
0429: "Not supported SELECT statement - use executeQuery method");
0430: else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
0431: throw new SQLException(
0432: "Not supported CREATE TABLE statement - use execute method");
0433: } else if (parser.sqlType.equals(I18nSqlParser.INSERT)) {
0434: String fileName = connection.getPath()
0435: + parser.getTableName() + connection.getExtension();
0436: File checkFile = new File(fileName);
0437:
0438: if (!checkFile.exists()) {
0439: throw new SQLException("Cannot open data file '"
0440: + fileName + "' !");
0441: }
0442:
0443: if (!checkFile.canWrite()) {
0444: throw new SQLException("Data file '" + fileName
0445: + "' is read only !");
0446: }
0447: try {
0448: String[] xxx = parser.getColumnNames();
0449: String[] yyy = connection.getColumnNames();
0450: boolean isOK = true;
0451: for (int i = 0; i < xxx.length; i++) {
0452: if (!xxx[i].endsWith("*")) {
0453: out: for (int j = 0; j < yyy.length; j++) {
0454: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0455: isOK = true;
0456: break out;
0457: } else
0458: isOK = false;
0459: }
0460: if (!isOK)
0461: throw new SQLException("Column '" + xxx[i]
0462: + "' not found.");
0463: }
0464: }
0465: try {
0466: String[] colValues = parser.columnValues;
0467: String[] colNames = parser.columnNames;
0468: String keyColumn = connection.getNameColumn();
0469: String key;
0470: String value;
0471: if (colNames.length != colValues.length) {
0472: throw new Exception(
0473: "Number of columns and number of values are different!");
0474: }
0475: if (colNames[0].equalsIgnoreCase(keyColumn)) {
0476: key = colValues[0];
0477: value = colValues[1];
0478: } else {
0479: key = colValues[1];
0480: value = colValues[0];
0481: }
0482:
0483: connection.setCurrentTableName(parser
0484: .getTableName());
0485:
0486: if (connection.getAutoCommit()) {
0487: connection.getProperties().load(
0488: new FileInputStream(checkFile));
0489: }
0490: if (connection.getProperties().containsKey(key) == true) {
0491: throw new Exception(
0492: "Key already exist in the property file. Key must be unique!");
0493: } else {
0494: connection.getProperties().put(key, value);
0495: if (connection.getAutoCommit()) {
0496: connection.getProperties().store(checkFile);
0497: }
0498: updated++;
0499: }
0500:
0501: } catch (Exception e) {
0502: throw new SQLException(
0503: "Error writing data to property file."
0504: + e.getMessage());
0505: }
0506: } catch (Exception e) {
0507: throw new SQLException(
0508: "Error writing data file. Message was: " + e);
0509: }
0510:
0511: } else if (parser.sqlType.equals(I18nSqlParser.UPDATE)) {
0512:
0513: String fileName = connection.getPath()
0514: + parser.getTableName() + connection.getExtension();
0515: File checkFile = new File(fileName);
0516:
0517: if (!checkFile.exists()) {
0518: throw new SQLException("Cannot open data file '"
0519: + fileName + "' !");
0520: }
0521:
0522: if (!checkFile.canWrite()) {
0523: throw new SQLException("Data file '" + fileName
0524: + "' is read only !");
0525: }
0526:
0527: try {
0528: String[] xxx = parser.getColumnNames();
0529: String[] yyy = connection.getColumnNames();
0530: boolean isOK = true;
0531: for (int i = 0; i < xxx.length; i++) {
0532: if (!xxx[i].endsWith("*")) {
0533: out: for (int j = 0; j < yyy.length; j++) {
0534: if (xxx[i].equalsIgnoreCase(yyy[j])) {
0535: isOK = true;
0536: break out;
0537: } else
0538: isOK = false;
0539: }
0540: if (!isOK)
0541: throw new SQLException("Column '" + xxx[i]
0542: + "' not found.");
0543: }
0544: }
0545:
0546: try {
0547: String[] colValues = parser.columnValues;
0548: String[] colNames = parser.columnNames;
0549: String[] colWhereNames = parser.columnWhereNames;
0550: String[] colWhereValues = parser.columnWhereValues;
0551: String keyColumn = connection.getNameColumn();
0552: String valueColumn = connection.getValueColumn();
0553: String key = "";
0554: String value = "";
0555: boolean paramsOK = true;
0556: //pick up values which will be updated.This block is used if firs column is
0557: // key column
0558: if (colNames[0].equalsIgnoreCase(keyColumn)) {
0559: if (colValues.length == 1) {
0560: key = colValues[0];
0561: } else if (colValues.length == 2) {
0562: key = colValues[0];
0563: value = colValues[1];
0564: }
0565: //pick up values which will be updated.This block is used if first column is
0566: //value column
0567: } else if (colNames[0]
0568: .equalsIgnoreCase(valueColumn)) {
0569: if (colValues.length == 1) {
0570: value = colValues[0];
0571: } else if (colValues.length == 2) {
0572: value = colValues[0];
0573: key = colValues[1];
0574: }
0575: }
0576:
0577: connection.setCurrentTableName(parser
0578: .getTableName());
0579:
0580: if (connection.getAutoCommit()) {
0581: connection.getProperties().load(
0582: new FileInputStream(checkFile));
0583: }
0584: if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0]
0585: .equalsIgnoreCase(valueColumn))) {
0586: throw new SQLException(
0587: "Error in sql statement. Wrong column name!");
0588: }
0589: if ((!key.equalsIgnoreCase(""))
0590: && (!value.equalsIgnoreCase(""))) {
0591: Enumeration en = connection.getProperties()
0592: .keys();
0593: while (en.hasMoreElements()) {
0594: String oldKey = en.nextElement().toString();
0595: String oldValue = connection
0596: .getProperties()
0597: .getProperty(oldKey);
0598: //update key and value if this key is equal with key from where claus and also column name from where claus is equal with key column
0599: //or update key and value if this value is equal with value from where claus and also column name from where claus is equal with value column
0600: if ((colWhereValues[0]
0601: .equalsIgnoreCase(oldKey) && keyColumn
0602: .equals(colWhereNames[0]))
0603: || (colWhereValues[0]
0604: .equalsIgnoreCase(oldValue) && valueColumn
0605: .equals(colWhereNames[0]))) {
0606: connection.getProperties().remove(
0607: oldKey);
0608: connection.getProperties().put(key,
0609: value);
0610: updated++;
0611: }
0612: }
0613:
0614: } else if (!value.equalsIgnoreCase("")) {
0615:
0616: Enumeration en = connection.getProperties()
0617: .keys();
0618: while (en.hasMoreElements()) {
0619: String oldKey = en.nextElement().toString();
0620: String oldValue = connection
0621: .getProperties()
0622: .getProperty(oldKey);
0623: //update value if this key is equal with key from where claus and also column name from where claus is equal with key column
0624: //or update value if this value is equal with value from where claus and also column name from where claus is equal with value column
0625: if ((colWhereValues[0]
0626: .equalsIgnoreCase(oldKey) && keyColumn
0627: .equals(colWhereNames[0]))
0628: || (colWhereValues[0]
0629: .equalsIgnoreCase(oldValue) && valueColumn
0630: .equals(colWhereNames[0]))) {
0631: connection.getProperties().put(oldKey,
0632: value);
0633: updated++;
0634: }
0635: }
0636: } else if (!key.equalsIgnoreCase("")) {
0637:
0638: Enumeration en = connection.getProperties()
0639: .keys();
0640: while (en.hasMoreElements()) {
0641: String oldKey = en.nextElement().toString();
0642: String oldValue = connection
0643: .getProperties()
0644: .getProperty(oldKey);
0645: //update key if this key is equal with key from where claus and also column name from where claus is equal with key column
0646: //or update key if this value is equal with value from where claus and also column name from where claus is equal with value column
0647: if ((colWhereValues[0]
0648: .equalsIgnoreCase(oldKey) && keyColumn
0649: .equals(colWhereNames[0]))
0650: || (colWhereValues[0]
0651: .equalsIgnoreCase(oldValue) && valueColumn
0652: .equals(colWhereNames[0]))) {
0653: connection.getProperties().remove(
0654: oldKey);
0655: connection.getProperties().put(key,
0656: oldValue);
0657: updated++;
0658: }
0659: }
0660:
0661: }
0662: if (connection.getAutoCommit()) {
0663: connection.getProperties().store(checkFile);
0664: }
0665: //}
0666: } catch (Exception e) {
0667: throw new SQLException(
0668: "Error writing data to property file."
0669: + e.getMessage());
0670: }
0671:
0672: } catch (Exception e) {
0673: throw new SQLException(
0674: "Error writing data file. Message was: " + e);
0675: }
0676:
0677: } else if (parser.sqlType.equals(I18nSqlParser.DELETE)) {
0678: String fileName = connection.getPath()
0679: + parser.getTableName() + connection.getExtension();
0680: File checkFile = new File(fileName);
0681:
0682: if (!checkFile.exists()) {
0683: throw new SQLException("Cannot open data file '"
0684: + fileName + "' !");
0685: }
0686:
0687: if (!checkFile.canWrite()) {
0688: throw new SQLException("Data file '" + fileName
0689: + "' is read only !");
0690: }
0691: try {
0692:
0693: //// try {
0694: boolean deleteAll = false;
0695: String[] colWhereNames = parser.columnWhereNames;
0696: String[] colWhereValues = parser.columnWhereValues;
0697: String keyColumn = connection.getNameColumn();
0698: String valueColumn = connection.getValueColumn();
0699:
0700: connection.setCurrentTableName(parser.getTableName());
0701:
0702: if (connection.getAutoCommit()) {
0703: connection.getProperties().load(
0704: new FileInputStream(checkFile));
0705: }
0706: if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0]
0707: .equalsIgnoreCase(valueColumn))) {
0708: throw new SQLException(
0709: "Error in sql statement. Wrong column name!");
0710: }
0711: Enumeration en = connection.getProperties().keys();
0712: if (colWhereNames.length == 0) {
0713: deleteAll = true;
0714: }
0715: if (!deleteAll) {
0716: while (en.hasMoreElements()) {
0717: String oldKey = en.nextElement().toString();
0718: String oldValue = connection.getProperties()
0719: .getProperty(oldKey);
0720:
0721: if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn
0722: .equals(colWhereNames[0]))
0723: || (colWhereValues[0]
0724: .equalsIgnoreCase(oldValue) && valueColumn
0725: .equals(colWhereNames[0]))) {
0726: connection.getProperties().remove(oldKey);
0727: if (connection.getAutoCommit()) {
0728: connection.getProperties().store(
0729: checkFile);
0730: }
0731: updated++;
0732: }
0733:
0734: }
0735: } else {
0736: connection.getProperties().clear();
0737: if (connection.getAutoCommit()) {
0738: connection.getProperties().store(checkFile);
0739: }
0740: }
0741: } catch (Exception e) {
0742: throw new SQLException(
0743: "Error deleting data from property file."
0744: + e.getMessage());
0745: }
0746:
0747: }
0748: return updated;
0749:
0750: }
0751:
0752: /**
0753: * Releases this <code>Statement</code> object's database
0754: * and JDBC resources immediately instead of waiting for
0755: * this to happen when it is automatically closed.
0756: * It is generally good practice to release resources as soon as
0757: * you are finished with them to avoid tying up database
0758: * resources.
0759: * <P>
0760: * Calling the method <code>close</code> on a <code>Statement</code>
0761: * object that is already closed has no effect.
0762: * <P>
0763: * <B>Note:</B> A <code>Statement</code> object is automatically closed
0764: * when it is garbage collected. When a <code>Statement</code> object is
0765: * closed, its current <code>ResultSet</code> object, if one exists, is
0766: * also closed.
0767: *
0768: * @exception SQLException if a database access error occurs
0769: */
0770: public void close() throws SQLException {
0771: // close all result sets
0772: for (Enumeration i = resultSets.elements(); i.hasMoreElements();) {
0773: I18nResultSet resultSet = (I18nResultSet) i.nextElement();
0774: resultSet.close();
0775: }
0776:
0777: }
0778:
0779: /**
0780: *Description of the Method
0781: *
0782: * @exception SQLException Description of Exception
0783: * @since
0784: */
0785: public void cancel() throws SQLException {
0786: throw new SQLException("Not Supported !");
0787: }
0788:
0789: /**
0790: *Description of the Method
0791: *
0792: * @exception SQLException Description of Exception
0793: * @since
0794: */
0795: public void clearWarnings() throws SQLException {
0796: throw new SQLException("Not Supported !");
0797: }
0798:
0799: /**
0800: *Description of the Method
0801: *
0802: * @param sql Description of Parameter
0803: * @return Description of the Returned Value
0804: * @exception SQLException Description of Exception
0805: * @since
0806: */
0807: public boolean execute(String sql) throws SQLException {
0808: I18nSqlParser parser = new I18nSqlParser();
0809: if (binaryStreamParameters.size() != 0)
0810: parser.setBinaryStreamList(binaryStreamParameters);
0811: this .sql = sql;
0812: try {
0813: parser.parse(this );
0814: } catch (Exception e) {
0815: throw new SQLException("Syntax Error. " + e.getMessage());
0816: }
0817: if (parser.sqlType.equals(I18nSqlParser.SELECT))
0818: throw new SQLException(
0819: "Not supported SELECT statement - use executeQuery method");
0820: else if (parser.sqlType.equals(I18nSqlParser.INSERT))
0821: executeUpdate(sql);
0822: else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
0823: String fileName = connection.getPath()
0824: + parser.getTableName() + connection.getExtension();
0825: File checkFile = new File(fileName);
0826:
0827: if (checkFile.exists()) {
0828: throw new SQLException("Data file '" + fileName
0829: + "'already exists !");
0830: }
0831:
0832: try {
0833: checkFile.createNewFile();
0834:
0835: } catch (Exception e) {
0836: throw new SQLException(
0837: "Error reading data file. Message was: " + e);
0838: }
0839: }
0840: return true;
0841:
0842: }
0843:
0844: /**
0845: * Set String as parameter in sql statement.
0846: * @param parameterIndex
0847: * @param value
0848: * @throws SQLException
0849: */
0850: public void setString(int parameterIndex, String value)
0851: throws SQLException {
0852: if (value == null) {
0853: I18nDriver.log("value = null object");
0854: parameters.set(parameterIndex - 1, value);
0855: } else {
0856: value = Utils.replaceAll(value, "'",
0857: I18nSqlParser.QUOTE_ESCAPE);
0858: I18nDriver.log("value = " + value);
0859: parameters.set(parameterIndex - 1, "'" + value + "'");
0860: }
0861: }
0862:
0863: /**
0864: *
0865: * @param parameterIndex
0866: * @param value
0867: * @throws SQLException
0868: */
0869: public void setBytes(int parameterIndex, byte[] value)
0870: throws SQLException {
0871: binaryStreamParameters.add(Utils.bytesToHexString(value));
0872: String paramName = I18nSqlParser.BINARY_STREAM_OBJECT + ""
0873: + binaryStreamParameters.size();
0874: parameters.set(parameterIndex - 1, paramName);
0875: }
0876:
0877: /**
0878: *Adds a feature to the Batch attribute of the I18nStatement object
0879: *
0880: * @param p0 The feature to be added to the Batch attribute
0881: * @exception SQLException Description of Exception
0882: * @since
0883: */
0884: public void addBatch(String p0) throws SQLException {
0885: throw new SQLException("Not Supported !");
0886: }
0887:
0888: /**
0889: *Description of the Method
0890: *
0891: * @exception SQLException Description of Exception
0892: * @since
0893: */
0894: public void clearBatch() throws SQLException {
0895: throw new SQLException("Not Supported !");
0896: }
0897:
0898: /**
0899: *Description of the Method
0900: *
0901: * @return Description of the Returned Value
0902: * @exception SQLException Description of Exception
0903: * @since
0904: */
0905: public int[] executeBatch() throws SQLException {
0906: throw new SQLException("Not Supported !");
0907: }
0908:
0909: //---------------------------------------------------------------------
0910: // JDBC 3.0
0911: //---------------------------------------------------------------------
0912:
0913: public boolean getMoreResults(int current) throws SQLException {
0914: throw new UnsupportedOperationException(
0915: "Statement.getMoreResults(int) unsupported");
0916: }
0917:
0918: public ResultSet getGeneratedKeys() throws SQLException {
0919: throw new UnsupportedOperationException(
0920: "Statement.getGeneratedKeys() unsupported");
0921: }
0922:
0923: public int executeUpdate(String sql, int autoGeneratedKeys)
0924: throws SQLException {
0925: throw new UnsupportedOperationException(
0926: "Statement.executeUpdate(String,int) unsupported");
0927: }
0928:
0929: public int executeUpdate(String sql, int[] columnIndexes)
0930: throws SQLException {
0931: throw new UnsupportedOperationException(
0932: "Statement.executeUpdate(String,int[]) unsupported");
0933: }
0934:
0935: public int executeUpdate(String sql, String[] columnNames)
0936: throws SQLException {
0937: throw new UnsupportedOperationException(
0938: "Statement.executeUpdate(String,String[]) unsupported");
0939: }
0940:
0941: public boolean execute(String sql, int autoGeneratedKeys)
0942: throws SQLException {
0943: throw new UnsupportedOperationException(
0944: "Statement.execute(String,int) unsupported");
0945: }
0946:
0947: public boolean execute(String sql, int[] columnIndexes)
0948: throws SQLException {
0949: throw new UnsupportedOperationException(
0950: "Statement.execute(String,int[]) unsupported");
0951: }
0952:
0953: public boolean execute(String sql, String[] columnNames)
0954: throws SQLException {
0955: throw new UnsupportedOperationException(
0956: "Statement.execute(String,String[]) unsupported");
0957: }
0958:
0959: public int getResultSetHoldability() throws SQLException {
0960: throw new UnsupportedOperationException(
0961: "Statement.getResultSetHoldability() unsupported");
0962: }
0963:
0964: public ResultSet executeQuery() throws SQLException {
0965: if (!prepareSql())
0966: throw new SQLException("Error with prepared statement !");
0967: return executeQuery(this .sqlPrepared);
0968:
0969: }
0970:
0971: public int executeUpdate() throws SQLException {
0972: if (!prepareSql())
0973: throw new SQLException("Error with prepared statement !");
0974: executeUpdate(this .sqlPrepared);
0975: return 0;
0976: }
0977:
0978: public void setNull(int parameterIndex, int sqlType)
0979: throws SQLException {
0980: this .setString(parameterIndex, null);
0981: }
0982:
0983: public void setBoolean(int parameterIndex, boolean value)
0984: throws SQLException {
0985: this .setString(parameterIndex, String.valueOf(value));
0986: }
0987:
0988: public void setByte(int parameterIndex, byte value)
0989: throws SQLException {
0990: this .setString(parameterIndex, String.valueOf(value));
0991: }
0992:
0993: public void setShort(int parameterIndex, short value)
0994: throws SQLException {
0995: this .setString(parameterIndex, String.valueOf(value));
0996: }
0997:
0998: public void setInt(int parameterIndex, int value)
0999: throws SQLException {
1000: this .setString(parameterIndex, String.valueOf(value));
1001: }
1002:
1003: public void setLong(int parameterIndex, long value)
1004: throws SQLException {
1005: this .setString(parameterIndex, String.valueOf(value));
1006: }
1007:
1008: public void setFloat(int parameterIndex, float value)
1009: throws SQLException {
1010: this .setString(parameterIndex, String.valueOf(value));
1011: }
1012:
1013: public void setDouble(int parameterIndex, double value)
1014: throws SQLException {
1015: this .setString(parameterIndex, String.valueOf(value));
1016: }
1017:
1018: public void setBigDecimal(int parameterIndex, BigDecimal value)
1019: throws SQLException {
1020: if (value == null) {
1021: this .setString(parameterIndex, value.toString());
1022: } else {
1023: this .setString(parameterIndex, "");
1024: }
1025: }
1026:
1027: public void setDate(int parameterIndex, Date value)
1028: throws SQLException {
1029: if (value == null) {
1030: this .setString(parameterIndex, value.toString());
1031: } else {
1032: this .setString(parameterIndex, "");
1033: }
1034: }
1035:
1036: public void setTime(int parameterIndex, Time value)
1037: throws SQLException {
1038: if (value == null) {
1039: this .setString(parameterIndex, value.toString());
1040: } else {
1041: this .setString(parameterIndex, "");
1042: }
1043: }
1044:
1045: public void setTimestamp(int parameterIndex, Timestamp value)
1046: throws SQLException {
1047: if (value == null) {
1048: this .setString(parameterIndex, value.toString());
1049: } else {
1050: this .setString(parameterIndex, "");
1051: }
1052: }
1053:
1054: public void setAsciiStream(int parameterIndex, InputStream x,
1055: int length) throws SQLException {
1056: /**@todo Implement this java.sql.PreparedStatement method*/
1057: throw new java.lang.UnsupportedOperationException(
1058: "Method setAsciiStream() not yet implemented.");
1059: }
1060:
1061: public void setUnicodeStream(int parameterIndex, InputStream x,
1062: int length) throws SQLException {
1063: /**@todo Implement this java.sql.PreparedStatement method*/
1064: throw new java.lang.UnsupportedOperationException(
1065: "Method setUnicodeStream() not yet implemented.");
1066: }
1067:
1068: public void clearParameters() throws SQLException {
1069: this .sqlPrepared = this .sqlForPrepare;
1070: for (int i = 0; i < parameters.size(); i++)
1071: parameters.set(i, null);
1072: }
1073:
1074: public void setObject(int parameterIndex, Object x,
1075: int targetSqlType, int scale) throws SQLException {
1076: /**@todo Implement this java.sql.PreparedStatement method*/
1077: throw new java.lang.UnsupportedOperationException(
1078: "Method setObject() not yet implemented.");
1079: }
1080:
1081: public void setObject(int parameterIndex, Object x,
1082: int targetSqlType) throws SQLException {
1083: /**@todo Implement this java.sql.PreparedStatement method*/
1084: throw new java.lang.UnsupportedOperationException(
1085: "Method setObject() not yet implemented.");
1086: }
1087:
1088: public void setObject(int parameterIndex, Object x)
1089: throws SQLException {
1090: if (x == null)
1091: x = new String("null");
1092: setString(parameterIndex, x.toString());
1093: }
1094:
1095: public boolean execute() throws SQLException {
1096: /**@todo Implement this java.sql.PreparedStatement method*/
1097: throw new java.lang.UnsupportedOperationException(
1098: "Method execute() not yet implemented.");
1099: }
1100:
1101: public void addBatch() throws SQLException {
1102: /**@todo Implement this java.sql.PreparedStatement method*/
1103: throw new java.lang.UnsupportedOperationException(
1104: "Method addBatch() not yet implemented.");
1105: }
1106:
1107: public void setCharacterStream(int parameterIndex, Reader reader,
1108: int length) throws SQLException {
1109: /**@todo Implement this java.sql.PreparedStatement method*/
1110: throw new java.lang.UnsupportedOperationException(
1111: "Method setCharacterStream() not yet implemented.");
1112: }
1113:
1114: public void setRef(int i, Ref x) throws SQLException {
1115: /**@todo Implement this java.sql.PreparedStatement method*/
1116: throw new java.lang.UnsupportedOperationException(
1117: "Method setRef() not yet implemented.");
1118: }
1119:
1120: public void setClob(int i, Clob x) throws SQLException {
1121: /**@todo Implement this java.sql.PreparedStatement method*/
1122: throw new java.lang.UnsupportedOperationException(
1123: "Method setClob() not yet implemented.");
1124: }
1125:
1126: public void setArray(int i, Array x) throws SQLException {
1127: /**@todo Implement this java.sql.PreparedStatement method*/
1128: throw new java.lang.UnsupportedOperationException(
1129: "Method setArray() not yet implemented.");
1130: }
1131:
1132: public ResultSetMetaData getMetaData() throws SQLException {
1133: /**@todo Implement this java.sql.PreparedStatement method*/
1134: throw new java.lang.UnsupportedOperationException(
1135: "Method getMetaData() not yet implemented.");
1136: }
1137:
1138: public void setDate(int parameterIndex, Date x, Calendar cal)
1139: throws SQLException {
1140: /**@todo Implement this java.sql.PreparedStatement method*/
1141: throw new java.lang.UnsupportedOperationException(
1142: "Method setDate() not yet implemented.");
1143: }
1144:
1145: public void setTime(int parameterIndex, Time x, Calendar cal)
1146: throws SQLException {
1147: /**@todo Implement this java.sql.PreparedStatement method*/
1148: throw new java.lang.UnsupportedOperationException(
1149: "Method setTime() not yet implemented.");
1150: }
1151:
1152: public void setTimestamp(int parameterIndex, Timestamp x,
1153: Calendar cal) throws SQLException {
1154: /**@todo Implement this java.sql.PreparedStatement method*/
1155: throw new java.lang.UnsupportedOperationException(
1156: "Method setTimestamp() not yet implemented.");
1157: }
1158:
1159: public void setNull(int paramIndex, int sqlType, String typeName)
1160: throws SQLException {
1161: this .setString(paramIndex, null);
1162: }
1163:
1164: public void setURL(int parameterIndex, URL x) throws SQLException {
1165: /**@todo Implement this java.sql.PreparedStatement method*/
1166: throw new java.lang.UnsupportedOperationException(
1167: "Method setURL() not yet implemented.");
1168: }
1169:
1170: public ParameterMetaData getParameterMetaData() throws SQLException {
1171: /**@todo Implement this java.sql.PreparedStatement method*/
1172: throw new java.lang.UnsupportedOperationException(
1173: "Method getParameterMetaData() not yet implemented.");
1174: }
1175:
1176: public void setBinaryStream(int parameterIndex, InputStream value,
1177: int length) throws SQLException {
1178: /**@todo Implement this java.sql.PreparedStatement method*/
1179: throw new java.lang.UnsupportedOperationException(
1180: "Method setBinaryStream() not yet implemented.");
1181: }
1182:
1183: public void setBlob(int parameterIndex, Blob value)
1184: throws SQLException {
1185: /**@todo Implement this java.sql.PreparedStatement method*/
1186: throw new java.lang.UnsupportedOperationException(
1187: "Method setBlob() not yet implemented.");
1188: }
1189:
1190: public String getSqlStatement() {
1191: return sql;
1192: }
1193:
1194: public I18nProperties getProperties() {
1195: return connection.getProperties();
1196: }
1197:
1198: public void setAsciiStream(int parameterIndex, InputStream x)
1199: throws SQLException {
1200: // TODO Auto-generated method stub
1201: throw new java.lang.UnsupportedOperationException(
1202: "Method setAsciiStream(int,InputStream) not yet implemented.");
1203: }
1204:
1205: public void setAsciiStream(int parameterIndex, InputStream x,
1206: long length) throws SQLException {
1207: // TODO Auto-generated method stub
1208: throw new java.lang.UnsupportedOperationException(
1209: "Method setAsciiStream(int,InputStream,long) not yet implemented.");
1210: }
1211:
1212: public void setBinaryStream(int parameterIndex, InputStream x)
1213: throws SQLException {
1214: // TODO Auto-generated method stub
1215: throw new java.lang.UnsupportedOperationException(
1216: "Method setBinaryStream(int,InputStream) not yet implemented.");
1217: }
1218:
1219: public void setBinaryStream(int parameterIndex, InputStream x,
1220: long length) throws SQLException {
1221: // TODO Auto-generated method stub
1222: throw new java.lang.UnsupportedOperationException(
1223: "Method setBinaryStream(int,InputStream,long) not yet implemented.");
1224: }
1225:
1226: public void setBlob(int parameterIndex, InputStream inputStream)
1227: throws SQLException {
1228: // TODO Auto-generated method stub
1229: throw new java.lang.UnsupportedOperationException(
1230: "Method setBlob(int,InputStream) not yet implemented.");
1231: }
1232:
1233: public void setBlob(int parameterIndex, InputStream inputStream,
1234: long length) throws SQLException {
1235: // TODO Auto-generated method stub
1236: throw new java.lang.UnsupportedOperationException(
1237: "Method setBlob(int,InputStream,long) not yet implemented.");
1238: }
1239:
1240: public void setCharacterStream(int parameterIndex, Reader reader)
1241: throws SQLException {
1242: // TODO Auto-generated method stub
1243: throw new java.lang.UnsupportedOperationException(
1244: "Method setCharacterStream(int,Reader) not yet implemented.");
1245: }
1246:
1247: public void setCharacterStream(int parameterIndex, Reader reader,
1248: long length) throws SQLException {
1249: // TODO Auto-generated method stub
1250: throw new java.lang.UnsupportedOperationException(
1251: "Method setCharacterStream(int,Reader,long) not yet implemented.");
1252: }
1253:
1254: public void setClob(int parameterIndex, Reader reader)
1255: throws SQLException {
1256: // TODO Auto-generated method stub
1257: throw new java.lang.UnsupportedOperationException(
1258: "Method setClob(int,Reader) not yet implemented.");
1259: }
1260:
1261: public void setClob(int parameterIndex, Reader reader, long length)
1262: throws SQLException {
1263: // TODO Auto-generated method stub
1264: throw new java.lang.UnsupportedOperationException(
1265: "Method setClob(int,Reader,long) not yet implemented.");
1266: }
1267:
1268: public void setNCharacterStream(int parameterIndex, Reader value)
1269: throws SQLException {
1270: // TODO Auto-generated method stub
1271: throw new java.lang.UnsupportedOperationException(
1272: "Method setNCharacterStream(int,Reader) not yet implemented.");
1273: }
1274:
1275: public void setNCharacterStream(int parameterIndex, Reader value,
1276: long length) throws SQLException {
1277: // TODO Auto-generated method stub
1278: throw new java.lang.UnsupportedOperationException(
1279: "Method setNCharacterStream(int,Reader,long) not yet implemented.");
1280: }
1281:
1282: public void setNClob(int parameterIndex, NClob value)
1283: throws SQLException {
1284: // TODO Auto-generated method stub
1285: throw new java.lang.UnsupportedOperationException(
1286: "Method setNClob(int,NClob) not yet implemented.");
1287: }
1288:
1289: public void setNClob(int parameterIndex, Reader reader)
1290: throws SQLException {
1291: // TODO Auto-generated method stub
1292: throw new java.lang.UnsupportedOperationException(
1293: "Method setNClob(int,Reader) not yet implemented.");
1294: }
1295:
1296: public void setNClob(int parameterIndex, Reader reader, long length)
1297: throws SQLException {
1298: // TODO Auto-generated method stub
1299: throw new java.lang.UnsupportedOperationException(
1300: "Method setNClob(int,Reader,long) not yet implemented.");
1301: }
1302:
1303: public void setNString(int parameterIndex, String value)
1304: throws SQLException {
1305: // TODO Auto-generated method stub
1306: throw new java.lang.UnsupportedOperationException(
1307: "Method setNString(int,String) not yet implemented.");
1308: }
1309:
1310: public void setRowId(int parameterIndex, RowId x)
1311: throws SQLException {
1312: // TODO Auto-generated method stub
1313: throw new java.lang.UnsupportedOperationException(
1314: "Method setRowId(int,RowId) not yet implemented.");
1315: }
1316:
1317: public void setSQLXML(int parameterIndex, SQLXML xmlObject)
1318: throws SQLException {
1319: // TODO Auto-generated method stub
1320: throw new java.lang.UnsupportedOperationException(
1321: "Method setSQLXML(int,SQLXML) not yet implemented.");
1322: }
1323:
1324: public boolean isClosed() throws SQLException {
1325: // TODO Auto-generated method stub
1326: return false;
1327: }
1328:
1329: public boolean isPoolable() throws SQLException {
1330: // TODO Auto-generated method stub
1331: return false;
1332: }
1333:
1334: public void setPoolable(boolean poolable) throws SQLException {
1335: // TODO Auto-generated method stub
1336: throw new java.lang.UnsupportedOperationException(
1337: "Method setPoolable(boolean) not yet implemented.");
1338: }
1339:
1340: public boolean isWrapperFor(Class<?> iface) throws SQLException {
1341: // TODO Auto-generated method stub
1342: return false;
1343: }
1344:
1345: public <T> T unwrap(Class<T> iface) throws SQLException {
1346: // TODO Auto-generated method stub
1347: return null;
1348: }
1349:
1350: }
|