org.eclipse.datatools.connectivity.oda.flatfile_3.1.2.v201112081200

16:42:43.781 INFO  jd.cli.Main - Decompiling org.eclipse.datatools.connectivity.oda.flatfile_3.1.2.v201112081200.jar
package org.eclipse.datatools.connectivity.oda.flatfile;

public final class CommonConstants
{
  public static final String CONN_HOME_DIR_PROP = "HOME";
  public static final String CONN_FILE_URI_PROP = "URI";
  public static final String CONN_CHARSET_PROP = "CHARSET";
  public static final String CONN_INCLCOLUMNNAME_PROP = "INCLCOLUMNNAME";
  public static final String CONN_INCLTYPELINE_PROP = "INCLTYPELINE";
  public static final String CONN_DEFAULT_CHARSET = "UTF-8";
  public static final String CONN_DELIMITER_TYPE = "DELIMTYPE";
  public static final String CONN_TRAILNULLCOLS_PROP = "TRAILNULLCOLS";
  public static final String CONN_RESOURCE_IDENTIFIER = "RESOURCE_IDENTIFIER";
  public static final String DELIMITER_COMMA = "COMMA";
  public static final String DELIMITER_COMMA_VALUE = ",";
  public static final String DELIMITER_SEMICOLON = "SEMICOLON";
  public static final String DELIMITER_SEMICOLON_VALUE = ";";
  public static final String DELIMITER_PIPE = "PIPE";
  public static final String DELIMITER_PIPE_VALUE = "|";
  public static final String DELIMITER_TAB = "TAB";
  public static final String DELIMITER_TAB_VALUE = "\t";
  public static final String DELIMITER_SPACE = " ";
  public static final char DELIMITER_DOUBLEQUOTE = '"';
  public static final String KEYWORD_SELECT = "SELECT";
  public static final String KEYWORD_FROM = "FROM";
  public static final String KEYWORD_AS = "AS";
  public static final String KEYWORD_ASTERISK = "*";
  public static final String DRIVER_NAME = "ODA FLAT FILE DRIVER";
  public static final String PRODUCT_VERSION = "3.0";
  public static final String INC_COLUMN_NAME_YES = "YES";
  public static final String INC_COLUMN_NAME_NO = "NO";
  public static final String INC_TYPE_LINE_YES = "YES";
  public static final String INC_TYPE_LINE_NO = "NO";
  public static final String TRAIL_NULL_COLS_YES = "YES";
  public static final String TRAIL_NULL_COLS_NO = "NO";
  public static final int MaxConnections = 0;
  public static final int MaxStatements = 0;
  
  public static String getDelimiterValue(String delimiterName)
  {
    if (delimiterName.equalsIgnoreCase("COMMA")) {
      return ",";
    }
    if (delimiterName.equalsIgnoreCase("SEMICOLON")) {
      return ";";
    }
    if (delimiterName.equalsIgnoreCase("PIPE")) {
      return "|";
    }
    if (delimiterName.equalsIgnoreCase("TAB")) {
      return "\t";
    }
    return null;
  }
  
  public static boolean isValidDelimiterName(String delimiterName)
  {
    if (delimiterName.equalsIgnoreCase("COMMA")) {
      return true;
    }
    if (delimiterName.equalsIgnoreCase("SEMICOLON")) {
      return true;
    }
    if (delimiterName.equalsIgnoreCase("PIPE")) {
      return true;
    }
    if (delimiterName.equalsIgnoreCase("TAB")) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.CommonConstants
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import com.ibm.icu.util.ULocale;
import java.util.Map;
import java.util.Properties;
import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
import org.eclipse.datatools.connectivity.oda.IQuery;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.flatfile.i18n.Messages;

public class Connection
  implements IConnection
{
  private boolean isOpen = false;
  private Map appContext = null;
  private char delimiter;
  private String charSet;
  private boolean hasColumnNames;
  private boolean hasTypeLine;
  private boolean trailNullColumns;
  private String homeFolder;
  private String fileURI;
  private Object ri;
  
  public void open(Properties connProperties)
    throws OdaException
  {
    if (connProperties == null) {
      throw new OdaException(Messages.getString("connection_CONNECTION_PROPERTIES_MISSING"));
    }
    populateFileLocation(connProperties);
    
    populateDelimiter(connProperties);
    
    populateInclColumnNames(connProperties);
    
    populateInclTypeLine(connProperties);
    
    populateTrailNullCols(connProperties);
    
    populateCharSet(connProperties);
  }
  
  private void populateFileLocation(Properties connProperties)
    throws OdaException
  {
    homeFolder = connProperties.getProperty("HOME");
    if ((homeFolder != null) && (homeFolder.trim().length() == 0)) {
      homeFolder = null;
    }
    fileURI = connProperties.getProperty("URI");
    if ((fileURI != null) && (fileURI.trim().length() == 0)) {
      fileURI = null;
    }
    if ((homeFolder == null) && (fileURI == null)) {
      throw new OdaException(Messages.getString("connection_MISSING_FILELOCATION"));
    }
    isOpen = true;
  }
  
  private void populateDelimiter(Properties connProperties)
    throws OdaException
  {
    String delimiterName = connProperties.getProperty("DELIMTYPE");
    if (delimiterName == null)
    {
      delimiterName = "COMMA";
      connProperties.setProperty("DELIMTYPE", 
        delimiterName);
    }
    else if (CommonConstants.isValidDelimiterName(delimiterName))
    {
      connProperties.setProperty("DELIMTYPE", 
        delimiterName);
    }
    else
    {
      throw new OdaException(Messages.getString("Unsupported_Delimiter"));
    }
    delimiter = CommonConstants.getDelimiterValue(delimiterName).charAt(0);
  }
  
  private void populateCharSet(Properties connProperties)
  {
    charSet = connProperties.getProperty("CHARSET");
  }
  
  private void populateInclColumnNames(Properties connProperties)
  {
    boolean includeColumnNames = true;
    String inclColumnNames = connProperties.getProperty("INCLCOLUMNNAME");
    if ((inclColumnNames != null) && (inclColumnNames.trim().length() > 0)) {
      includeColumnNames = !inclColumnNames.equalsIgnoreCase("NO");
    }
    connProperties.setProperty("INCLCOLUMNNAME", 
      includeColumnNames ? "YES" : 
      "NO");
    
    hasColumnNames = includeColumnNames;
  }
  
  private void populateInclTypeLine(Properties connProperties)
  {
    boolean includeTypeLine = true;
    String inclTypeLine = connProperties.getProperty("INCLTYPELINE");
    if ((inclTypeLine != null) && (inclTypeLine.trim().length() > 0)) {
      includeTypeLine = !inclTypeLine.equalsIgnoreCase("NO");
    }
    connProperties.setProperty("INCLTYPELINE", 
      includeTypeLine ? "YES" : 
      "NO");
    
    hasTypeLine = includeTypeLine;
  }
  
  private void populateTrailNullCols(Properties connProperties)
  {
    boolean trailNullCols = true;
    String trailNullColsProp = connProperties.getProperty("TRAILNULLCOLS");
    if ((trailNullColsProp != null) && (trailNullColsProp.trim().length() > 0)) {
      trailNullCols = !trailNullColsProp.equalsIgnoreCase("NO");
    }
    connProperties.setProperty("TRAILNULLCOLS", 
      trailNullCols ? "YES" : 
      "NO");
    
    trailNullColumns = trailNullCols;
  }
  
  public void setAppContext(Object context)
    throws OdaException
  {
    appContext = ((Map)context);
  }
  
  public void close()
    throws OdaException
  {
    isOpen = false;
  }
  
  public boolean isOpen()
    throws OdaException
  {
    return isOpen;
  }
  
  public IDataSetMetaData getMetaData(String dataSetType)
    throws OdaException
  {
    return new DataSetMetaData(this);
  }
  
  public IQuery newQuery(String dataSourceType)
    throws OdaException
  {
    if (!isOpen()) {
      throw new OdaException(Messages.getString("common_CONNECTION_HAS_NOT_OPEN"));
    }
    return new FlatFileQuery(this);
  }
  
  public void commit()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void rollback()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setLocale(ULocale locale)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public int getMaxQueries()
    throws OdaException
  {
    return 0;
  }
  
  public char getDelimeter()
  {
    return delimiter;
  }
  
  public String getCharSet()
  {
    return charSet;
  }
  
  public boolean hasTypeLine()
  {
    return hasTypeLine;
  }
  
  public boolean hasColumnNames()
  {
    return hasColumnNames;
  }
  
  public boolean trailNullColumns()
  {
    return trailNullColumns;
  }
  
  public String getHomeFolder()
  {
    return homeFolder;
  }
  
  public String getFileURI()
  {
    return fileURI;
  }
  
  public ResourceInputStream getInputStream(String tableName)
    throws OdaException
  {
    if ((ri == null) && (appContext != null))
    {
      Object resource = appContext.get("org.eclipse.datatools.connectivity.oda.util_consumerResourceIds");
      if (resource != null) {
        ri = resource;
      }
    }
    return ResourceLocator.getResourceInputStream(homeFolder, tableName, fileURI, ri);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.Connection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
import org.eclipse.datatools.connectivity.oda.IResultSet;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.flatfile.i18n.Messages;

public class DataSetMetaData
  implements IDataSetMetaData
{
  private IConnection connection;
  
  DataSetMetaData(IConnection conn)
  {
    connection = conn;
  }
  
  public IConnection getConnection()
    throws OdaException
  {
    return connection;
  }
  
  public IResultSet getDataSourceObjects(String catalog, String schema, String object, String version)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public int getDataSourceMajorVersion()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public int getDataSourceMinorVersion()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public String getDataSourceProductName()
    throws OdaException
  {
    return Messages.getString("dataSetMetaData_PRODUCT_NAME");
  }
  
  public String getDataSourceProductVersion()
    throws OdaException
  {
    return "3.0";
  }
  
  public int getSQLStateType()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean supportsMultipleOpenResults()
    throws OdaException
  {
    return false;
  }
  
  public boolean supportsMultipleResultSets()
    throws OdaException
  {
    return false;
  }
  
  public boolean supportsNamedResultSets()
    throws OdaException
  {
    return false;
  }
  
  public boolean supportsNamedParameters()
    throws OdaException
  {
    return false;
  }
  
  public boolean supportsInParameters()
    throws OdaException
  {
    return false;
  }
  
  public boolean supportsOutParameters()
    throws OdaException
  {
    return false;
  }
  
  public int getSortMode()
  {
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.DataSetMetaData
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.flatfile.i18n.Messages;
import org.eclipse.datatools.connectivity.oda.util.manifest.DataSetType;
import org.eclipse.datatools.connectivity.oda.util.manifest.DataTypeMapping;
import org.eclipse.datatools.connectivity.oda.util.manifest.ExtensionManifest;
import org.eclipse.datatools.connectivity.oda.util.manifest.ManifestExplorer;

public final class DataTypes
{
  static final int STRING = 12;
  static final int NULL = 0;
  static final String NULL_LITERAL = "NULL";
  private static final String FLATFILE_DATA_SOURCE_ID = "org.eclipse.datatools.connectivity.oda.flatfile";
  
  public static int getTypeCode(String typeName)
    throws OdaException
  {
    if ((typeName == null) || (typeName.trim().length() == 0)) {
      return 12;
    }
    String preparedTypeName = typeName.trim().toUpperCase();
    if (preparedTypeName.equals("NULL")) {
      return 0;
    }
    DataTypeMapping typeMapping = getManifest().getDataSetType(null)
      .getDataTypeMapping(preparedTypeName);
    if (typeMapping != null) {
      return typeMapping.getNativeTypeCode();
    }
    throw new OdaException(
      Messages.getString("dataTypes_TYPE_NAME_INVALID") + typeName);
  }
  
  public static boolean isValidType(String typeName)
  {
    String preparedTypeName = typeName.trim().toUpperCase();
    if (preparedTypeName.equals("NULL")) {
      return true;
    }
    DataTypeMapping typeMapping = null;
    try
    {
      typeMapping = 
        getManifest().getDataSetType(null).getDataTypeMapping(preparedTypeName);
    }
    catch (OdaException localOdaException) {}
    return typeMapping != null;
  }
  
  static ExtensionManifest getManifest()
    throws OdaException
  {
    return 
      ManifestExplorer.getInstance().getExtensionManifest("org.eclipse.datatools.connectivity.oda.flatfile");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.DataTypes
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IDriver;
import org.eclipse.datatools.connectivity.oda.LogConfiguration;
import org.eclipse.datatools.connectivity.oda.OdaException;

public class FlatFileDriver
  implements IDriver
{
  public IConnection getConnection(String dataSourceId)
    throws OdaException
  {
    return new Connection();
  }
  
  public int getMaxConnections()
    throws OdaException
  {
    return 0;
  }
  
  public void setAppContext(Object context)
    throws OdaException
  {}
  
  public void setLogConfiguration(LogConfiguration logConfig)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.FlatFileDriver
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PushbackInputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.flatfile.i18n.Messages;

public class FlatFileQuery$FlatFileBufferedReader
{
  private Reader reader;
  private char[] charBuffer;
  private static int CHARBUFFSIZE = 8192;
  private char separator;
  private int endIndex;
  private int currentIndex;
  
  public FlatFileQuery$FlatFileBufferedReader(InputStream in, String encoding, char seperator)
    throws IOException
  {
    initReader(in, encoding);
    separator = seperator;
    endIndex = -1;
    currentIndex = -1;
    charBuffer = new char[CHARBUFFSIZE];
  }
  
  private void initReader(InputStream in, String encoding)
    throws IOException
  {
    if ("UTF-8".equals(encoding))
    {
      PushbackInputStream internalInputStream = new PushbackInputStream(in, 3);
      byte[] bom = new byte[3];
      int len = internalInputStream.read(bom);
      if ((len != 3) || 
        (bom[0] != -17) || 
        (bom[1] != -69) || 
        (bom[2] != -65)) {
        if (len > 0) {
          internalInputStream.unread(bom, 0, len);
        }
      }
      reader = new BufferedReader(new InputStreamReader(internalInputStream, encoding));
    }
    else
    {
      reader = new BufferedReader(new InputStreamReader(in, encoding));
    }
  }
  
  public List<String> readLine()
    throws OdaException
  {
    int newLineStartIndex = currentIndex + 1;
    StringBuffer column = new StringBuffer();
    boolean doubleQuoted = false;
    if (!next()) {
      return null;
    }
    List<String> result = new ArrayList();
    do
    {
      char curChar = getChar();
      if (!doubleQuoted)
      {
        if (curChar == separator)
        {
          result.add(getColumnValue(column));
          column.setLength(0);
        }
        else if (curChar == '"')
        {
          if (column.toString().trim().length() > 0) {
            throw new OdaException(Messages.getString("invalid_flatfile_format"));
          }
          doubleQuoted = true;
          column.setLength(0);
          column.append('"');
        }
        else
        {
          if (curChar == '\n')
          {
            if (currentIndex != newLineStartIndex) {
              result.add(getColumnValue(column));
            }
            return result;
          }
          column.append(curChar);
        }
      }
      else
      {
        moveToEndQuotation(column);
        moveToEndOfColumn();
        doubleQuoted = false;
      }
    } while (
    
      next());
    result.add(getColumnValue(column));
    return result;
  }
  
  private void moveToEndOfColumn()
    throws OdaException
  {
    if (next())
    {
      char curChar = getChar();
      if ((curChar == separator) || (curChar == '\n'))
      {
        back();
        return;
      }
      if (isAnEmptyChar(curChar)) {
        moveToEndOfColumn();
      } else {
        throw new OdaException(Messages.getString("invalid_flatfile_format"));
      }
    }
  }
  
  private void moveToEndQuotation(StringBuffer column)
    throws OdaException
  {
    do
    {
      char curChar = getChar();
      if (curChar == '"')
      {
        if (next())
        {
          curChar = getChar();
          if (curChar == '"')
          {
            column.append('"');
          }
          else
          {
            back();
            column.append('"');
          }
        }
        else
        {
          column.append('"');
        }
      }
      else {
        column.append(curChar);
      }
    } while (
    
      next());
    throw new OdaException(Messages.getString("invalid_flatfile_format"));
  }
  
  private boolean next()
    throws OdaException
  {
    if (currentIndex < endIndex)
    {
      currentIndex += 1;
      return true;
    }
    try
    {
      int len = reader.read(charBuffer);
      if (len <= 0) {
        return false;
      }
      currentIndex = 0;
      endIndex = (len - 1);
      return true;
    }
    catch (IOException e)
    {
      throw new OdaException(e);
    }
  }
  
  private void back()
  {
    if (currentIndex >= 0) {
      currentIndex -= 1;
    }
  }
  
  private char getChar()
  {
    return charBuffer[currentIndex];
  }
  
  private String getColumnValue(StringBuffer column)
  {
    if ((column.length() >= 2) && 
      (column.charAt(0) == '"') && 
      (column.charAt(column.length() - 1) == '"')) {
      return column.substring(1, column.length() - 1);
    }
    return column.toString().trim();
  }
  
  private boolean isAnEmptyChar(char c)
  {
    return String.valueOf(c).trim().equals("");
  }
  
  public void close()
    throws IOException
  {
    charBuffer = null;
    reader.close();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.flatfile.FlatFileQuery.FlatFileBufferedReader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.flatfile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PushbackInputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IParameterMetaData;
import org.eclipse.datatools.connectivity.oda.IQuery;
import org.eclipse.datatools.connectivity.oda.IResultSet;
import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.SortSpec;
import org.eclipse.datatools.connectivity.oda.flatfile.i18n.Messages;
import org.eclipse.datatools.connectivity.oda.flatfile.util.FlatFileDataReader;
import org.eclipse.datatools.connectivity.oda.flatfile.util.querytextutil.QueryTextUtil;
import org.eclipse.datatools.connectivity.oda.spec.QuerySpecification;

public class FlatFileQuery
  implements IQuery
{
  public static final int DEFAULT_MAX_ROWS = 1000;
  private static final String NAME_LITERAL = "NAME";
  private static final String TYPE_LITERAL = "TYPE";
  private boolean hasColumnNames;
  private boolean hasTypeLine;
  private String currentTableName = null;
  private int maxRows = 0;
  private Connection connection = null;
  private ResultSetMetaData resultSetMetaData = null;
  private ResultSetMetaDataHelper resultSetMetaDataHelper = null;
  
  public FlatFileQuery(IConnection host)
    throws OdaException
  {
    if ((host == null) || (
      (((Connection)host).getHomeFolder() == null) && (((Connection)host).getFileURI() == null))) {
      throw new OdaException(Messages.getString("common_ARGUMENT_CANNOT_BE_NULL"));
    }
    connection = ((Connection)host);
    extractsHasColumnNamesInfo();
    extractsHasColumnTypeLineInfo();
  }
  
  private void extractsHasColumnNamesInfo()
  {
    hasColumnNames = connection.hasColumnNames();
  }
  
  private void extractsHasColumnTypeLineInfo()
  {
    hasTypeLine = connection.hasTypeLine();
  }
  
  public void prepare(String queryText)
    throws OdaException
  {
    if (queryText != null)
    {
      QueryTextUtil qtu = new QueryTextUtil(queryText);
      String query = qtu.getQuery();
      String colInfo = qtu.getColumnsInfo();
      validateOpenConnection();
      String formattedQuery = formatQueryText(query);
      prepareMetaData(formattedQuery, colInfo);
    }
    else
    {
      throw new OdaException(Messages.getString("common_NULL_QUERY_TEXT"));
    }
  }
  
  public void setAppContext(Object context)
    throws OdaException
  {}
  
  public void setProperty(String name, String value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void close()
    throws OdaException
  {
    currentTableName = null;
    maxRows = 0;
    connection = null;
    resultSetMetaData = null;
  }
  
  public void setMaxRows(int max)
    throws OdaException
  {
    maxRows = max;
  }
  
  public int getMaxRows()
    throws OdaException
  {
    return maxRows;
  }
  
  public IResultSetMetaData getMetaData()
    throws OdaException
  {
    return resultSetMetaData;
  }
  
  public IResultSet executeQuery()
    throws OdaException
  {
    return new ResultSet(new FlatFileDataReader(connection, 
      currentTableName, 
      maxRows, 
      resultSetMetaData, 
      resultSetMetaDataHelper), 
      resultSetMetaData);
  }
  
  public void cancel()
    throws OdaException, UnsupportedOperationException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setInt(String parameterName, int value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setInt(int parameterId, int value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setDouble(String parameterName, double value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setDouble(int parameterId, double value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setBigDecimal(String parameterName, BigDecimal value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setBigDecimal(int parameterId, BigDecimal value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setString(String parameterName, String value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setString(int parameterId, String value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setDate(String parameterName, Date value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setDate(int parameterId, Date value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setTime(String parameterName, Time value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setTime(int parameterId, Time value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setTimestamp(String parameterName, Timestamp value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setTimestamp(int parameterId, Timestamp value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setBoolean(String parameterName, boolean value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setBoolean(int parameterId, boolean value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setObject(int parameterId, Object value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setObject(String parameterName, Object value)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setNull(String parameterName)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setNull(int parameterId)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public int findInParameter(String parameterName)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public IParameterMetaData getParameterMetaData()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void clearInParameters()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setSortSpec(SortSpec sortBy)
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public SortSpec getSortSpec()
    throws OdaException
  {
    throw new UnsupportedOperationException();
  }
  
  public void setSpecification(QuerySpecification querySpec)
    throws OdaException, UnsupportedOperationException
  {
    throw new UnsupportedOperationException();
  }
  
  public QuerySpecification getSpecification()
  {
    return null;
  }
  
  public String getEffectiveQueryText()
  {
    throw new UnsupportedOperationException();
  }
  
  private void validateOpenConnection()
    throws OdaException
  {
    if (!connection.isOpen()) {
      throw new OdaException(Messages.getString("common_CONNECTION_IS_NOT_OPEN"));
    }
  }
  
  private void validateNonEmptyQueryText(String formattedQuery)
    throws OdaException
  {
    if ((formattedQuery == null) || (formattedQuery.length() == 0)) {
      throw new OdaException(Messages.getString("query_COMMAND_IS_EMPTY"));
    }
  }
  
  private void validateSingleTableQuery(String[] parsedQuerySegments)
    throws OdaException
  {
    if (getPreparedTableNames(parsedQuerySegments).split(",").length != 1) {
      throw new OdaException(Messages.getString("query_DO_NOT_SUPPORT_CROSS_TABLE_QUERY"));
    }
  }
  
  private String getPreparedColumnNames(String[] parsedQueryFragments)
  {
    return parsedQueryFragments[0];
  }
  
  private String getPreparedColumnLabels(String[] parsedQueryFragments)
  {
    return parsedQueryFragments[1];
  }
  
  private String getPreparedTableNames(String[] parsedQueryFragments)
  {
    return parsedQueryFragments[2];
  }
  
  private String[] parsePreparedQueryText(String formattedQuery)
    throws OdaException
  {
    return QueryTextUtil.getQueryMetaData(formattedQuery);
  }
  
  private Vector<String> getQueryColumnNamesVector(String queryColumnNames)
  {
    Vector<String> result = new Vector();
    char[] chars = queryColumnNames.toCharArray();
    List<Integer> indiceList = new ArrayList();
    boolean inQuote = false;
    boolean isEscaped = false;
    int beginIndex = 0;
    int endIndex = 0;
    for (int i = 0; i < chars.length; i++) {
      if (chars[i] == '"')
      {
        if (!isEscaped) {
          inQuote = !inQuote;
        } else {
          isEscaped = !isEscaped;
        }
      }
      else if (chars[i] == '\\') {
        isEscaped = !isEscaped;
      } else if (chars[i] == ',') {
        if (!inQuote) {
          indiceList.add(new Integer(i));
        }
      }
    }
    if (indiceList.size() > 0) {
      for (int j = 0; j < indiceList.size(); j++)
      {
        endIndex = ((Integer)indiceList.get(j)).intValue();
        
        result.add(queryColumnNames.substring(beginIndex, 
          endIndex).trim());
        beginIndex = endIndex + 1;
        if (j == indiceList.size() - 1) {
          result.add(queryColumnNames.substring(beginIndex, 
            queryColumnNames.length()).trim());
        }
      }
    } else {
      result.add(queryColumnNames);
    }
    return result;
  }
  
  private Vector<String> stripFormatInfoFromQueryColumnNames(Vector<String> queryColumnNames)
  {
    Vector<String> columnNames = new Vector();
    
    boolean isEscaped = false;
    for (int i = 0; i < queryColumnNames.size(); i++)
    {
      StringBuffer sb = new StringBuffer();
      char[] chars = ((String)queryColumnNames.get(i)).toCharArray();
      if (chars[0] != '"')
      {
        columnNames.add((String)queryColumnNames.get(i));
      }
      else
      {
        for (int j = 0; j < chars.length; j++) {
          if (chars[j] == '"')
          {
            if (isEscaped)
            {
              sb.append(chars[j]);
              isEscaped = !isEscaped;
            }
          }
          else if (chars[j] == '\\')
          {
            if (isEscaped) {
              sb.append(chars[j]);
            }
            isEscaped = !isEscaped;
          }
          else
          {
            sb.append(chars[j]);
          }
        }
        columnNames.add(sb.toString());
      }
    }
    return columnNames;
  }
  
  private String[] createTempColumnNames(int columnCount)
  {
    String[] tempColumnNames = new String[columnCount];
    for (int i = 0; i < columnCount; i++) {
      tempColumnNames[i] = ("COLUMN_" + (i + 1));
    }
    return tempColumnNames;
  }
  
  private String[] createTempColumnTypes(int columnCount)
  {
    String[] tempColumnTypes = new String[columnCount];
    for (int i = 0; i < columnCount; i++) {
      tempColumnTypes[i] = "STRING";
    }
    return tempColumnTypes;
  }
  
  private String[] discoverActualColumnMetaData(String tableName, String metaDataType)
    throws OdaException
  {
    FlatFileDataReader ffdsr = new FlatFileDataReader(connection, 
      tableName, 
      0, 
      null, 
      null);
    try
    {
      if ((!metaDataType.trim().equalsIgnoreCase("NAME")) && 
        (!metaDataType.trim().equalsIgnoreCase("TYPE"))) {
        throw new OdaException(Messages.getString("query_ARGUMENT_ERROR"));
      }
      while ((metaDataType.trim().equalsIgnoreCase("TYPE")) && 
      
        (FlatFileDataReader.isEmptyRow(ffdsr.readLine()))) {}
      List<String> columnNameLine;
      while (FlatFileDataReader.isEmptyRow(columnNameLine = ffdsr.readLine())) {}
      String[] result = ffdsr.getColumnNameArray(columnNameLine);
      if (metaDataType.trim().equalsIgnoreCase("NAME")) {
        validateUniqueName(result);
      }
      if (metaDataType.trim().equalsIgnoreCase("TYPE")) {
        validateColumnTypeConsistency(result);
      }
      return trimStringArray(result);
    }
    finally
    {
      ffdsr.clearBufferedReader();
    }
  }
  
  private String[] trimStringArray(String[] array)
  {
    String[] result = new String[array.length];
    for (int i = 0; i < result.length; i++) {
      result[i] = array[i].trim();
    }
    return result;
  }
  
  private void validateColumnName(String[] cCN, String[] aCN)
    throws OdaException
  {
    for (int i = 0; i < cCN.length; i++) {
      if (findOccuranceOfValueInStringArray(cCN[i], aCN) != 1) {
        throw new OdaException(Messages.getString("query_COMMAND_NOT_VALID"));
      }
    }
  }
  
  private boolean isWildCard(String cCN)
  {
    if (cCN.equalsIgnoreCase("*")) {
      return true;
    }
    return false;
  }
  
  private void validateUniqueName(String[] aCN)
    throws OdaException
  {
    for (int i = 0; i < aCN.length; i++) {
      if (findOccuranceOfValueInStringArray(aCN[i], aCN) > 1) {
        throw new OdaException(Messages.getString("query_SOURCE_DATA_ERROR"));
      }
    }
  }
  
  private void validateColumnTypeConsistency(String[] aCT)
    throws OdaException
  {
    if (!hasTypeLine) {
      return;
    }
    for (int i = 0; i < aCT.length; i++) {
      if (!DataTypes.isValidType(aCT[i])) {
        throw new OdaException(Messages.getString("dataTypes_TYPE_NAME_INVALID") + aCT[i]);
      }
    }
  }
  
  private int findOccuranceOfValueInStringArray(String value, String[] array)
  {
    int count = 0;
    for (int i = 0; i < array.length; i++) {
      if (value.trim().equalsIgnoreCase(array[i].trim())) {
        count++;
      }
    }
    return count;
  }
  
  private void prepareMetaData(String query, String savedSelectedColInfo)
    throws OdaException
  {
    validateNonEmptyQueryText(query);
    
    String[] queryFragments = parsePreparedQueryText(query);
    
    validateSingleTableQuery(queryFragments);
    
    String tableName = getPreparedTableNames(queryFragments);
    
    FlatFileDataReader ffdsr = new FlatFileDataReader(connection, tableName, 0, null, null);
    
    String[] allColumnNames = hasColumnNames ? 
      discoverActualColumnMetaData(tableName, "NAME") : 
      createTempColumnNames(ffdsr.getColumnCount());
    
    String[] allColumnTypes = hasTypeLine ? 
      discoverActualColumnMetaData(tableName, "TYPE") : 
      createTempColumnTypes(ffdsr.getColumnCount());
    if (allColumnNames.length != allColumnTypes.length) {
      throw new OdaException(Messages.getString("invalid_flatfile_format"));
    }
    String[] queryColumnNames = (String[])null;
    String[] queryColumnTypes = (String[])null;
    String[] queryColumnLables = (String[])null;
    if (isWildCard(getPreparedColumnNames(queryFragments)))
    {
      queryColumnNames = allColumnNames;
      queryColumnTypes = allColumnTypes;
      queryColumnLables = allColumnNames;
      resultSetMetaDataHelper = new ResultSetMetaDataHelper(queryColumnNames, 
        queryColumnTypes, 
        queryColumnLables);
      resultSetMetaData = new ResultSetMetaData(resultSetMetaDataHelper);
    }
    else
    {
      queryColumnNames = FlatFileDataReader.getStringArrayFromList(stripFormatInfoFromQueryColumnNames(getQueryColumnNamesVector(getPreparedColumnNames(queryFragments))));
      validateColumnName(queryColumnNames, allColumnNames);
      if ((savedSelectedColInfo == null) || 
        (savedSelectedColInfo.length() == 0))
      {
        queryColumnTypes = hasTypeLine ? 
          getQueryColumnTypes(allColumnNames, 
          allColumnTypes, 
          queryColumnNames) : 
          createTempColumnTypes(queryColumnNames.length);
        queryColumnLables = hasColumnNames ? 
          getColumnLabels(queryFragments) : queryColumnNames;
        if (queryColumnLables == null) {
          queryColumnLables = queryColumnNames;
        }
        resultSetMetaDataHelper = new ResultSetMetaDataHelper(queryColumnNames, 
          queryColumnTypes, 
          queryColumnLables);
        resultSetMetaData = new ResultSetMetaData(resultSetMetaDataHelper);
      }
      else
      {
        resultSetMetaDataHelper = new ResultSetMetaDataHelper(savedSelectedColInfo);
        resultSetMetaData = new ResultSetMetaData(resultSetMetaDataHelper);
      }
    }
    currentTableName = tableName;
  }
  
  private String[] getQueryColumnTypes(String[] allColumnNames, String[] allColumnTypes, String[] queryColumnNames)
  {
    if (!hasTypeLine) {
      return null;
    }
    String[] queryColumnTypes = new String[queryColumnNames.length];
    for (int i = 0; i < queryColumnNames.length; i++) {
      for (int j = 0; j < allColumnNames.length; j++) {
        if (queryColumnNames[i].trim().equalsIgnoreCase(allColumnNames[j]))
        {
          queryColumnTypes[i] = allColumnTypes[j];
          break;
        }
      }
    }
    return queryColumnTypes;
  }
  
  private String[] getColumnLabels(String[] queryFragments)
  {
    String queryColumnLabels = getPreparedColumnLabels(queryFragments);
    return queryColumnLabels != null ? 
      queryColumnLabels.split(",") : 
      null;
  }
  
  private String formatQueryText(String queryText)
  {
    StringBuffer result = new StringBuffer();
    String[] temp = queryText.trim()
      .split(" ");
    for (int i = 0; i < temp.length; i++)
    {
      if (temp[i].equalsIgnoreCase("AS")) {
        temp[i] = temp[i].toUpperCase();
      }
      if (temp[i].equalsIgnoreCase("FROM")) {
        temp[i] = temp[i].toUpperCase();
      }
      if (temp[i].equalsIgnoreCase("SELECT")) {
        temp[i] = temp[i].toUpperCase();
      }
      result.append(temp[i]).append(" ");
    }
    return result.toString().trim();
  }
  
  public static class FlatFileBufferedReader
  {
    private Reader reader;
    private char[] charBuffer;
    private static int CHARBUFFSIZE = 8192;
    private char separator;
    private int endIndex;
    private int currentIndex;
    
    public FlatFileBufferedReader(InputStream in, String encoding, char seperator)
      throws IOException
    {
      initReader(in, encoding);
      separator = seperator;
      endIndex = -1;
      currentIndex = -1;
      charBuffer = new char[CHARBUFFSIZE];
    }
    
    private void initReader(InputStream in, String encoding)
      throws IOException
    {
      if ("UTF-8".equals(encoding))
      {
        PushbackInputStream internalInputStream = new PushbackInputStream(in, 3);
        byte[] bom = new byte[3];
        int len = internalInputStream.read(bom);
        if ((len != 3) || 
          (bom[0] != -17) || 
          (bom[1] != -69) || 
          (bom[2] != -65)) {
          if (len > 0) {
            internalInputStream.unread(bom, 0, len);
          }
        }
        reader = new BufferedReader(new InputStreamReader(internalInputStream, encoding));
      }
      else
      {
        reader = new BufferedReader(new InputStreamReader(in, encoding));
      }
    }
    
    public List<String> readLine()
      throws OdaException
    {
      int newLineStartIndex = currentIndex + 1;
      StringBuffer column = new StringBuffer();
      boolean doubleQuoted = false;
      if (!next()) {
        return null;
      }
      List<String> result = new ArrayList();
      do
      {
        char curChar = getChar();
        if (!doubleQuoted)
        {
          if (curChar == separator)
          {
            result.add(getColumnValue(column));
            column.setLength(0);
          }
          else if (curChar == '"')
          {
            if (column.toString().trim().length() > 0) {
              throw new OdaException(Messages.getString("invalid_flatfile_format"));
            }
            doubleQuoted = true;
            column.setLength(0);
            column.append('"');
          }
          else
          {
            if (curChar == '\n')
            {
              if (currentIndex != 
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd