public static bool?toBoolean(Object o)
        {
            if (o == null)
            {
                return(null);
            }

            if (o is Boolean)
            {
                return((Boolean)o);
            }
            if (o is String)
            {
                try
                {
                    return(parseBoolean((String)o));
                }
                catch (ArgumentException e)
                {
                    logger.warn("Could not convert String '{0}' to boolean, returning false", o);
                    return(false);
                }
            }
            if (o is NNumber)
            {
                int i = ((NNumber)o).asInt();
                return(i >= 1);
            }

            logger.warn("Could not convert '{0}' to boolean, returning false", o);
            return(false);
        } // toBoolean()
        } // materializeFromItem()

        protected DataSet materializeTable(Table table, List <SelectItem> selectItems,
                                           List <FilterItem> whereItems, int firstRow, int maxRows)
        {
            if (table == null)
            {
                throw new ArgumentException("Table cannot be null");
            }

            if (selectItems == null || selectItems.IsEmpty())
            {
                // add any column (typically this occurs because of COUNT(*)
                // queries)
                Column[] columns = table.getColumns();
                if (columns.Length == 0)
                {
                    logger.warn("Queried table has no columns: {}", table);
                }
                else
                {
                    selectItems.Add(new SelectItem(columns[0]));
                }
            }

            Schema schema = table.getSchema();
            String schemaName;

            if (schema == null)
            {
                schemaName = null;
            }
            else
            {
                schemaName = schema.getName();
            }

            DataSet dataSet;

            if (INFORMATION_SCHEMA_NAME.Equals(schemaName))
            {
                DataSet informationDataSet = materializeInformationSchemaTable
                                                 (table, buildWorkingSelectItems(selectItems, whereItems));
                informationDataSet = MetaModelHelper.getFiltered(informationDataSet, whereItems);
                informationDataSet = MetaModelHelper.getSelection(selectItems, informationDataSet);
                informationDataSet = MetaModelHelper.getPaged(informationDataSet, firstRow, maxRows);
                dataSet            = informationDataSet;
            }
            else
            {
                DataSet tableDataSet = materializeMainSchemaTable(table, selectItems, whereItems, firstRow, maxRows);

                // conversion is done at materialization time, since it enables
                // the refined types to be used also in eg. where clauses.
                dataSet = new ConvertedDataSetInterceptor(_converters).intercept(tableDataSet);
            }

            return(dataSet);
        } // materializeTable()
コード例 #3
0
        } // createTempFile()

        public static string getTempDir()
        {
            string     result = "";
            FileStream fs     = null;
            // String tmpDirPath = System.getProperty("java.io.tmpdir");
            string tmp_file_path = Path.GetTempPath();

            if (tmp_file_path != null && !"".Equals(tmp_file_path))
            {
                fs = File.Open(tmp_file_path, FileMode.Create);
            }
            else
            {
                logger.debug("Could not determine tmpdir by using environment variable.");
                try
                {
                    // https://www.tutorialspoint.com/java/io/file_createtempfile_directory.htm
                    //File.createTempFile("foo", "bar");
                    tmp_file_path = ".foo.bar";
                    fs            = File.Open(tmp_file_path, FileMode.Create);
                    DirectoryInfo di = Directory.GetParent(tmp_file_path);
                    string        tmp_file_full_path = di.FullName + "\\" + tmp_file_path;
                    result = tmp_file_full_path;
                    try
                    {
                        File.Delete(tmp_file_full_path);
                    }
                    catch (Exception e)
                    {
                        logger.warn("Could not delete temp file '{}'", tmp_file_full_path);
                    }
                }
                catch (IOException e)
                {
                    logger.error("Could not create tempFile in order to find temporary dir", e);
                    try
                    {
                        DirectoryInfo di = Directory.CreateDirectory("metamodel.tmp.dir");
                    }
                    catch (Exception e2)
                    {
                        throw new InvalidOperationException("Could not create directory for temporary files: "
                                                            + e2.Message);
                    }

                    //result.deleteOnExit();
                    fs.Dispose();
                }
            }
            if (logger.isInfoEnabled())
            {
                logger.info("Using '{0}' as tmpdir.", result);
            }
            return(result);
        } // getTempDir()
コード例 #4
0
        } // Compare()

        public static NDate toDate(object value)
        {
            NDate result = null;

            if (value == null)
            {
                result = null;
            }
            else if (value is NDate)
            {
                result = (NDate)value;
            }
            else if (value is Calendar)
            {
                // https://www.tutorialspoint.com/java/util/calendar_gettime.htm
                result = new NDate(DateTime.Now);
            }
            else if (value is String)
            {
                result = convertFromString((String)value);
            }
            else if (value is NNumber)
            {
                result = convertFromNumber((NNumber)value);
            }

            if (result == null)
            {
                logger.warn("Could not convert '{}' to date, returning null", value);
            }

            return(result);
        }
コード例 #5
0
 //@Override
 public override void close()
 {
     base.close();
     try
     {
         _document_source.close();
     }
     catch (Exception e)
     {
         logger.warn("Failed to close DocumentSource: {}", _document, e);
     }
 } // close()
        } // readValue()

        public void close()
        {
            try
            {
                _parser.close();
            }
            catch (IOException e)
            {
                logger.warn("Failed to ");
            }
            //throw new NotImplementedException();
        } // close()
コード例 #7
0
        } // isIntegerType()

        public static NNumber toNumber(object value)
        {
            String string_value;

            if (value == null)
            {
                return(null);
            }
            else if (value is NNumber)
            {
                return((NNumber)value);
            }
            else if (value is NBool)
            {
                if (bool.TrueString.Equals(value.ToString()))
                {
                    return(NInteger.ONE);
                }
                else
                {
                    return(NInteger.ZERO);
                }
            }
            else
            {
                string_value = value.ToString().Trim();
                if (string_value.IsEmpty())
                {
                    return(null);
                }

                try
                {
                    return(new NNumber(NNumber.ParseInt(string_value)));
                }
                catch (FormatException e)
                {
                }
                try
                {
                    return(NNumber.ParseLong(string_value));
                }
                catch (FormatException e)
                {
                }
                try
                {
                    return(new NNumber(NNumber.ParseDouble(string_value)));
                }
                catch (FormatException e)
                {
                }
            }

            //[J2Cs: Weird syntax block referring a variable from the previous if/else block]
            // note: Boolean.parseBoolean does not throw NumberFormatException -
            // it just returns false in case of invalid values.
            {
                if ("true".Equals(string_value, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(NInteger.ONE);
                }
                if ("false".Equals(string_value, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(NInteger.ZERO);
                }
            }
            logger.warn("Could not convert '{}' to number, returning null", value);
            return(null);
        } // toNumber()