【发布时间】:2014-08-07 23:48:43
【问题描述】:
我今天看到一个已经写好的旧 Java 代码,其中包含以下几行:
STRUCT accDetail = new STRUCT(t_account_details, conn, itemAttributes);
STRUCT[] accDetails = {accDetail};
这个 STRUCT 是什么样的数据类型?
谢谢
【问题讨论】:
标签: java arrays type-conversion
我今天看到一个已经写好的旧 Java 代码,其中包含以下几行:
STRUCT accDetail = new STRUCT(t_account_details, conn, itemAttributes);
STRUCT[] accDetails = {accDetail};
这个 STRUCT 是什么样的数据类型?
谢谢
【问题讨论】:
标签: java arrays type-conversion
它只是一个普通的 Java 类,有人为它取了一个奇怪的名字。看看你是否有它的任何文档,或者你的 IDE 是否识别它,因为看到你的问题的人不太可能知道这个类。
【讨论】:
在这种情况下,STRUCT 似乎是一个命名错误的类。类通常命名如下:
“类名应该是名词,大小写混合,每个内部单词的第一个字母大写。尽量保持你的类名简单和描述性。使用完整的单词——避免首字母缩略词和缩写(除非缩写被更广泛地使用而不是长格式,例如 URL 或 HTML)。”
更多信息请参见Naming Conventions。
根据 Noman K 的评论,请参阅 (http://docs.oracle.com/cd/E18283_01/appdev.112/e13995/oracle/sql/STRUCT.html#STRUCT_oracle_sql_StructDescriptor__java_sql_Connection__java_util_Map_)
public STRUCT(StructDescriptor type,
java.sql.Connection conn,
java.lang.Object[] attributes)
throws java.sql.SQLException
Constructor. The raw bytes are computed at this time or a copy of attributes is made. In any event the caller is free to modify the array without affecting the values held in the STRUCT. For inherited object types we must check that the descriptor indicates that the type is instantiable. That database does not check on e.g. insertion but only on PL/SQL object creation. So we have to check here, too. There is an argument to be made that there is a good use for the STRUCT instance to carry data around and that the error ought to be when an insertion or udpate is attempted. But this keeps the "not instantiable" rather than "not storable" notion. And is is much more simple.
Parameters:
type - the SQLStructType used to convert the type to
attributes - the array specifying the attributes to be converted to raw bytes.
Throws:
java.sql.SQLException
See Also:
oracle.sql.SQLStructType
【讨论】:
从代码sn-p来看
STRUCT accDetail = new STRUCT(t_account_details, conn, itemAttributes);
STRUCT[] accDetails = {accDetail};
STRUCT 属于 STRUCT 类型,尽管它不遵循 Java 命名约定。 STRUCT 是用 new 关键字和 STRUCT 构造函数实例化的,这表明它是一个类,Java 中的所有类都是它们所代表的名称类型。例如。 String类是String类型,Date类是Date等。
【讨论】:
如果您使用的是 IDE,例如 Eclipse,那么只需单击 STRUCT 并按 F3。它会带上类定义,你可以用它来找出类是什么。
但无论如何,这不会像 c++。
【讨论】:
根据STRUCT Javadoc,
- 它是通用 JDBC Struct 接口的 Oracle 实现类。
- 它包装了 Oracle 对象类型的“原始字节”。
Java 使用它通过 JDBC 与 Oracle 关系数据库实例进行交互。根据 Oracle 文档:Working with Oracle Object Types
如果您选择不为 Oracle 对象的 SQL-Java 映射提供自定义 Java 类,则 Oracle JDBC 会将对象具体化为 oracle.sql.STRUCT 类的实例。
【讨论】: