예제 #1
0
        /**
         * Create a JSONObject from a DBXReader
         * @param dbxReader
         * @return JSONObject
         */
        public static TJSONObject DBXReaderToJSONObject(TDBXReader dbxReader)
        {
            TJSONObject json = new TJSONObject();
            TJSONArray  arr2;
            TParams     columns = dbxReader.getColumns();

            try
            {
                arr2 = new TJSONArray();
                for (int i = 0; i < columns.size(); i++)
                {
                    arr2.add(columns.getParameter(i).tojson());
                    // Create the empty JArray for the data. Will be filled after
                    json.addPairs(columns.getParameter(i).getName(), new TJSONArray());
                }

                while (dbxReader.next())
                {
                    for (int c = 0; c < columns.size(); c++)
                    {
                        dbxReader.getColumns().getParameter(c).getValue().appendTo(
                            json.getJSONArray(columns.getParameter(c)
                                              .getName()));
                    }
                }
                json.addPairs("table", arr2);
            }
            catch (Exception)
            {
            }
            return(json);
        }
예제 #2
0
        /**
         * Create a JSONObject from a DBXParameters
         * @param dbxParameters
         * @return JSONObject
         */
        public static TJSONObject DBXParametersToJSONObject(TParams dbxParameters)
        {
            TJSONObject json = new TJSONObject();
            TJSONObject jsonobj = new TJSONObject();

            for (int i = 0; i < dbxParameters.size(); i++)
            {
                TJSONArray arr3;
                try
                {
                    arr3 = new TJSONArray();
                    arr3.add(new TJSONString(dbxParameters.getParameter(i).getValue().ToString()));
                    json.addPairs(dbxParameters.getParameter(i).getName(), arr3);
                }
                catch (Exception)
                {

                }
            }

            TJSONArray arr2;
            arr2 = new TJSONArray();
            for (int i = 0; i < dbxParameters.size(); i++)
            {
                TJSONArray arr;
                arr = new TJSONArray();
                arr.add(new TJSONString(dbxParameters.getParameter(i).getName()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getDataType()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getOrdinal()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSubType()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getScale()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSize()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getPrecision()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getChildPosition()));
                if (dbxParameters.getParameter(i).getNullable()) arr.add(new TJSONTrue());
                else arr.add(new TJSONFalse());
                if (dbxParameters.getParameter(i).getHidden()) arr.add(new TJSONTrue());
                else arr.add(new TJSONFalse());
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getParameterDirection()));
                if (dbxParameters.getParameter(i).getValueParameter()) arr.add(new TJSONTrue());
                else arr.add(new TJSONFalse());
                if (dbxParameters.getParameter(i).getLiteral()) arr.add(new TJSONTrue());
                else arr.add(new TJSONFalse());
                arr2.add(arr);
            }
            try
            {
                json.addPairs("table", arr2);
            }
            catch (Exception)
            {

            }
            return json;
        }
예제 #3
0
        /**
         *
         * @return a JArray with the ByteArray of Stream
         */
        protected TJSONArray StreamToJson()
        {
            checkCurrentDBXType(DBXDataTypes.BinaryBlobType);

            try {
                byte[]     b     = DBXTools.streamToByteArray(streamValue);
                TJSONArray jsArr = new TJSONArray();
                for (int i = 0; i < b.Length; i++)
                {
                    jsArr.add(new TJSONNumber(Convert.ToInt32(b[i])));
                }
                return(jsArr);
            } catch (Exception e) {
                throw new DBXException(e.Message);
            }
        }
예제 #4
0
        /**
          	 * Create a JSONObject from a DBXReader
          	 * @param dbxReader
          	 * @return JSONObject
          	 */
        public static TJSONObject DBXReaderToJSONObject(TDBXReader dbxReader)
        {
            TJSONObject json = new TJSONObject();
            TJSONArray arr2;
            TParams columns = dbxReader.getColumns();
            try
            {
                arr2 = new TJSONArray();
                for (int i = 0; i < columns.size(); i++)
                {
                    arr2.add(columns.getParameter(i).tojson());
                    // Create the empty JArray for the data. Will be filled after
                    json.addPairs(columns.getParameter(i).getName(), new TJSONArray());
                }

                while (dbxReader.next())
                {
                    for (int c = 0; c < columns.size(); c++)
                        dbxReader.getColumns().getParameter(c).getValue().appendTo(
                                json.getJSONArray(columns.getParameter(c)
                                                .getName()));
                }
                json.addPairs("table", arr2);
            }
            catch (Exception)
            {

            }
            return json;
        }
예제 #5
0
        /**
         * Adds in a JArray DBXValue and then use it in the body of the request
         */
        public void appendTo(TJSONArray json)
        {
            try {
                if (containsASimpleValueType())
                {
                    GetAsDBXValue().appendTo(json);
                    return;
                }

                switch (CurrentDBXType)
                {
                case DBXDataTypes.Int8Type: {
                    json.add(new TJSONNumber(GetAsInt8()));
                    break;
                }

                case DBXDataTypes.Int16Type: {
                    json.add(new TJSONNumber(GetAsInt16()));
                    break;
                }

                case DBXDataTypes.Int32Type: {
                    json.add(new TJSONNumber(GetAsInt32()));
                    break;
                }

                case DBXDataTypes.Int64Type: {
                    json.add(new TJSONNumber(GetAsInt64()));
                    break;
                }

                case DBXDataTypes.UInt8Type: {
                    json.add(new TJSONNumber(GetAsUInt8()));
                    break;
                }

                case DBXDataTypes.UInt16Type: {
                    json.add(new TJSONNumber(GetAsUInt16()));
                    break;
                }

                case DBXDataTypes.UInt32Type: {
                    json.add(new TJSONNumber(GetAsUInt32()));
                    break;
                }

                case DBXDataTypes.UInt64Type: {
                    json.add(new TJSONNumber(GetAsUInt64()));
                    break;
                }

                case DBXDataTypes.AnsiStringType:
                case DBXDataTypes.WideStringType: {
                    json.add(new TJSONString(GetAsString()));
                    break;
                }

                case DBXDataTypes.DateTimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                                                 dateTimeValue)));
                    break;
                }

                case DBXDataTypes.TimeStampType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                                                 TimeStampValue)));
                    break;
                }

                case DBXDataTypes.DateType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXDateToString(
                                                 GetAsTDBXDate())));
                    break;
                }

                case DBXDataTypes.TimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXTimeToString(
                                                 GetAsTDBXTime())));
                    break;
                }

                case DBXDataTypes.JsonValueType: {
                    Object o = GetAsJSONValue().getInternalObject();
                    json.add(o);
                    break;
                }

                case DBXDataTypes.TableType: {
                    try {
                        json.add(((JSONSerializable)objectValue).asJSONObject());
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.CurrencyType: {
                    try {
                        json.add(new TJSONNumber(GetAsCurrency()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.DoubleType: {
                    try {
                        json.add(new TJSONNumber(GetAsDouble()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.SingleType: {
                    try {
                        json.add(new TJSONNumber(GetAsSingle()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }

                case DBXDataTypes.BinaryBlobType: {
                    json.add(StreamToJson());
                    break;
                }

                default:
                    throw new DBXException("Cannot convert this type to string");
                }
            } catch (DBXException) {
                return;
            }
        }
예제 #6
0
        /**
         * Create a JSONObject from a DBXParameters
         * @param dbxParameters
         * @return JSONObject
         */
        public static TJSONObject DBXParametersToJSONObject(TParams dbxParameters)
        {
            TJSONObject json    = new TJSONObject();
            TJSONObject jsonobj = new TJSONObject();

            for (int i = 0; i < dbxParameters.size(); i++)
            {
                TJSONArray arr3;
                try
                {
                    arr3 = new TJSONArray();
                    arr3.add(new TJSONString(dbxParameters.getParameter(i).getValue().ToString()));
                    json.addPairs(dbxParameters.getParameter(i).getName(), arr3);
                }
                catch (Exception)
                {
                }
            }

            TJSONArray arr2;

            arr2 = new TJSONArray();
            for (int i = 0; i < dbxParameters.size(); i++)
            {
                TJSONArray arr;
                arr = new TJSONArray();
                arr.add(new TJSONString(dbxParameters.getParameter(i).getName()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getDataType()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getOrdinal()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSubType()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getScale()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getSize()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getPrecision()));
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getChildPosition()));
                if (dbxParameters.getParameter(i).getNullable())
                {
                    arr.add(new TJSONTrue());
                }
                else
                {
                    arr.add(new TJSONFalse());
                }
                if (dbxParameters.getParameter(i).getHidden())
                {
                    arr.add(new TJSONTrue());
                }
                else
                {
                    arr.add(new TJSONFalse());
                }
                arr.add(new TJSONNumber(dbxParameters.getParameter(i).getParameterDirection()));
                if (dbxParameters.getParameter(i).getValueParameter())
                {
                    arr.add(new TJSONTrue());
                }
                else
                {
                    arr.add(new TJSONFalse());
                }
                if (dbxParameters.getParameter(i).getLiteral())
                {
                    arr.add(new TJSONTrue());
                }
                else
                {
                    arr.add(new TJSONFalse());
                }
                arr2.add(arr);
            }
            try
            {
                json.addPairs("table", arr2);
            }
            catch (Exception)
            {
            }
            return(json);
        }
예제 #7
0
        /**
         * Adds in a JArray DBXValue and then use it in the body of the request
         */
        public void appendTo(TJSONArray json)
        {
            try {
                if (containsASimpleValueType()) {
                    GetAsDBXValue().appendTo(json);
                    return;
                }

                switch (CurrentDBXType) {
                case DBXDataTypes.Int8Type: {
                    json.add(new TJSONNumber(GetAsInt8()));
                    break;
                }
                case DBXDataTypes.Int16Type: {
                    json.add(new TJSONNumber(GetAsInt16()));
                    break;
                }
                case DBXDataTypes.Int32Type: {
                    json.add(new TJSONNumber(GetAsInt32()));
                    break;
                }
                case DBXDataTypes.Int64Type: {
                    json.add(new TJSONNumber(GetAsInt64()));
                    break;
                }
                case DBXDataTypes.UInt8Type: {
                    json.add(new TJSONNumber(GetAsUInt8()));
                    break;
                }
                case DBXDataTypes.UInt16Type: {
                    json.add(new TJSONNumber(GetAsUInt16()));
                    break;
                }
                case DBXDataTypes.UInt32Type: {
                    json.add(new TJSONNumber(GetAsUInt32()));
                    break;
                }
                case DBXDataTypes.UInt64Type: {
                    json.add(new TJSONNumber(GetAsUInt64()));
                    break;
                }
                case DBXDataTypes.AnsiStringType:
                case DBXDataTypes.WideStringType: {
                    json.add(new TJSONString(GetAsString()));
                    break;
                }
                case DBXDataTypes.DateTimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                            dateTimeValue)));
                    break;
                }
                case DBXDataTypes.TimeStampType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().DateTimeToString(
                            TimeStampValue)));
                    break;
                }
                case DBXDataTypes.DateType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXDateToString(
                            GetAsTDBXDate())));
                    break;
                }
                case DBXDataTypes.TimeType: {
                    json.add(new TJSONString(DBXDefaultFormatter.getInstance().TDBXTimeToString(
                            GetAsTDBXTime())));
                    break;
                }
                case DBXDataTypes.JsonValueType: {
                    Object o = GetAsJSONValue().getInternalObject();
                    json.add(o);
                    break;
                }
                case DBXDataTypes.TableType: {
                    try {
                        json.add(((JSONSerializable) objectValue).asJSONObject());
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }
                case DBXDataTypes.CurrencyType: {
                    try {
                        json.add(new TJSONNumber(GetAsCurrency()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }
                case DBXDataTypes.DoubleType: {
                    try {
                        json.add(new TJSONNumber(GetAsDouble()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }
                case DBXDataTypes.SingleType: {
                    try {
                        json.add(new TJSONNumber(GetAsSingle()));
                    } catch (Exception e) {
                        throw new DBXException(e.Message);
                    }
                    break;
                }
                case DBXDataTypes.BinaryBlobType: {
                    json.add(StreamToJson());
                    break;
                }
                default:
                    throw new DBXException("Cannot convert this type to string");
                }
            } catch (DBXException) {
                return;
            }
        }
예제 #8
0
        /**
         *
         * @return a JArray with the ByteArray of Stream
         */
        protected TJSONArray StreamToJson()
        {
            checkCurrentDBXType(DBXDataTypes.BinaryBlobType);

            try {
                byte[] b = DBXTools.streamToByteArray(streamValue);
                TJSONArray jsArr = new TJSONArray();
                for (int i = 0; i < b.Length; i++)
                    jsArr.add(new TJSONNumber(Convert.ToInt32(b[i])));
                return jsArr;
            } catch (Exception e) {
                throw new DBXException(e.Message);
            }
        }