📄 i18nstatement.java
字号:
/**
Copyright (C) 2002-2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.i18njdbc;
import java.sql.*;
import java.io.File;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Vector;
/**
* This class implements the Statement interface for the I18nJdbc driver.
*
* @author Zoran Milakovic
* @author Zeljko Kovacevic
*/
public class I18nStatement implements Statement
{
private I18nProperties properties;
private I18nConnection connection;
private Vector resultSets = new Vector();
private String sql;
/**
*Constructor for the I18nStatement object
*
* @param connection Description of Parameter
* @since
*/
protected I18nStatement(I18nConnection connection)
{
try {
DriverManager.println("I18nJdbc - I18Statement() - connection=" + connection);
this.connection = connection;
this.properties = new I18nProperties();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
*Sets the maxFieldSize attribute of the I18nStatement object
*
* @param p0 The new maxFieldSize value
* @exception SQLException Description of Exception
* @since
*/
public void setMaxFieldSize(int p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the maxRows attribute of the I18nStatement object
*
* @param p0 The new maxRows value
* @exception SQLException Description of Exception
* @since
*/
public void setMaxRows(int p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the escapeProcessing attribute of the I18nStatement object
*
* @param p0 The new escapeProcessing value
* @exception SQLException Description of Exception
* @since
*/
public void setEscapeProcessing(boolean p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the queryTimeout attribute of the I18nStatement object
*
* @param p0 The new queryTimeout value
* @exception SQLException Description of Exception
* @since
*/
public void setQueryTimeout(int p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the cursorName attribute of the I18nStatement object
*
* @param p0 The new cursorName value
* @exception SQLException Description of Exception
* @since
*/
public void setCursorName(String p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the fetchDirection attribute of the I18nStatement object
*
* @param p0 The new fetchDirection value
* @exception SQLException Description of Exception
* @since
*/
public void setFetchDirection(int p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Sets the fetchSize attribute of the I18nStatement object
*
* @param p0 The new fetchSize value
* @exception SQLException Description of Exception
* @since
*/
public void setFetchSize(int p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the maxFieldSize attribute of the I18nStatement object
*
* @return The maxFieldSize value
* @exception SQLException Description of Exception
* @since
*/
public int getMaxFieldSize() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the maxRows attribute of the I18nStatement object
*
* @return The maxRows value
* @exception SQLException Description of Exception
* @since
*/
public int getMaxRows() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the queryTimeout attribute of the I18nStatement object
*
* @return The queryTimeout value
* @exception SQLException Description of Exception
* @since
*/
public int getQueryTimeout() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the warnings attribute of the I18nStatement object
*
* @return The warnings value
* @exception SQLException Description of Exception
* @since
*/
public SQLWarning getWarnings() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSet attribute of the I18nStatement object
*
* @return The resultSet value
* @exception SQLException Description of Exception
* @since
*/
public ResultSet getResultSet() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the updateCount attribute of the I18nStatement object
*
* @return The updateCount value
* @exception SQLException Description of Exception
* @since
*/
public int getUpdateCount() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the moreResults attribute of the I18nStatement object
*
* @return The moreResults value
* @exception SQLException Description of Exception
* @since
*/
public boolean getMoreResults() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the fetchDirection attribute of the I18nStatement object
*
* @return The fetchDirection value
* @exception SQLException Description of Exception
* @since
*/
public int getFetchDirection() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the fetchSize attribute of the I18nStatement object
*
* @return The fetchSize value
* @exception SQLException Description of Exception
* @since
*/
public int getFetchSize() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSetConcurrency attribute of the I18nStatement object
*
* @return The resultSetConcurrency value
* @exception SQLException Description of Exception
* @since
*/
public int getResultSetConcurrency() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSetType attribute of the I18nStatement object
*
* @return The resultSetType value
* @exception SQLException Description of Exception
* @since
*/
public int getResultSetType() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Gets the connection attribute of the I18nStatement object
*
* @return The connection value
* @exception SQLException Description of Exception
* @since
*/
public Connection getConnection() throws SQLException
{
return connection;
}
/**
*Description of the Method
*
* @param sql Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public ResultSet executeQuery(String sql) throws SQLException
{
DriverManager.println("I18nJdbc - I18nStatement:executeQuery() - sql= " + sql);
I18nSqlParser parser = new I18nSqlParser();
this.sql = sql;
try
{
parser.parse(this);
}
catch (Exception e)
{
throw new SQLException("Syntax Error. " + e.getMessage());
}
String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
File checkFile = new File(fileName);
if (!checkFile.exists())
{
throw new SQLException("Cannot open data file '" + fileName + "' !");
}
if (!checkFile.canRead())
{
throw new SQLException("Data file '" + fileName + "' not readable !");
}
try
{
String[] xxx = parser.getColumnNames();
String[] yyy = connection.getColumnNames();
boolean isOK = true;
for(int i=0; i< xxx.length; i++) {
if(!xxx[i].endsWith("*")) {
out:
for(int j=0; j< yyy.length; j++) {
if(xxx[i].equalsIgnoreCase(yyy[j])) {
isOK=true;
break out;
}
else
isOK=false;
}
if(!isOK)
throw new SQLException("Column '" + xxx[i] + "' not found.");
}
}
}
catch (Exception e)
{
if( I18nDriver.DEBUG )
e.printStackTrace();
throw new SQLException("Error reading data file. Message was: " + e);
}
//load properties file
try {
this.properties.load(new FileInputStream(checkFile));
} catch (Exception e) {
throw new SQLException("Error while loading properties");
}
I18nResultSet resultSet = new I18nResultSet(this,
parser.getTableName(), parser.getColumnNames(), parser.getWhereColumnNames(),
parser.getWhereColumnValues());
resultSets.add(resultSet);
return resultSet;
}
/**
*Description of the Method
*
* @param sql Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public int executeUpdate(String sql) throws SQLException
{
int updated=0;
DriverManager.println("I18nJdbc - I18nStatement:executeUpdate() - sql= " + sql);
I18nSqlParser parser = new I18nSqlParser();
this.sql = sql;
try
{
parser.parse(this);
}
catch (Exception e)
{
throw new SQLException("Syntax Error. " + e.getMessage());
}
if(parser.sqlType.equals(I18nSqlParser.SELECT))
throw new SQLException("Not supported SELECT statement - use executeQuery method");
else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
throw new SQLException("Not supported CREATE TABLE statement - use execute method");
}
else if (parser.sqlType.equals(I18nSqlParser.INSERT)) {
String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
File checkFile = new File(fileName);
if (!checkFile.exists())
{
throw new SQLException("Cannot open data file '" + fileName + "' !");
}
if (!checkFile.canWrite())
{
throw new SQLException("Data file '" + fileName + "' is read only !");
}
try
{
String[] xxx = parser.getColumnNames();
String[] yyy = connection.getColumnNames();
boolean isOK = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -