コード例 #1
0
ファイル: TsResultSet.cs プロジェクト: bastie/NetVampire
        /*
         * This method sets the initial state of the ResultSet, including adding
         * any grouping or ordering information.  If the ResultSet contains
         * summary functions, then a single row is added to the ResultSet initially.
         * If no rows are found that match any specified where clauses, this initial
         * row will be returned.
         */
        public void setState(int pstate, java.util.Hashtable <Object, Object> ptables,
                             String inputOrderType, bool inputDistinct)
        //throws tinySQLException
        {
            int      i;
            TsRow    record = new TsRow();
            TsColumn initializeColumn;

            sTables   = ptables;
            orderType = inputOrderType;
            distinct  = inputDistinct;
            level     = pstate;
            if (groupedColumns)
            {
                /*
                 *       Initialize the ResultSet with any not null summary functions
                 *       such as COUNT = 0
                 */
                for (i = 0; i < rsColumns.size(); i++)
                {
                    initializeColumn = (TsColumn)rsColumns.elementAt(i);

                    /*
                     *          Evaluate all functions before adding the
                     *          column to the output record.
                     */
                    initializeColumn.updateFunctions();
                    if (initializeColumn.isNotNull())
                    {
                        record.put(initializeColumn.name, initializeColumn.getString());
                    }
                }
                addRow(record);
            }
        }
コード例 #2
0
        internal override void CreateTable(String tableName, java.util.Vector <Object> v)
        {//    throws IOException, tinySQLException {
            //---------------------------------------------------
            // determin meta data ....
            int numCols      = v.size();
            int recordLength = 1;        // 1 byte for the flag field

            for (int i = 0; i < numCols; i++)
            {
                TsColumn coldef = ((TsColumn)v.elementAt(i));
                recordLength += coldef.size;
            }

            //---------------------------------------------------
            // create the new dBase file ...
            DBFHeader dbfHeader = new DBFHeader(numCols, recordLength);

            java.io.RandomAccessFile ftbl = dbfHeader.create(dataDir, tableName);

            //---------------------------------------------------
            // write out the rest of the columns' definition.
            for (int i = 0; i < v.size(); i++)
            {
                TsColumn coldef = ((TsColumn)v.elementAt(i));
                Utils.log("CREATING COL=" + coldef.name);
                writeColdef(ftbl, coldef);
            }

            ftbl.write((byte)0x0d); // header section ends with CR (carriage return)

            ftbl.close();
        }
コード例 #3
0
ファイル: SimpleXMLTag.cs プロジェクト: bastie/NetVampire
 /*
  * Return a particular tag by its index in the hierarchy.
  */
 public SimpleXMLTag getTag(int inputIndex)
 {
     if (inputIndex <0 | inputIndex> tagList.size() - 1)
     {
         return((SimpleXMLTag)null);
     }
     return((SimpleXMLTag)tagList.elementAt(inputIndex));
 }
コード例 #4
0
        public override void getData(Buffer buf)
        {
            setRecipient(buf.getInt());
            setRemoteWindowSize(buf.getInt());
            setRemotePacketSize(buf.getInt());
            byte[] addr = buf.getString();
            int    port = buf.getInt();

            byte[] orgaddr = buf.getString();
            int    orgport = buf.getInt();

            /*
             * System.out.println("addr: "+new String(addr));
             * System.out.println("port: "+port);
             * System.out.println("orgaddr: "+new String(orgaddr));
             * System.out.println("orgport: "+orgport);
             */

            lock (pool)
            {
                for (int i = 0; i < pool.size(); i++)
                {
                    Object[] foo = (Object[])(pool.elementAt(i));
                    if (foo[0] != session)
                    {
                        continue;
                    }
                    if (((Integer)foo[1]).intValue() != port)
                    {
                        continue;
                    }
                    this.rport  = port;
                    this.target = (String)foo[2];
                    if (foo[3] == null || (foo[3] is Object[]))
                    {
                        this.lport = -1;
                    }
                    else
                    {
                        this.lport = ((Integer)foo[3]).intValue();
                    }
                    if (foo.Length >= 5)
                    {
                        this.factory = ((SocketFactory)foo[4]);
                    }
                    break;
                }
                if (target == null)
                {
                    Console.WriteLine("??");
                }
            }
        }
コード例 #5
0
        /**
         *
         * Return a tinySQLTable object, given a table name.
         *
         * @param tableName
         * @see tinySQL#getTable
         *
         */
        internal override TinySQLTable getTable(String tableName) //throws tinySQLException
        {
            int          i, tableIndex;
            TinySQLTable nextTable;

            tableIndex = java.lang.Integer.MIN_VALUE;
            if (TinySQLGlobals.DEBUG)
            {
                java.lang.SystemJ.outJ.println("Trying to create table"
                                               + " object for " + tableName);
            }
            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (nextTable.table.equals(tableName))
                {
                    if (nextTable.isOpen())
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Found in cache " + nextTable.toString());
                        }
                        return(nextTable);
                    }
                    tableIndex = i;
                    break;
                }
            }
            if (tableIndex == java.lang.Integer.MIN_VALUE)
            {
                tableList.addElement(new DBFFileTable(dataDir, tableName));
                nextTable = (TinySQLTable)tableList.lastElement();
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Add to cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.lastElement());
            }
            else
            {
                tableList.setElementAt(new DBFFileTable(dataDir, tableName), tableIndex);
                nextTable = (TinySQLTable)tableList.elementAt(tableIndex);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Update in cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.elementAt(tableIndex));
            }
        }
コード例 #6
0
        /**
         *
         * Close any result sets. This is not used by tinySQL.
         * @see java.sql.PreparedStatement#close
         *
         */
        public void close() //throws SQLException
        {
            int          i;
            TinySQLTable nextTable;

            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("Closing " + nextTable.table);
                }
                nextTable.close();
            }
        }
コード例 #7
0
ファイル: TsColumn.cs プロジェクト: bastie/NetVampire
        /*
         * This method checks to see if the column has the specified context.
         */
        public String contextToString()
        {
            java.lang.StringBuffer outputBuffer = new java.lang.StringBuffer();
            int i;

            for (i = 0; i < contextList.size(); i++)
            {
                if (i > 0)
                {
                    outputBuffer.append(",");
                }
                outputBuffer.append((String)contextList.elementAt(i));
            }
            return(outputBuffer.toString());
        }
コード例 #8
0
ファイル: Channel.cs プロジェクト: swzry/tamir.ssh
 public static Channel getChannel(int id, Session session)
 {
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             Channel c = (Channel)(pool.elementAt(i));
             if (c.id == id && c.session == session)
             {
                 return(c);
             }
         }
     }
     return(null);
 }
コード例 #9
0
 public static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             Object[] bar = (Object[])(pool.elementAt(i));
             if (bar[0] != session)
             {
                 continue;
             }
             if (bar[3] == null)
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":");
             }
             else
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":" + bar[3]);
             }
         }
     }
     String[] bar2 = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar2[i] = (String)(foo.elementAt(i));
     }
     return(bar2);
 }
コード例 #10
0
        /**
         * Return the first implementation that has the desired
         * features, or <code>null</code> if none is found.
         *
         * @param features
         *            A string that specifies which features are required. This is
         *            a space separated list in which each feature is specified by
         *            its name optionally followed by a space and a version number.
         *            This is something like: "XML 1.0 Traversal +Events 2.0"
         * @return An implementation that has the desired features,
         *         or <code>null</code> if none found.
         */
        public DOMImplementation getDOMImplementation(String features)
        {
            int size = sources.size();

            //String name = null; Basties Note: unused...
            for (int i = 0; i < size; i++)
            {
                DOMImplementationSource source =
                    (DOMImplementationSource)sources.elementAt(i);
                DOMImplementation impl = source.getDOMImplementation(features);
                if (impl != null)
                {
                    return(impl);
                }
            }
            return(null);
        }
コード例 #11
0
        /*
         * Format a where condition for display.
         */
        private String conditionToString(java.util.Vector <Object> inputWhereCondition)
        {
            String   comparison, conditionStatus;
            TsColumn leftColumn, rightColumn;

            if (inputWhereCondition.size() < 4)
            {
                return("");
            }
            java.lang.StringBuffer outputBuffer = new java.lang.StringBuffer("WHERE ");
            leftColumn      = (TsColumn)inputWhereCondition.elementAt(0);
            comparison      = (String)inputWhereCondition.elementAt(1);
            rightColumn     = (TsColumn)inputWhereCondition.elementAt(2);
            conditionStatus = (String)inputWhereCondition.elementAt(3);
            outputBuffer.append(leftColumn.getString() + " " + comparison
                                + " " + rightColumn.getString() + " " + conditionStatus);
            return(outputBuffer.toString());
        }
コード例 #12
0
        /*
         * This method returns the column to build an index on.  This is very
         * primitive and only works on a single column that is compared to
         * to a constant.
         */
        public java.util.Vector <Object> getIndexCondition(String inputTableName)
        {
            int i, j;

            java.util.Vector <Object> whereConditions;
            TsColumn leftColumn, rightColumn;
            Object   whereObj;
            String   objectType, comparison;

            java.util.Vector <Object> whereCondition;
            java.lang.StringBuffer    outputBuffer = new java.lang.StringBuffer();
            for (i = 0; i < whereClauseList.size(); i++)
            {
                whereConditions = (java.util.Vector <Object>)whereClauseList.elementAt(i);
                for (j = 0; j < whereConditions.size(); j++)
                {
                    /*
                     *          Where conditions can be tinySQLWhere objects or String arrays.
                     */
                    whereObj   = whereConditions.elementAt(j);
                    objectType = whereObj.getClass().getName();
                    if (objectType.endsWith("java.util.Vector"))
                    {
                        whereCondition = (java.util.Vector <Object>)whereObj;
                        leftColumn     = (TsColumn)whereCondition.elementAt(0);
                        comparison     = (String)whereCondition.elementAt(1);
                        rightColumn    = (TsColumn)whereCondition.elementAt(2);
                        if (leftColumn.tableName.equals(inputTableName) &
                            rightColumn.isConstant & comparison.equals("="))
                        {
                            return(whereCondition);
                        }
                        else if (leftColumn.tableName.equals(inputTableName) &
                                 rightColumn.isConstant & comparison.equals("="))
                        {
                            return(whereCondition);
                        }
                    }
                }
            }
            return((java.util.Vector <Object>)null);
        }
コード例 #13
0
        /**
         * Creates a table given the name and a vector of
         * column definition (tsColumn) arrays.<br>
         *
         * @param table_name the name of the table
         * @param v a Vector containing arrays of column definitions.
         * @see tinySQL#CreateTable
         */
        internal override void CreateTable(String table_name, java.util.Vector <Object> v)
        {//throws IOException, tinySQLException {
            // make the data directory, if it needs to be make
            //
            mkDataDirectory();

            // perform an implicit drop table.
            //
            DropTable(table_name);

            // create the table definition file
            //
            java.io.FileOutputStream fdef =
                new java.io.FileOutputStream(dataDir + "/" + table_name + ".def");

            // open it as a DataOutputStream
            //
            java.io.DataOutputStream def = new java.io.DataOutputStream(fdef);

            // write out the column definition for the _DELETED column
            //
            def.writeBytes("CHAR|_DELETED|1\n");

            // write out the rest of the columns' definition. The
            // definition consists of datatype, column name, and
            // size delimited by a pipe symbol
            //
            for (int i = 0; i < v.size(); i++)
            {
                def.writeBytes(((TsColumn)v.elementAt(i)).type + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).name + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).size + "\n");
            }

            // flush the DataOutputStream and jiggle the handle
            //
            def.flush();

            // close the file
            //
            fdef.close();
        }
コード例 #14
0
ファイル: TsResultSet.cs プロジェクト: bastie/NetVampire
 public TsColumn columnAtIndex(int i, bool allColumns)
 {
     if (allColumns)
     {
         return((TsColumn)rsColumns.elementAt(i));
     }
     else
     {
         return((TsColumn)selectColumns.elementAt(i));
     }
 }
コード例 #15
0
ファイル: TinySQLGlobals.cs プロジェクト: bastie/NetVampire
        /*
         * This method checks for the existence of a short column name for the
         * input name.  If one does not exist it is created.
         */
        public static String getShortName(String inputColumnName)
        {
            String shortColumnName = (String)null, longColumnName;
            int    i;

            if (inputColumnName.length() < 12)
            {
                return(inputColumnName);
            }
            for (i = 0; i < longColumnNames.size(); i += 2)
            {
                longColumnName = (String)longColumnNames.elementAt(i + 1);
                if (longColumnName.equalsIgnoreCase(inputColumnName))
                {
                    shortColumnName = (String)longColumnNames.elementAt(i);
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Return " + shortColumnName);
                    }
                    return(shortColumnName);
                }
            }
            if (shortColumnName == (String)null)
            {
                /*
                 *       A short name has not been set up for this long name yet.
                 */
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("Generate short name for " + inputColumnName);
                }
                return(addLongName(inputColumnName));
            }
            return(inputColumnName);
        }
コード例 #16
0
ファイル: TsRow.cs プロジェクト: bastie/NetVampire
        public int compareTo(Object inputObj)
        {
            String   tableColumnName, thisString, inputString;
            TsColumn columnObject;
            TsRow    inputRow;
            int      i, columnType;
            double   thisValue, inputValue;

            if (orderByColumns == (java.util.Vector <Object>)null)
            {
                return(0);
            }
            inputRow = (TsRow)inputObj;
            for (i = 0; i < orderByColumns.size(); i++)
            {
                columnObject    = (TsColumn)orderByColumns.elementAt(i);
                tableColumnName = columnObject.name;
                columnType      = columnObject.type;
                thisString      = (String)get(tableColumnName);
                inputString     = (String)inputRow.get(tableColumnName);
                if (Utils.isCharColumn(columnType) |
                    Utils.isDateColumn(columnType))
                {
                    if (thisString == (String)null | inputString == (String)null)
                    {
                        continue;
                    }
                    if (thisString.compareTo(inputString) != 0)
                    {
                        return(thisString.compareTo(inputString));
                    }
                }
                else if (Utils.isNumberColumn(columnType))
                {
                    thisValue  = UtilString.doubleValue(thisString);
                    inputValue = UtilString.doubleValue(inputString);
                    if (thisValue > inputValue)
                    {
                        return(1);
                    }
                    else if (thisValue < inputValue)
                    {
                        return(-1);
                    }
                }
                else
                {
                    java.lang.SystemJ.outJ.println("Cannot sort unknown type");
                }
            }
            return(0);
        }
コード例 #17
0
        /*
         *  Update the actions based upon the contents of the substitute Vector.
         *  Only INSERT and UPDATE commands are supported at this time.
         */
        public void updateActions(java.util.Vector <Object> inputActions) //throws SQLException
        {
            java.util.Vector <Object>            values, originalValues;
            java.util.Hashtable <Object, Object> action;
            String actionType, valueString;
            int    i, j, subCount;

            if (actions == null)
            {
                actions = inputActions;
            }
            if (actions == null)
            {
                return;
            }
            for (i = 0; i < actions.size(); i++)
            {
                action     = (java.util.Hashtable <Object, Object>)actions.elementAt(i);
                actionType = (String)action.get("TYPE");
                if (actionType.equals("INSERT") | actionType.equals("UPDATE"))
                {
                    /*
                     *           Look for the original values (with the ? for parameters).
                     */
                    originalValues = (java.util.Vector <Object>)action.get("ORIGINAL_VALUES");
                    values         = (java.util.Vector <Object>)action.get("VALUES");
                    if (originalValues == (java.util.Vector <Object>)null)
                    {
                        originalValues = (java.util.Vector <Object>)values.clone();
                        action.put("ORIGINAL_VALUES", originalValues);
                    }
                    subCount = 0;
                    for (j = 0; j < originalValues.size(); j++)
                    {
                        valueString = (String)originalValues.elementAt(j);
                        if (valueString.equals("?"))
                        {
                            if (subCount > substitute.size() - 1)
                            {
                                throw new java.sql.SQLException("Substitution index " + subCount
                                                                + " not between 0 and "
                                                                + java.lang.Integer.toString(substitute.size() - 1));
                            }
                            values.setElementAt(substitute.elementAt(subCount), j);
                            subCount++;
                        }
                    }
                }
            }
        }
コード例 #18
0
        /*
         * Execute an SQL Select Statement
         */
        protected virtual TsResultSet SelectStatement(java.util.Hashtable <Object, Object> t, java.util.Vector <Object> c,
                                                      TinySQLWhere w, String ot, bool distinct, Object stmt)
        //throws TinySQLException
        {
            java.util.Hashtable <Object, Object> tables;
            java.util.Vector <Object>            tableList;
            TsResultSet jrs;
            TsColumn    columnObject;
            int         i;

            /*
             *    Instantiate a new, empty tsResultSet
             */
            jrs            = new TsResultSet(w, this);
            groupFunctions = new java.util.Hashtable <Object, Object>();
            try
            {
                jrs.setFetchSize(((TinySQLStatement)stmt).getFetchSize());
                jrs.setType(((TinySQLStatement)stmt).getResultSetType());
            }
            catch (java.sql.SQLException)
            {
                Utils.log("Caught SQLException while setting Fetchsize and ResultSetType");
                Utils.log("   This event is (should be) impossible!");
            }
            tables    = t;
            tableList = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");

            /*
             *    Add the column objects to the ResultSet.
             */
            for (i = 0; i < c.size(); i++)
            {
                columnObject = (TsColumn)c.elementAt(i);

                /*
                 *       The column object is now added to the ResultSet
                 */
                jrs.addColumn(columnObject);
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("Adding "
                                                   + columnObject.contextToString()
                                                   + " column " + newLine + columnObject.toString() + newLine);
                }
            }
            jrs.setState(1, tables, ot, distinct);
            contSelectStatement(jrs);
            return(jrs);
        }
コード例 #19
0
 public DOMImplementation item(int index)
 {
     if (index >= 0 && index < implementations.size())
     {
         try
         {
             return((DOMImplementation)
                    implementations.elementAt(index));
         }
         catch (java.lang.ArrayIndexOutOfBoundsException)
         {
             return(null);
         }
     }
     return(null);
 }
コード例 #20
0
 /**
  *
  * Updates the current row in the table.
  *
  * @param c Ordered Vector of column names
  * @param v Ordered Vector (must match order of c) of values
  * @see tinySQLTable#UpdateCurrentRow
  *
  */
 public override void UpdateCurrentRow(java.util.Vector <Object> c, java.util.Vector <Object> v)
 {// throws tinySQLException {
     // the Vectors v and c are expected to have the
     // same number of elements. It is also expected
     // that the elements correspond to each other,
     // such that value 1 of Vector v corresponds to
     // column 1 of Vector c, and so forth.
     //
     for (int i = 0; i < v.size(); i++)
     {
         // get the column name and the value, and
         // invoke UpdateCol() to update it.
         //
         String column = (String)c.elementAt(i);
         String value  = (String)v.elementAt(i);
         UpdateCol(column, value);
     }
 }
コード例 #21
0
        /**
         * Indicates whether this permissions collection implies a specific
         * {@code permission}.
         *
         * @param permission
         *            the permission to check.
         * @see java.security.PermissionCollection#implies(java.security.Permission)
         */

        public override bool implies(java.security.Permission permission)
        {
            if (permission is FilePermission)
            {
                FilePermission fp          = (FilePermission)permission;
                int            matchedMask = 0;
                int            i           = 0;
                while (i < permissions.size() &&
                       ((matchedMask & fp.mask) != fp.mask))
                {
                    // Cast will not fail since we added it
                    matchedMask |= ((FilePermission)permissions.elementAt(i))
                                   .impliesMask(permission);
                    i++;
                }
                return((matchedMask & fp.mask) == fp.mask);
            }
            return(false);
        }
コード例 #22
0
        /*
         * Find the input table alias in the list provided and return the table name
         * and alias in the form tableName=tableAlias.
         */
        public static String findTableAlias(String inputAlias, java.util.Vector <Object> tableList)
        //throws tinySQLException
        {
            int    i, aliasAt;
            String tableAndAlias, tableName, tableAlias;

            for (i = 0; i < tableList.size(); i++)
            {
                tableAndAlias = (String)tableList.elementAt(i);
                aliasAt       = tableAndAlias.indexOf("->");
                tableName     = tableAndAlias.substring(0, aliasAt);
                tableAlias    = tableAndAlias.substring(aliasAt + 2);
                if (inputAlias.equals(tableAlias))
                {
                    return(tableAndAlias);
                }
            }
            throw new TinySQLException("Unable to identify table alias "
                                       + inputAlias);
        }
コード例 #23
0
ファイル: DBFFileTable.cs プロジェクト: bastie/NetVampire
 /*
  * Updates the current row in the table.
  *
  * @param c Ordered Vector of column names
  * @param v Ordered Vector (must match order of c) of values
  * @see tinySQLTable#UpdateCurrentRow
  */
 public override void UpdateCurrentRow(java.util.Vector <Object> c, java.util.Vector <Object> v) //throws TinySQLException
 {
     /*
      *    The Vectors v and c are expected to have the
      *    same number of elements. It is also expected
      *    that the elements correspond to each other,
      *    such that value 1 of Vector v corresponds to
      *    column 1 of Vector c, and so forth.
      */
     for (int i = 0; i < v.size(); i++)
     {
         /*
          *       Get the column name and the value, and
          *       invoke UpdateCol() to update it.
          */
         String column = ((String)c.elementAt(i)).toUpperCase();
         String value  = (String)v.elementAt(i);
         UpdateCol(column, value);
     }
 }
コード例 #24
0
ファイル: TsResultSet.cs プロジェクト: bastie/NetVampire
        public void addColumn(TsColumn col)
        {
            int          i;
            bool         addTable;
            TinySQLTable checkTable;

            rsColumns.addElement(col);
            if (col.getContext("SELECT"))
            {
                selectColumns.addElement(col);
            }
            if (col.getContext("ORDER"))
            {
                orderByColumns.addElement(col);
            }
            if (col.isGroupedColumn())
            {
                groupedColumns = true;
            }

            /*
             *    Add the table that this column belongs to if required
             */
            addTable = true;
            if (col.columnTable != (TinySQLTable)null)
            {
                for (i = 0; i < tables.size(); i++)
                {
                    checkTable = (TinySQLTable)tables.elementAt(i);
                    if (checkTable.table.equals(col.columnTable.table))
                    {
                        addTable = false;
                        break;
                    }
                }
                if (addTable)
                {
                    tables.addElement(col.columnTable);
                }
            }
        }
コード例 #25
0
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					PortWatcher p=(PortWatcher)(pool.elementAt(i));
					if(p.session==session)
					{
						foo.addElement(p.lport+":"+p.host+":"+p.rport);
					}
				}
			}
			String[] bar=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar[i]=(String)(foo.elementAt(i));
			}
			return bar;
		}
コード例 #26
0
ファイル: PortWatcher.cs プロジェクト: weimingtom/pap2
 internal static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             PortWatcher p = (PortWatcher)(pool.elementAt(i));
             if (p.session == session)
             {
                 foo.addElement(p.lport + ":" + p.host + ":" + p.rport);
             }
         }
     }
     String[] bar = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar[i] = (String)(foo.elementAt(i));
     }
     return(bar);
 }
コード例 #27
0
        /*
         * Move the input table to the top of the selection list.
         */
        public static void setPriority(java.util.Vector <Object> inputList, String inputTable)
        {
            String tableName;
            int    i;

            if (inputList == null)
            {
                return;
            }
            for (i = 0; i < inputList.size(); i++)
            {
                tableName = (String)inputList.elementAt(i);
                if (tableName.equals(inputTable))
                {
                    if (i > 0)
                    {
                        inputList.removeElementAt(i);
                        inputList.insertElementAt(tableName, 0);
                    }
                    break;
                }
            }
        }
コード例 #28
0
        /*
         * Validate the column specifications by checking against the tables.
         */
        public void validateColumns() //throws TinySQLException
        {
            String       columnName, columnAlias, columnContext;
            TsColumn     columnObject;
            bool         selectStar;
            TinySQLTable jtbl;
            int          i, j;

/*
 *    Check for a column named *
 */
            selectStar = false;
            for (i = 0; i < columnList.size(); i++)
            {
                columnName    = (String)columnList.elementAt(i);
                columnContext = (String)contextList.elementAt(i);
                if (columnName.equals("*"))
                {
                    if (!columnContext.equals("SELECT"))
                    {
                        throw new TinySQLException("* must be a SELECT column.");
                    }
                    selectStar = true;
                    break;
                }
            }
            if (selectStar)
            {
/*
 *       A column * has been found.  Delete the existing list of SELECT
 *       columns and replace by using an enumeration variable to cycle through
 *       the columns in the tables Hashtable.
 */
                for (i = 0; i < columnList.size(); i++)
                {
                    columnContext = (String)contextList.elementAt(i);
                    if (columnContext.equals("SELECT"))
                    {
                        columnList.removeElementAt(i);
                        contextList.removeElementAt(i);
                        columnAliasList.removeElementAt(i);
                    }
                }
                for (i = 0; i < tableList.size(); i++)
                {
                    jtbl = (TinySQLTable)tables.get((String)tableList.elementAt(i));

/*
 *          Expand to all columns.
 */
                    for (j = 0; j < jtbl.columnNameKeys.size(); j++)
                    {
                        columnName = (String)jtbl.columnNameKeys.elementAt(j);
                        columnList.addElement(jtbl.table + "->" + jtbl.tableAlias
                                              + "." + columnName);
                        columnAliasList.addElement(columnName);
                        contextList.addElement("SELECT");
                    }
                }
            }

/*
 *    Build a column object for each selected column.
 */
            if (tables == (java.util.Hashtable <Object, Object>)null)
            {
                java.lang.SystemJ.outJ.println("*****Column validation - no tables defined.");
            }
            for (i = 0; i < columnList.size(); i++)
            {
                columnName    = (String)columnList.elementAt(i);
                columnContext = (String)contextList.elementAt(i);
                columnAlias   = (String)null;
                if (i < columnAliasList.size())
                {
                    columnAlias = (String)columnAliasList.elementAt(i);
                }
                columnObject       = new TsColumn(columnName, tables, columnContext);
                columnObject.alias = UtilString.removeQuotes(columnAlias);
                columns.addElement(columnObject);
            }
        }
コード例 #29
0
        /*
         * Create the tinySQLTable object, then insert a row, and update
         * it with the c and v Vectors
         */
        private void InsertStatement(String statementType, String tableName,
                                     java.util.Vector <Object> c, java.util.Vector <Object> v)
        //throws TinySQLException
        {
            String columnName, valueString;
            int    i, columnType, columnSize;
            double value;

            insertTable = getTable(tableName);

            /*
             *    Check that the values supplied are the correct type and length.
             */
            for (i = 0; i < c.size(); i++)
            {
                columnName  = (String)c.elementAt(i);
                valueString = (String)v.elementAt(i);
                if (valueString == (String)null)
                {
                    continue;
                }
                valueString = UtilString.removeQuotes(valueString);
                valueString = UtilString.replaceAll(valueString, "''", "'");
                columnType  = insertTable.ColType(columnName);
                if (Utils.isNumberColumn(columnType))
                {
                    try
                    {
                        value = java.lang.Double.parseDouble(valueString);
                    }
                    catch (Exception)
                    {
                        throw new TinySQLException("Insert failed: column "
                                                   + columnName + " is numeric - found " + valueString);
                    }
                }
                else if (Utils.isDateColumn(columnType))
                {
                    try
                    {
                        /*
                         *             Modify the input to be the standard YYYYMMDD format
                         */
                        if (valueString.trim().length() > 0)
                        {
                            v.setElementAt(UtilString.dateValue(valueString), i);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new TinySQLException("Insert failed: " + e.getMessage());
                    }
                }
                columnSize = insertTable.ColSize(columnName);
                if (valueString.length() > columnSize)
                {
                    throw new TinySQLException("Insert failed: string too long for "
                                               + " column " + columnName + " "
                                               + java.lang.Integer.toString(valueString.length())
                                               + " > " + java.lang.Integer.toString(columnSize) + "<" + valueString + ">");
                }
            }
            insertTable.InsertRow(c, v);

            /*
             *    Close the table file that has just been updated unless this is a
             *    PreparedStatement.  In that case an explicit close must be done
             *    on the statement object to close any open files.
             */
            if (!statementType.endsWith("tinySQLPreparedStatement"))
            {
                insertTable.close();
            }
        }
コード例 #30
0
        /*
         * Support function for restartable queries. Continue to
         * read the query result. The current state is taken from
         * tsResultSet. Proceed until maxFetchSize has reached.
         */
        protected internal virtual void contSelectStatement(TsResultSet jrs)
        //throws TinySQLException
        {
            /*
             *    The table scan here is an iterative tree expansion, similar to
             *    the algorithm shown in the outline example in Chapter 5.
             */
            String       columnName, columnString, whereStatus, tableAndAlias;
            bool         addOK;
            int          i;
            int          level = jrs.getLevel();
            TinySQLTable jtbl;
            TsColumn     updateColumn;

            java.util.Hashtable <Object, Object> tables = jrs.getTableState();
            TinySQLWhere wc = jrs.getWhereClause();

            /*
             *    Create a hashtable to enumerate the tables to be scanned and initialize
             *    with the first table name.
             */
            java.util.Hashtable <Object, Object> tbl_list = new java.util.Hashtable <Object, Object>();
            java.util.Vector <Object>            t        = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");
            String current = (String)t.elementAt(0);

            tbl_list.put(current, new java.lang.Integer(1));

            /*
             *    Create a row object; this is added to the ResultSet.
             */
            TsRow record = new TsRow();

            java.util.Vector <Object> resultSet = new java.util.Vector <Object>();

            /*
             *    Keep retrieving rows until we run out of rows to process.
             */
            while (level > 0)
            {
                bool levelFound = false;

                /*
                 *       Find an item within the tbl_list which has the same level as the
                 *       one we're on.
                 */
                java.util.Enumeration <Object> keys = tbl_list.keys();
                while (keys.hasMoreElements())
                {
                    /*
                     *          Get the next element in the "to be processed"
                     *          Hashtable, and find out its level, storing this
                     *          value in currLevel.
                     */
                    String hashkey   = (String)keys.nextElement();
                    int    currLevel = ((java.lang.Integer)tbl_list.get(hashkey)).intValue();

                    /*
                     *          As soon as an element is found whose level is equal to the
                     *          one currently being processed, grab it's primary key (the hashkey),
                     *          flag levelfound, and break!
                     */
                    if (currLevel == level)
                    {
                        current = hashkey; levelFound = true; break;
                    }
                }
                bool haveRecord = false; // did we get a record or not?

                /*
                 *       If a table was found at the current level, then we should
                 *       try to get another row from it.
                 */
                if (levelFound)
                {
                    /*
                     *          Get the current table
                     */
                    jtbl          = (TinySQLTable)tables.get(current);
                    tableAndAlias = jtbl.table + "->" + jtbl.tableAlias;
                    if (TinySQLGlobals.WHERE_DEBUG)
                    {
                        java.lang.SystemJ.outJ.println("Processing level " + level
                                                       + " table " + tableAndAlias + "\n");
                    }

                    /*
                     *          The following code is the start of setting up simple indexes
                     *          for tinySQL.  The concept involves creating a new tinySQLCondition
                     *          class, instances of which will be created by tinySQLWhere.  At least
                     *          initially only conditions that are equal to a constant will be
                     *          considered.  One of these conditions will be stored inside the
                     *          dbfFileTable object. Calls to NextRecord would then have to add
                     *          logic to check to see if an index exists.  The presence of a
                     *          complete index would be indicated by a counter that was equal
                     *          to the number of rows in the table.  In that case a single get
                     *          would deliver the record numbers required for the where condition.
                     *          The NextRecord function would return these record numbers in
                     *          sequence.  If the index did not exist then new values in the
                     *          index Hashtable would be created.  None of this code has been
                     *          developed or implemented, let alone tested.
                     *
                     *
                     *          if ( wc != (tinySQLWhere)null )
                     *             jtbl.setIndexCondition(wc.getIndexCondition(tableAndAlias));
                     */
                    if (performDebug)
                    {
                        java.lang.SystemJ.outJ.println("Selecting records from "
                                                       + jtbl.table);
                    }

                    /*
                     *          Skip to the next undeleted record; at some point,
                     *          this will run out of records, and found will be false.
                     */
                    bool found = false;
                    while (jtbl.NextRecord())
                    {
                        /*
                         *             Clear the column values for this table before starting
                         *             to process the next row.
                         */
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);
                            updateColumn.clear(tableAndAlias);
                        }
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        if (!jtbl.isDeleted())
                        {
                            /*
                             *                Evaluate the where clause for each column in the table.  If
                             *                it is false, skip to the next row.  Otherwise, add the
                             *                column value to the output record.
                             */
                            java.util.Enumeration <Object> cols = jtbl.column_info.keys();
                            found       = true;
                            whereStatus = "TRUE";
                            while (cols.hasMoreElements())
                            {
                                columnName = tableAndAlias + "."
                                             + (String)cols.nextElement();
                                columnString = jtbl.GetCol(columnName);
                                if (wc != (TinySQLWhere)null)
                                {
                                    whereStatus = wc.evaluate(columnName, columnString);
                                    if (whereStatus.equals("FALSE"))
                                    {
                                        /*
                                         *                         This column value caused the where clause to
                                         *                         be FALSE.  Go to the next row in the table.
                                         */
                                        found = false;
                                        break;
                                    }
                                }

                                /*
                                 *                   Update the ResultSet tsColumn values
                                 */
                                jrs.updateColumns(columnName, columnString);
                            }

                            /*
                             *                If no where condition has evaluated to false then this
                             *                record is a candidate for output.  Break to the next table
                             *                in this case for further WHERE processing.
                             */
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Build candidate record.");
                        }
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);

                            /*
                             *                Evaluate all functions before adding the
                             *                column to the output record.
                             */
                            updateColumn.updateFunctions();
                            columnString = updateColumn.getString();
                            if (updateColumn.isNotNull())
                            {
                                record.put(updateColumn.name, columnString);
                            }
                            else
                            {
                                record.remove(updateColumn.name);
                            }
                        }
                        if (performDebug)
                        {
                            java.lang.SystemJ.outJ.println("Record is " + record.toString());
                        }

                        /*
                         *             If the table we are processing is not the last in
                         *             the list, then we should increment level and loop to the top.
                         */
                        if (level < t.size())
                        {
                            /*
                             *                Increment level
                             */
                            level++;

                            /*
                             *                Add the next table in the list of tables to
                             *                the tbl_list, the Hashtable of "to be processed" tables.
                             */
                            String next_tbl = (String)t.elementAt(level - 1);
                            tbl_list.put(next_tbl, new java.lang.Integer(level));
                        }
                        else
                        {
                            /*
                             *                If the table that was just processed is the last in
                             *                the list, then we have drilled down to the bottom;
                             *                all columns have values, and we can add it to the
                             *                result set. The next time through, the program
                             *                will try to read another row at this level; if it's
                             *                found, only columns for the table being read will
                             *                be overwritten in the tsRow.
                             *
                             *                Columns for the other table will be left alone, and
                             *                another row will be added to the result set. Here
                             *                is the essence of the Cartesian Product which is
                             *                being built here.
                             */
                            haveRecord = true;
                        }
                    }
                    else
                    {
                        /*
                         *             We didn't find any more records at this level.
                         *             Reset the record pointer to the top of the table,
                         *             and decrement level. We have hit end of file here.
                         */
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        level--;
                        jtbl.GoTop();
                    }
                }
                else
                {
                    /*
                     *          No tables were found at this level; back up a level
                     *          and see if there's any up there.
                     */
                    level--;
                }

                /*
                 *       If we got a record, then add it to the result set.
                 */
                if (haveRecord)
                {
                    /*
                     *          If group functions are involved, add records only after a break,
                     *          which is defined as a change in all of the group columns.
                     *          Otherwise, update the current record.
                     */
                    if (jrs.isGrouped())
                    {
                        if (groupBreak)
                        {
                            addOK = jrs.addRow((TsRow)record.clone());
                            if (addOK == false)
                            {
                                jrs.setLevel(level);
                                return;
                            }
                            groupBreak = false;
                        }
                        else
                        {
                            jrs.updateRow((TsRow)record.clone());
                        }
                    }
                    else
                    {
                        /*
                         *             No group functions are involved.  Just add the record.
                         */
                        addOK = jrs.addRow((TsRow)record.clone());
                        if (addOK == false)
                        {
                            jrs.setLevel(level);
                            return;
                        }
                    }
                }
            }

            /*
             *    Close all the tables
             */
            for (i = 0; i < t.size(); i++)
            {
                jtbl = (TinySQLTable)tables.get((String)t.elementAt(i));
                jtbl.close();
            }

            /*
             *    return a result set
             */
            jrs.setLevel(0);
        }
コード例 #31
0
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					Object[] bar=(Object[])(pool.elementAt(i));
					if(bar[0]!=session) continue;
					if(bar[3]==null){ foo.addElement(bar[1]+":"+bar[2]+":"); }
					else{ foo.addElement(bar[1]+":"+bar[2]+":"+bar[3]); }
				}
			}
			String[] bar2=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar2[i]=(String)(foo.elementAt(i));
			}
			return bar2;
		}
コード例 #32
0
        /*
         * Gets a description of tables available in a catalog.
         *
         * Only table descriptions matching the catalog, schema, table
         * name and type criteria are returned.  They are ordered by
         * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
         *
         * Each table description has the following columns:
         *
         * TABLE_CAT String => table catalog (may be null)
         * TABLE_SCHEM String => table schema (may be null)
         * TABLE_NAME String => table name
         * TABLE_TYPE String => table type.  Typical types are "TABLE",
         *      "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
         *      "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
         * REMARKS String => explanatory comment on the table
         *
         * Note: Some databases may not return information for
         * all tables.
         *
         * @param catalog a catalog name; "" retrieves those without a
         * catalog; null means drop catalog name from the selection criteria
         * THIS VALUE IS IGNORED
         * @param schemaPattern THIS VALUE IS IGNORED
         * @param tableNamePattern a table name pattern, ´null´ or "%" delivers all
         *                         token will be handled as substrings
         * @param types a list of table types to include; null returns all DBF types
         *              only "TABLE" is supported, others like "VIEW", "SYSTEM TABLE", "SEQUENCE"
         *              are ignored.
         * @return ResultSet - each row is a table description
         * @exception SQLException if a database access error occurs
         * @see #getSearchStringEscape
         *
         * @author Thomas Morgner <*****@*****.**> Fill all needed columns, or some query tools will crash :(
         */
        public override java.sql.ResultSet getTables(String catalog, String schemaPattern,
                                                     String tableNamePattern, String[] types)
        {
            String dataDir = getDataDir();
            String tableName;

            java.io.File tableFile;
            TsColumn     jsc;
            int          i, dotAt;

            if (dataDir == null)
            {
                return(null);
            }
            if (types == null)
            {
                types    = new String[1];
                types[0] = "TABLE";
            }
            TsResultSet jrs = new TsResultSet();

            /*
             *    Create the header for the tables ResultSet
             */
            try
            {
                jsc      = new TsColumn("TABLE_CAT");
                jsc.type = java.sql.Types.CHAR;    // CHAR max 254 bytes
                jsc.size = 10;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TABLE_SCHEM");
                jsc.type = java.sql.Types.CHAR;    // CHAR max 254 bytes
                jsc.size = 10;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TABLE_NAME");
                jsc.type = java.sql.Types.CHAR;    // CHAR max 254 bytes
                jsc.size = 10;
                jrs.addColumn(jsc);

                jsc            = new TsColumn("TABLE_TYPE");
                jsc.type       = java.sql.Types.CHAR; // CHAR max 254 bytes
                jsc.size       = 40;
                jsc.defaultVal = "TABLE";
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TABLE_REMARKS");
                jsc.type = java.sql.Types.CHAR;    // CHAR max 254 bytes
                jsc.size = 254;
                jrs.addColumn(jsc);

                /*
                 *       Add the MetaData by examining all the DBF files in the current
                 *       directory.
                 */
                for (int itype = 0; itype < types.Length; itype++)
                {
                    String type = types[itype];
                    if (type == null)
                    {
                        continue;
                    }
                    String extension = null;
                    if (type.equalsIgnoreCase("TABLE"))
                    {
                        extension = DBFFileTable.dbfExtension; // ".DBF";
                    }
                    if (extension == null)
                    {
                        continue;
                    }
                    java.util.Vector <Object> vec = Utils.getAllFiles(dataDir, extension);
                    for (i = 0; i < vec.size(); i++)
                    {
                        tableFile = (java.io.File)vec.elementAt(i);
                        tableName = tableFile.getName().toUpperCase();
                        dotAt     = tableName.indexOf(".");
                        if (dotAt > -1)
                        {
                            tableName = tableName.substring(0, dotAt);
                        }
                        if (tableNamePattern == null)
                        {
                            tableNamePattern = "%";
                        }
                        if (tableNamePattern.equals("%") |
                            tableName.equalsIgnoreCase(tableNamePattern))
                        {
                            if (tableName.length() > jsc.size)
                            {
                                jsc.size = tableName.length();
                            }
                            TsRow record = new TsRow();
                            record.put("TABLE_NAME", tableName.toUpperCase());
                            record.put("TABLE_TYPE", "TABLE");
                            jrs.addRow(record);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                java.lang.SystemJ.outJ.println("Unable to create MetaData");
                java.lang.SystemJ.outJ.println(ex.ToString());// ex.printStackTrace(System.out);
            }

            // This Resultset is not created by an statement
            return(new TinySQLResultSet(jrs, (TinySQLStatement)null));
        }