0

我有一个数据源,它将 Odata 传递给 Teiid,然后传递给 Oracle。但是,当我尝试从 Kendo 数据源传递一个日期时,Oracle 感到窒息。我认为这是因为 Oracle 无法将其发送的日期字符串(例如2014-07-01T05:00:00.000Z)识别为有效。这是我得到的错误:

avax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.teiid.jdbc.TeiidSQLException: TEIID30504 JTRAC_DEV_ENV: 1843 TEIID11013:TEIID11004 Error executing statement(s): [Prepared Values: ['2014-07-01T05:00:00.000Z', 700281, 700280] SQL: UPDATE "JTRAC"."MAPPED_HISTORY" SET "TIME_STAMP" = ? WHERE "JTRAC"."MAPPED_HISTORY"."HISTORY_ID" = ? AND "JTRAC"."MAPPED_HISTORY"."ITEM_ID" = ?]
Error Code: 1843
Call: UPDATE "JTRAC.MAPPED_HISTORY" SET "TIME_STAMP" = ? WHERE ((("HISTORY_ID" = ?) AND ("ITEM_ID" = ?)) AND ("TEIID_MULTI_DATA_SOURCE_COLUMN" = ?))
bind => [2014-07-01T05:00:00.000Z, 700281, 700280, JTRAC_DEV_ENV]

如何将时间戳更改为可以使用的东西?我已经尝试使用 parameterMap (似乎还没有在那个阶段转换它 - 仍然是相当正常的时间格式),requestStart(我似乎无法访问数据以篡改它)和解析(isn' t 以我期望的方式工作)。作为记录,另一端有一个 INSTEAD OF Oracle 触发器,因为最终我正在更新一个视图。想法?

这是我正在使用的触发器:

create or replace 
trigger update_mapped_history
  INSTEAD OF UPDATE ON mapped_history
  FOR EACH ROW
DECLARE
  new_status_id number;
  new_assigned_to number;
  new_logged_by number;
  new_timestamp timestamp;
  cmmd VARCHAR2(100);
BEGIN
  cmmd:='alter session set NLS_TIMESTAMP_FORMAT=''YYYY-MM-DD"T"HH:MI:SS.FF"Z"''';
  EXECUTE IMMEDIATE cmmd;
  SELECT status_id INTO new_status_id FROM status_int_mapping WHERE status_label=:NEW.status AND space_id = (select i.space_id from items i where i.id = :OLD.item_id);
  SELECT id INTO new_assigned_to FROM users WHERE login_name = :NEW.assigned_to;
  SELECT id INTO new_logged_by FROM users WHERE login_name = :NEW.logged_by;
  select FROM_TZ(TO_TIMESTAMP(:NEW.time_stamp, 'YYYY-MM-DD"T"HH:MI:SS.FF"Z"'),'UTC') at time zone 'US/Central' into new_timestamp from dual;
  UPDATE history SET
    logged_by = new_logged_by, 
    status = new_status_id,
    assigned_to = new_assigned_to,
    jt_comment = :NEW.jt_comment,
    time_stamp = new_timestamp
  WHERE id=:OLD.history_id;
END;

这是我所有荣耀的代码。

historyDataSource = new kendo.data.DataSource({
        //autoSync: true,
        type: "odata",
        serverFiltering: true,
        serverPaging: true,
        serverSorting: true,
        pageSize: 10,
        transport: {
            read: {
                url: baseUrl + "MAPPED_HISTORY",
                type: "GET",
                headers: {
                    Authorization: authorizationStr64
                },
                dataType: "json"
            },
            update: {
                url: function(options){
                    return kendo.format(baseUrl + "MAPPED_HISTORY"+"({0})", options.HISTORY_ID);
                },
                type: "PUT",
                headers: {
                    Authorization: authorizationStr64
                },
                dataType: "json",
                contentType: "application/json"
            },
            create: {
                url: baseUrl + "MAPPED_HISTORY",
                type: "POST",
                headers: {
                    Authorization: authorizationStr64
                },
                dataType: "json"
            },
            destroy: {
                //url: "http://amr-dsiprod05:8080/odata/SDA/TEIID_TEST",
                url: function(options){
                    return kendo.format(baseUrl + "MAPPED_HISTORY"+"({0})", options.HISTORY_ID);
                },
                type: "DELETE",
                headers: {
                    Authorization: authorizationStr64
                },
                dataType: "json"
            },
            parameterMap: function(data,type){
                if(type=='update'){
                    debugger;
                }
                return data;
            }
        },
        // Enable server filtering so we don't have to download the whole history data set
        serverFiltering: true,
        filter: { logic: "and", filters: [ { field: "HISTORY_ID", operator: "equals", value: historyId } ] },

        "schema": {
            "model": {
                "id": "HISTORY_ID",
                "fields": {
                    /*"HISTORY_ID": {
                        "editable": true,
                        "nullable": false
                    },
                    "ITEM_ID": {
                        "editable": true,
                        "nullable": true
                    },*/
                    "LOGGED_BY": {
                        "editable": false,
                        "nullable": true
                    },
                    "STATUS": {
                        "editable": false,
                        "nullable": false
                    },
                    "ASSIGNED_TO": {
                        "editable": false,
                        "nullable": true
                    },
                    "JT_COMMENT": {
                        "editable": true,
                        "nullable": true
                    },
                    "TIME_STAMP": {
                        "editable": true,
                        "nullable": false
                    }
                }
            },
            errors: "error"/*,
            parse:function (response) {
                $.each(response, function (idx, elem) {
                    if (elem.Date && typeof elem.Date === "string") {
                        elem.Date = kendo.parseDate(elem.Date, "yyyy-MM-ddTHH:mm:ss.fffZ");
                        console.log(elem.Date);
                        debugger;
                    }
                });
                return response;
            }*/
        },
        error: function(e){
            if(confirm("Could not update or display data! Show full error report?")){
                var myWindow = window.open("", "MsgWindow", "width=1000, height=800,resizable=yes, ");
                myWindow.document.write(e.xhr.responseText);
            }
            //console.log();
        },
        /*requestStart: function(e){
            if(e.type=='update'){
                debugger;
            }
        },
        requestEnd: function(e){
            if(e.type=='update'){
                debugger;
                for(var i=0; i<e.response.d.results.length; i++){  
                    var timeStamp = kendo.parseDate(e.response.d.results[i].time_stamp);
                    var utcTimeStamp = new Date(timeStamp.getTime() + timeStamp.getTimezoneOffset() * 60000);
                    e.response.d.results[i].OrderDate = utcTimeStamp;
                    alert(utcTimeStamp);
                }
                debugger;//alert('updating kendo!');
            }
        }*/
    });   
    historyDataSource.read();


    $("#" + divId).kendoGrid({
        "dataSource": historyDataSource,
        "autoBind": false,
        "pageable": true,
        "height": 350,
        "selectable": true,
        "editable": true,
        "toolbar": [/*"create",*/"save","cancel"],
        "columns": [
            //{ "field": "HISTORY_ID", "width":"100px" },
            //{ "field": "ITEM_ID", "width":"100px" },
            { "field": "LOGGED_BY", "width":"160px", editor: usersDropDownEditor, template: "#=LOGGED_BY#"  },
            { "field": "STATUS", "width":"200px" , editor: statusDropDownEditor, template: "#=STATUS#"  },
            { "field": "ASSIGNED_TO", "width":"160px", editor: usersDropDownEditor, template: "#=ASSIGNED_TO#"  },
            { "field": "JT_COMMENT"},
            { "field": "TIME_STAMP", "width":"200px", format: "{0:MM/dd/yyyy hh:mm tt}", editor: dateTimeEditor }//,
            //{ "command": "destroy" }
        ]
    });

    function dateTimeEditor(container, options) {
        $('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
                .appendTo(container)
                .kendoDateTimePicker({
                    interval: 05,
                    min: new Date(2011, 0, 1),
                    timeFormat: "HH:mm"
                    /*parseFormats: ["yyyy-MM-dd hh:mm:ss"]*/
                });
    }

    function statusDropDownEditor(container, options) {
        var statusInput = $('<input required data-text-field="STATUS_LABEL" data-value-field="STATUS_LABEL" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource: {
                    type: "odata",
                    transport: {
                        read: {
                            url: baseUrl + "STATUS_INT_MAPPING",
                            type: "GET",
                            headers: {
                                Authorization: authorizationStr64
                            },
                            dataType: "json"
                        }
                    },
                    serverFiltering: true,
                    filter: { logic: "and", filters: [ {field: "SPACE_ID", operator: "equals", value: spaceId}]}
                }
            });
    }

    function usersDropDownEditor(container, options) {
        var usersInput= $('<input required data-text-field="LOGIN_NAME" data-value-field="LOGIN_NAME" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource: {
                    type: "odata",
                    transport: {
                        read: {
                            url: baseUrl + "SPACE_LOGIN_NAMES",
                            type: "GET",
                            headers: {
                                Authorization: authorizationStr64
                            },
                            dataType: "json"
                        }
                    },
                    serverFiltering: true,
                    filter: { logic: "and", filters: [ {field: "SPACE_ID", operator: "equals", value: spaceId}]}
                }
            });
    }
});
4

1 回答 1

1

要么使用显式TO_TIMESTAMP()函数,要么在客户端中设置 NLS_TIMESTAMP_FORMAT。

更多信息可以在这里找到:

TO_TIMESTAMP() 函数 http://docs.oracle.com/cd/E16655_01/server.121/e17209/functions223.htm#SQLRF06142

NLS_TIMESTAMP_FORMAT http://docs.oracle.com/cd/E16655_01/server.121/e17615/refrn10131.htm#REFRN10131

于 2014-07-16T21:59:44.753 回答