/* * Given a column name, and a Hashtable containing tables, determine * which table "owns" a given column. */ private TinySQLTable getTableForColumn(java.util.Hashtable <Object, Object> tables, String inputColumn) { TinySQLTable tbl; java.util.Vector <Object> tableNames; java.util.Hashtable <Object, Object> columnInfo; String findColumn, tableAndAlias = (String)null, tableAlias; int i, dotAt; findColumn = inputColumn.toUpperCase(); dotAt = findColumn.indexOf("."); tableNames = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER"); if (dotAt > -1) { tableAlias = findColumn.substring(0, dotAt); try { tableAndAlias = UtilString.findTableAlias(tableAlias, tableNames); } catch (Exception) { } if (tableAndAlias != (String)null) { tbl = (TinySQLTable)tables.get(tableAndAlias); if (tbl != (TinySQLTable)null) { return(tbl); } } } else { for (i = 0; i < tableNames.size(); i++) { tbl = (TinySQLTable)tables.get((String)tableNames.elementAt(i)); /* * Get the Hashtable containing column information, and see if it * contains the column we're looking for. */ columnInfo = tbl.column_info; if (columnInfo != (java.util.Hashtable <Object, Object>)null) { if (columnInfo.containsKey(findColumn)) { return(tbl); } } } } return((TinySQLTable)null); }
private void _GetGlossesUsingReflection() { com.articulate.sigma.WordNet wn = SUMO.WordNet.Intern; FieldInfo nounType = wn.GetType().GetField("nounDocumentationHash", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo verbType = wn.GetType().GetField("verbDocumentationHash", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo adjType = wn.GetType().GetField("adjectiveDocumentationHash", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo advType = wn.GetType().GetField("adverbDocumentationHash", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); java.util.Hashtable nounHash = (java.util.Hashtable)nounType.GetValue(wn); java.util.Hashtable verbHash = (java.util.Hashtable)verbType.GetValue(wn); java.util.Hashtable adjHash = (java.util.Hashtable)adjType.GetValue(wn); java.util.Hashtable advHash = (java.util.Hashtable)advType.GetValue(wn); _glosses = new Hashtable(); _glosses.Add(SpeechTypes.Noun, nounHash.get(_id) == null ? "" : nounHash.get(_id)); _glosses.Add(SpeechTypes.Verb, verbHash.get(_id) == null ? "" : verbHash.get(_id)); _glosses.Add(SpeechTypes.Adjective, adjHash.get(_id) == null ? "" : adjHash.get(_id)); _glosses.Add(SpeechTypes.Adverb, advHash.get(_id) == null ? "" : advHash.get(_id)); }
/* * 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); }
public void testOneElementHashtableKeyEnumerator() { java.util.Hashtable <String, String> nameWert = new java.util.Hashtable <String, String>(); nameWert.put("1", "one"); java.util.Enumeration <String> names = nameWert.keys(); Assert.True(names.hasMoreElements()); String one = names.nextElement(); Assert.AreEqual("1", one); one = nameWert.get(one); Assert.AreEqual("one", one); Assert.False(names.hasMoreElements()); }
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { lock (this){ if ((propertyName != null) && (listener != null)) { PropertyChangeSupport listeners = children.get(propertyName); if (listeners != null) { listeners.removePropertyChangeListener(listener); } } } }
private void initOutputFiles()//throws FileNotFoundException, IOException { { while (true) { // try to find a unique file which is not locked by other process uniqueID++; // FIXME: improve performance here for (int generation = 0; generation < count; generation++) { // cache all file names for rotation use files[generation] = new java.io.File(parseFileName(generation)); } fileName = files[0].getAbsolutePath(); lock (allLocks) { /* * if current process has held lock for this fileName continue * to find next file */ if (null != allLocks.get(fileName)) { continue; } if (files[0].exists() && (!append || files[0].length() >= limit)) { for (int i = count - 1; i > 0; i--) { if (files[i].exists()) { files[i].delete(); } files[i - 1].renameTo(files[i]); } } java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName + LCK_EXT); java.nio.channels.FileChannel channel = fileStream.getChannel(); /* * if lock is unsupported and IOException thrown, just let the * IOException throws out and exit otherwise it will go into an * undead cycle */ lockJ = channel.tryLock(); if (null == lockJ) { try { fileStream.close(); } catch (Exception e) { // ignore } continue; } allLocks.put(fileName, lockJ); break; } } output = new MeasureOutputStream(new java.io.BufferedOutputStream( new java.io.FileOutputStream(fileName, append)), files[0].length()); setOutputStream(output); }
public void validateTable(String tableSpec, bool closeTable) //throws TinySQLException { /* * Create a table object for each table used in the SELECT statement * and store these objects in the tables Hashtable. Save the original * list of table names to set the default selection order. * * If closeTable is true the table object will be closed after it is * validated (for DROP TABLE and ALTER TABLE commands). */ String tableName, tableAlias, tableNameAndAlias, sortName; TinySQLTable addTable, sortTable; bool tableAdded; FieldTokenizer ftTable; int i, addRowCount, sortRowCount; ftTable = new FieldTokenizer(tableSpec, ' ', false); tableName = ftTable.getField(0); tableAlias = (ftTable.getField(1, tableName)).toUpperCase(); tableNameAndAlias = tableName + "->" + tableAlias; addTable = dbEngine.getTable(tableNameAndAlias); addTable.GoTop(); addRowCount = addTable.GetRowCount(); if (closeTable) { addTable.close(); } if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("Add table " + tableNameAndAlias + " to tables"); } tables.put(tableNameAndAlias, addTable); tableAdded = false; for (i = 0; i < tableList.size(); i++) { sortName = (String)tableList.elementAt(i); sortTable = (TinySQLTable)tables.get(sortName); sortRowCount = sortTable.GetRowCount(); /* * Sort the table selections from smallest to largest table to * enhance the query performance. */ if (addRowCount > sortRowCount) { continue; } tableList.insertElementAt(tableNameAndAlias, i); tableAdded = true; break; } if (!tableAdded) { tableList.addElement(tableNameAndAlias); } if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("Table selection order"); for (i = 0; i < tableList.size(); i++) { sortName = (String)tableList.elementAt(i); sortTable = (TinySQLTable)tables.get(sortName); sortRowCount = sortTable.GetRowCount(); java.lang.SystemJ.outJ.println(sortName + " " + sortRowCount); } } }
/* * 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); }
/** * Gets a description of table columns available in * the specified catalog. * * <P>Only column descriptions matching the catalog, schema, table * and column name criteria are returned. They are ordered by * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION. * * <P>Each column description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)sRow record = new TsRow(); * * <LI><B>TABLE_NAME</B> String => table name * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types * <LI><B>TYPE_NAME</B> String => Data source dependent type name, * for a UDT the type name is fully qualified * <LI><B>COLUMN_SIZE</B> int => column size. For char or date * types this is the maximum number of characters, for numeric or * decimal types this is precision. * <LI><B>BUFFER_LENGTH</B> is not used. * <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits * <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2) * <LI><B>NULLABLE</B> int => is NULL allowed? * <UL> * <LI> columnNoNulls - might not allow NULL values * <LI> columnNullable - definitely allows NULL values * <LI> columnNullableUnknown - nullability unknown * </UL> * <LI><B>REMARKS</B> String => comment describing column (may be null) * <LI><B>COLUMN_DEF</B> String => default value (may be null) * <LI><B>SQL_DATA_TYPE</B> int => unused * <LI><B>SQL_DATETIME_SUB</B> int => unused * <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the * maximum number of bytes in the column * <LI><B>ORDINAL_POSITION</B> int => index of column in table * (starting at 1) * <LI><B>IS_NULLABLE</B> String => "NO" means column definitely * does not allow NULL values; "YES" means the column might * allow NULL values. An empty string means nobody knows. * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param tableNamePattern a table name pattern * @param columnNamePattern a column name pattern * @return ResultSet - each row is a column description * @exception SQLException if a database access error occurs * @see #getSearchStringEscape */ public override java.sql.ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) { int i; String columnNameKey; try { String dataDir = getDataDir(); Utils.log("Entering getColumns(tableNamePattern='" + tableNamePattern + "')"); if (dataDir == null) { return(null); } java.sql.ResultSet tableRs = getTables(catalog, schemaPattern, tableNamePattern, null); TsResultSet jrs = new TsResultSet(); TsColumn jsc = new TsColumn("TABLE_CAT"); jsc.type = java.sql.Types.CHAR; jsc.size = 9; jrs.addColumn(jsc); jsc = new TsColumn("TABLE_SCHEM"); jsc.type = java.sql.Types.CHAR; jsc.size = 11; jrs.addColumn(jsc); jsc = new TsColumn("TABLE_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 10; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 11; jrs.addColumn(jsc); jsc = new TsColumn("DATA_TYPE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 6; jrs.addColumn(jsc); jsc = new TsColumn("TYPE_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 9; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_SIZE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("BUFFER_LENGTH"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("DECIMAL_DIGITS"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("NUM_PREC_RADIX"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("NULLABLE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("REMARKS"); jsc.type = java.sql.Types.CHAR; jsc.size = 128; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_DEF"); jsc.type = java.sql.Types.CHAR; jsc.size = 128; jrs.addColumn(jsc); jsc = new TsColumn("SQL_DATA_TYPE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 128; jrs.addColumn(jsc); // Several parameters missing. jsc = new TsColumn("IS_NULLABLE"); jsc.type = java.sql.Types.CHAR; jsc.size = 3; jrs.addColumn(jsc); while (tableRs.next()) { // process each DBF file and extract column info ... String tableName = tableRs.getString("TABLE_NAME"); DBFFileTable tbl; try { tbl = new DBFFileTable(dataDir, tableName); } catch (Exception) { continue; // ignore buggy and empty (zero byte size) DBF files } Utils.log("Accessing column info for table " + tableName); java.util.Hashtable <Object, Object> column_info = tbl.column_info; for (i = 0; i < tbl.columnNameKeys.size(); i++) { columnNameKey = (String)tbl.columnNameKeys.elementAt(i); TsColumn tsc = (TsColumn)column_info.get(columnNameKey); // process each column of the current table ... TsRow record = new TsRow(); record.put("TABLE_CAT", ""); record.put("TABLE_SCHEM", ""); record.put("TABLE_NAME", tableName); record.put("COLUMN_NAME", TinySQLGlobals.getLongName(tsc.name)); record.put("DATA_TYPE", new java.lang.Integer(tsc.type).toString()); record.put("TYPE_NAME", DBFFile.typeToLiteral(tsc.type).toString()); record.put("COLUMN_SIZE", new java.lang.Integer(tsc.size).toString()); record.put("DECIMAL_DIGITS", new java.lang.Integer(tsc.decimalPlaces).toString()); int nullable = columnNoNulls; if (tsc.notNull == true) { nullable = columnNullable; } record.put("NULLABLE", new java.lang.Integer(nullable).toString()); record.put("REMARKS", "noRemarks"); String defaultVal = tsc.defaultVal; if (defaultVal == null) { defaultVal = ""; } record.put("COLUMN_DEF", defaultVal); String isNullable = "NO"; if (tsc.notNull == true) { isNullable = "YES"; } record.put("IS_NULLABLE", isNullable); /* * Suppress any sorting of the ResultSet. Column Metadata should * be presented in the order the columns exist in the dBase header. */ jrs.addRow(record, false); } tbl.close(); tbl = null; } return(new TinySQLResultSet(jrs, (TinySQLStatement)null)); } catch (Exception) { return(null); } }
internal TsColumn(String s, java.util.Hashtable <Object, Object> tableDefs, String inputContext) //throws tinySQLException { FieldTokenizer ft, ftArgs; int j, numericType, nameLength, dotAt, argIndex; String upperName, checkName, nextArg; TinySQLTable jtbl; TsColumn tcol; java.util.Vector <Object> t; java.util.Enumeration <Object> col_keys; name = s; longName = name; nameLength = name.length(); contextList = new java.util.Vector <Object>(); contextList.addElement(inputContext); ft = new FieldTokenizer(name, '(', false); if (ft.countFields() == 2) { /* * This is a function rather than a simple column or constant */ functionName = ft.getField(0).toUpperCase(); if (functionName.equals("COUNT")) { type = java.sql.Types.INTEGER; size = 10; intValue = java.lang.Integer.MIN_VALUE; groupedColumn = true; } else if (functionName.equals("SUM")) { type = java.sql.Types.FLOAT; size = 10; groupedColumn = true; } else if (functionName.equals("TO_DATE")) { type = java.sql.Types.DATE; size = 10; } else if (functionName.equals("CONCAT") | functionName.equals("UPPER") | functionName.equals("SUBSTR") | functionName.equals("TRIM")) { type = java.sql.Types.CHAR; } functionArgString = ft.getField(1); ftArgs = new FieldTokenizer(functionArgString, ',', false); functionArgs = new java.util.Vector <Object>(); argIndex = 0; while (ftArgs.hasMoreFields()) { nextArg = ftArgs.nextField(); tcol = new TsColumn(nextArg, tableDefs, inputContext); if (tcol.isGroupedColumn()) { groupedColumn = true; } /* * MAX and MIN functions can be either FLOAT or CHAR types * depending upon the type of the argument. */ if (functionName.equals("MAX") | functionName.equals("MIN")) { if (argIndex > 0) { throw new TinySQLException("Function can only have 1 argument"); } groupedColumn = true; type = tcol.type; size = tcol.size; } else if (functionName.equals("CONCAT")) { type = java.sql.Types.CHAR; size += tcol.size; } else if (functionName.equals("UPPER")) { type = java.sql.Types.CHAR; size = tcol.size; } else if (functionName.equals("TO_DATE")) { type = java.sql.Types.DATE; size = 10; } else if (functionName.equals("TRIM")) { type = java.sql.Types.CHAR; size = tcol.size; } else if (functionName.equals("SUBSTR")) { type = java.sql.Types.CHAR; if (argIndex == 0 & tcol.type != java.sql.Types.CHAR) { throw new TinySQLException("SUBSTR first argument must be character"); } else if (argIndex == 1) { if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1) { throw new TinySQLException("SUBSTR second argument " + tcol.getString() + " must be integer > 0"); } } else if (argIndex == 2) { if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1) { throw new TinySQLException("SUBSTR third argument " + tcol.getString() + " must be integer > 0"); } size = tcol.intValue; } } argIndex++; functionArgs.addElement(tcol); } } else { /* * Check for SYSDATE */ if (name.toUpperCase().equals("SYSDATE")) { isConstant = true; type = java.sql.Types.DATE; size = 10; notNull = true; valueSet = true; //Basties mote: not really SimpleDateFormat needed... - need yyyy-MM-dd // stringValue = fmtyyyyMMdd.format(today.getTime()); stringValue = System.DateTime.Today.ToString("yyyy-MM-dd"); /* * Check for a quoted string */ } else if (UtilString.isQuotedString(name)) { isConstant = true; type = java.sql.Types.CHAR; stringValue = UtilString.removeQuotes(name); if (stringValue != (String)null) { size = stringValue.length(); notNull = true; valueSet = true; } } else { /* * Check for a numeric constant */ numericType = UtilString.getValueType(name); if (numericType == java.sql.Types.INTEGER) { intValue = java.lang.Integer.valueOf(name).intValue(); size = 10; type = numericType; isConstant = true; notNull = true; valueSet = true; } else if (numericType == java.sql.Types.FLOAT) { floatValue = java.lang.Float.valueOf(name).floatValue(); size = 10; type = numericType; isConstant = true; notNull = true; valueSet = true; } else { /* * This should be a column name. */ columnTable = (TinySQLTable)null; upperName = name.toUpperCase(); if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Trying to find table for " + upperName); } dotAt = upperName.indexOf("."); if (dotAt > -1) { tableName = upperName.substring(0, dotAt); if (tableDefs != (java.util.Hashtable <Object, Object>)null & tableName.indexOf("->") < 0) { t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER"); tableName = UtilString.findTableAlias(tableName, t); } upperName = upperName.substring(dotAt + 1); /* * Check to see if this column name has a short equivalent. */ if (upperName.length() > 11) { longName = name; upperName = TinySQLGlobals.getShortName(upperName); } columnTable = (TinySQLTable)tableDefs.get(tableName); } else if (tableDefs != (java.util.Hashtable <Object, Object>)null) { /* * Check to see if this column name has a short equivalent. */ if (upperName.length() > 11) { longName = name; upperName = TinySQLGlobals.getShortName(upperName); } /* * Use an enumeration to go through all of the tables to find * this column. */ t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER"); for (j = 0; j < t.size(); j++) { tableName = (String)t.elementAt(j); jtbl = (TinySQLTable)tableDefs.get(tableName); col_keys = jtbl.column_info.keys(); /* * Check all columns. */ while (col_keys.hasMoreElements()) { checkName = (String)col_keys.nextElement(); if (checkName.equals(upperName)) { upperName = checkName; columnTable = jtbl; break; } } if (columnTable != (TinySQLTable)null) { break; } } } else { if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("No table definitions."); } } if (columnTable != (TinySQLTable)null) { name = columnTable.table + "->" + columnTable.tableAlias + "." + upperName; type = columnTable.ColType(upperName); size = columnTable.ColSize(upperName); decimalPlaces = columnTable.ColDec(upperName); tableName = columnTable.table + "->" + columnTable.tableAlias; } } } } }
/* * This method formats an action Hashtable for display. */ public static String actionToString(java.util.Hashtable <Object, Object> displayAction) { java.lang.StringBuffer displayBuffer = new java.lang.StringBuffer(); String displayType, tableName; TinySQLWhere displayWhere; TsColumn createColumn, displayColumn; bool groupBy = false, orderBy = false; int i; java.util.Vector <Object> displayTables, displayColumns, columnDefs, displayValues; java.util.Hashtable <Object, Object> tables; displayType = (String)displayAction.get("TYPE"); displayBuffer.append(displayType + " "); displayWhere = null; displayColumns = null; if (displayType.equals("SELECT")) { tables = (java.util.Hashtable <Object, Object>)displayAction.get("TABLES"); displayTables = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER"); displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS"); displayWhere = (TinySQLWhere)displayAction.get("WHERE"); for (i = 0; i < displayColumns.size(); i++) { displayColumn = (TsColumn)displayColumns.elementAt(i); if (displayColumn.getContext("GROUP")) { groupBy = true; continue; } else if (displayColumn.getContext("ORDER")) { orderBy = true; continue; } if (i > 0) { displayBuffer.append(","); } displayBuffer.append((String)displayColumn.name); } displayBuffer.append(" FROM "); for (i = 0; i < displayTables.size(); i++) { if (i > 0) { displayBuffer.append(","); } displayBuffer.append((String)displayTables.elementAt(i)); } } else if (displayType.equals("DROP_TABLE")) { tableName = (String)displayAction.get("TABLE"); displayBuffer.append(tableName); } else if (displayType.equals("CREATE_TABLE")) { tableName = (String)displayAction.get("TABLE"); displayBuffer.append(tableName + " ("); columnDefs = (java.util.Vector <Object>)displayAction.get("COLUMN_DEF"); for (i = 0; i < columnDefs.size(); i++) { if (i > 0) { displayBuffer.append(","); } createColumn = (TsColumn)columnDefs.elementAt(i); displayBuffer.append(createColumn.name + " " + createColumn.type + "( " + createColumn.size + "," + createColumn.decimalPlaces + ")"); } displayBuffer.append(")"); } else if (displayType.equals("INSERT")) { tableName = (String)displayAction.get("TABLE"); displayBuffer.append("INTO " + tableName + "("); displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS"); for (i = 0; i < displayColumns.size(); i++) { if (i > 0) { displayBuffer.append(","); } displayBuffer.append((String)displayColumns.elementAt(i)); } displayBuffer.append(") VALUES ("); displayValues = (java.util.Vector <Object>)displayAction.get("VALUES"); for (i = 0; i < displayValues.size(); i++) { if (i > 0) { displayBuffer.append(","); } displayBuffer.append((String)displayValues.elementAt(i)); } displayBuffer.append(")"); } else if (displayType.equals("UPDATE")) { tableName = (String)displayAction.get("TABLE"); displayBuffer.append(tableName + " SET "); displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS"); displayValues = (java.util.Vector <Object>)displayAction.get("VALUES"); displayWhere = (TinySQLWhere)displayAction.get("WHERE"); for (i = 0; i < displayColumns.size(); i++) { if (i > 0) { displayBuffer.append(","); } displayBuffer.append((String)displayColumns.elementAt(i) + "=" + (String)displayValues.elementAt(i)); } } else if (displayType.equals("DELETE")) { tableName = (String)displayAction.get("TABLE"); displayBuffer.append(" FROM " + tableName); displayWhere = (TinySQLWhere)displayAction.get("WHERE"); } if (displayWhere != (TinySQLWhere)null) { displayBuffer.append(displayWhere.toString()); } if (groupBy) { displayBuffer.append(" GROUP BY "); for (i = 0; i < displayColumns.size(); i++) { displayColumn = (TsColumn)displayColumns.elementAt(i); if (!displayColumn.getContext("GROUP")) { continue; } if (!displayBuffer.toString().endsWith(" GROUP BY ")) { displayBuffer.append(","); } displayBuffer.append(displayColumn.name); } } if (orderBy) { displayBuffer.append(" ORDER BY "); for (i = 0; i < displayColumns.size(); i++) { displayColumn = (TsColumn)displayColumns.elementAt(i); if (!displayColumn.getContext("ORDER")) { continue; } if (!displayBuffer.toString().endsWith(" ORDER BY ")) { displayBuffer.append(","); } displayBuffer.append(displayColumn.name); } } return(displayBuffer.toString()); }
/* * Sets the receiver's stream handler to one which is appropriate for its * protocol. Throws a MalformedURLException if no reasonable handler is * available. * <p/> * Note that this will overwrite any existing stream handler with the new * one. Senders must check if the strmHandler is null before calling the * method if they do not want this behavior (a speed optimization). */ void setupStreamHandler() { String className = null; // Check for a cached (previously looked up) handler for // the requested protocol. strmHandler = streamHandlers.get(protocol); if (strmHandler != null) { return; } // If there is a stream handler factory, then attempt to // use it to create the handler. if (streamHandlerFactory != null) { strmHandler = streamHandlerFactory.createURLStreamHandler(protocol); if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); return; } } // Check if there is a list of packages which can provide handlers. // If so, then walk this list looking for an applicable one. String packageList = java.security.AccessController .doPrivileged(new PriviAction <String>( "java.protocol.handler.pkgs")); //$NON-NLS-1$ if (packageList != null) { java.util.StringTokenizer st = new java.util.StringTokenizer(packageList, "|"); //$NON-NLS-1$ while (st.hasMoreTokens()) { className = st.nextToken() + "." + protocol + ".Handler"; //$NON-NLS-1$ //$NON-NLS-2$ try { strmHandler = (URLStreamHandler)java.lang.Class.forName(className, true, java.lang.ClassLoader.getSystemClassLoader()) .newInstance(); if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); } return; } catch (java.lang.IllegalAccessException e) { } catch (java.lang.InstantiationException e) { } catch (java.lang.ClassNotFoundException e) { } } } // No one else has provided a handler, so try our internal one. className = "org.apache.harmony.luni.internal.net.www.protocol." + protocol //$NON-NLS-1$ + ".Handler"; //$NON-NLS-1$ try { strmHandler = (URLStreamHandler)java.lang.Class.forName(className) .newInstance(); } catch (java.lang.IllegalAccessException e) { } catch (java.lang.InstantiationException e) { } catch (java.lang.ClassNotFoundException e) { } if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); } }