您好,欢迎访问一九零五行业门户网

OAF FlexField中数据库与页面的前后台数据类型转换

欢迎进入oracle社区论坛,与200万技术人员互动交流 >>进入 oracle application中有flexfield(弹性域)这个东西。在flexfield tables,数据存放于varchar2类型的一列或多列中。不论是数字、日期、文本等,最终都会以varchar2存放在table中。在oa page中,这些
欢迎进入oracle社区论坛,与200万技术人员互动交流 >>进入
oracle application中有flexfield(弹性域)这个东西。在flexfield tables,数据存放于varchar2类型的一列或多列中。不论是数字、日期、文本等,最终都会以varchar2存放在table中。在oa page中,这些varchar2一般需要使用相对应的格式,比如日期、数字,以使用相应的验证机制,或者根据不同的地区转换成不同的格式。问题是,怎样在前后台中做数据类型转换呢?一个最简单的办法是使用oaf的flexfield bean.但在一些情况下,使用flexfield bean反而会不方便控制。甚或乎,明明跟随了oaf developer guide的方法,但总是用不了这个flexfield bean.这时,只能手工地做这件事情了。
数据类型转换的基本原理很简单:把读写分离,或者说把前后台不同方向的数据流分开处理。
1. 传统情况
所谓传统情况,或者一般情况,就是数据库的列名是有实际意义的、明确的。比如,列名是effective_date,eo、vo中的属性名也会使用effectivedate.
我们会在vo中定义一个sql语句。当进行操作时,oaf会把这个sql语句封装,然后进行读写。比如:
[sql]
select   exampleeo.example_id as example_id
, exampleeo.effective_date as effective_date
, exampleeo.employee_name as employee_name
from   exampleeo
where  exampleeo.example_id > 10
当查询example_id = 100的记录,oaf会封装成这样子:
[sql]
select *
from   (select   exampleeo.example_id as example_id
, exampleeo.effective_date as effective_date
, exampleeo.employee_name as employee_name
from   exampleeo
where  exampleeo.example_id > 10) qrslt
where  qrslt.example_id = 100
插入的时候也是类似的:
[sql]
update (select   exampleeo.example_id as example_id
, exampleeo.effective_date as effective_date
, exampleeo.employee_name as employee_name
from   exampleeo
where  exampleeo.example_id > 10) qrslt
set      qrslt.effective_date =           -- ok
, qrslt.employee_name =             -- ok
where  qrslt.example_id = 100
总的来说,是将vo中的sql语句封装成表格,然后外面包裹相应的操作。
2. flexfield的问题
而在flexfield的情况,列名是没有实际意义,或者说不明确的。flexfield存放数据的列名一般是org_information1、per_information5之类。在vo中,这些名字可能会被替换为实际的用途,比如说org_information1可能是一个effective date,那么在vo中的属性就会被命名为effectivedate.这个的mapping是在vo properties中设置的。
为了简化列名,本文把org_information1、per_attribute1等统称为information1.于是,在一个flexfield表格,vo的语句会是这个样子:
[sql]
select   exampleeo.example_id as example_id
, exampleeo.information1 as effective_date
, exampleeo.information2 as employee_name
from   exampleeo
where  exampleeo.example_id > 10
查询example_id = 100的记录,会生成以下的语句:
[sql]
select *
from   (select   exampleeo.example_id as example_id
, exampleeo.information1 as effective_date       -- information1 is a varchar2
, exampleeo.information2 as employee_name
from   exampleeo
where  exampleeo.example_id > 10) qrslt
where  qrslt.example_id = 100
查询语句本身没有问题。但是在oa page中,显示日期的item所属的类型一般会设成date,而上面的sql语句查询结果的类型是varchar2.于是,vo与pg上的的属性类型不管如何设置,都会在页面上方报错。此乃问题一。
[1] [2]
其它类似信息

推荐信息