Service, becauseSoapOrIteratorThe data objects are always closed before the layer. To learn how to return data from the Database Control Xmlbeans For more information, Please Download Additional resources attached to this article ( 1.69 MB ). Which data type can beWebWhich components are widely used at the same time? There are two data types that meet the requirements: customJavaXmlbeans. NextArticleIt shows you how to create a database control that provides xmlbeans data. There are two main advantages of converting database data to xmlbeans: (1) xmlbeans can beWorkshopComponent usage; (2) Data in xmlbeans format is flexible and easy to process. I will start from explaining what xmlbeans is, and then describe how to create a database control that can return xmlbeans to the client. Note that there isXmlbeans_databasecontrol. This partner project contains items that can be returnedThe example Database Control of The xmlbeans data type. XmlbeanWhat is? Xmlbean is an XML document with Java APIs. This API is used to parse and manipulate data in XML documents. TypicalXmlbeanYou can use the following format to represent database data.
<! Doctype xcustomer> <Xcustomer xmlns = "Java: // database/customer_db" Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"> <Xcustomerrow> <Custid> 1 </custid> <Name> Fred Williams </Name> <Address> 123 slugger circle </address> </Xcustomerrow> <Xcustomerrow> <Custid> 2 </custid> <Name> Marnie Smithers </Name> <Address> 5 Hitchcock Lane </address> </Xcustomerrow> <Xcustomerrow> <Custid> 3 </custid> <Name> Bill Walton </Name> <Address> 655 tall timbers road </address> </Xcustomerrow> </Xcustomer> |
XmlbeanAPI,,Assume thatIndicates the precedingDocumentFred Williams. String name = custbean. getxcustomer (). getxcustomerrowarray (1). getname ();
Update the Database Control to returnXmlbeanInstead of returningRowset,ResultsetOrIterator,There are no restrictions. This is notResultsetAndIteratorLayer class (WebFormat data is also very easy to operate,OfAPI. Schema UseXmlbeanThe first step of the class is fromXmlbeanClass to createSchema. TheSchemaThe data returned from the database must be modeled. If you are writing your ownSchema, At least,SchemaThe element must have the same name as the field in the database, which allows the data returned from the database to be automatically mappedXmlbean. To be a database orRowsetControl automatically generatedSchema, Follow the steps below. 1.InDesign viewDisplays the Database Control File. 2.Select a method for returning data from the database (the method for not returning data, suchCreate TableStatement .) 3.Tab markedSQL. 4.AndSchemaDerivedXmlbeanSlaveEditor rowset SchemaText (this dialog box does not support the right-click operation, you must useCTRL + cTo copySchemaNote,XcustomerIn the following two locations: <XSD: element name = "xcustomer "... <XSD: element name = "xcustomerrow"> 6.Save textSchemasFile. Make sure thisXSDStart. File,GeneratedXmlbeanType can be returned by using methods in the Database Control.XmlbeanClass will be displayed inSchemaProjectXML bean classesFolder. EditSchemaCreate a new"Document"Type Note that only one generated type is "document" xmlbean type: xcustomerdocument. For other types, xcustomerdocument. xcustomer and xcustomerdocument. xcustomer. xcustomerrow can only be used to reference the "document" type. This difference is especially important because only the "document" type is eligible to directly participate in the business process or be transferred to the web service. For this reason, you may want to modify your schema to include it in the "document" type to correspond to other types in the schema, especially when you have a very large schema, this is especially true when the schema contains multiple nested types defined according to a single "document" type. To generate a new document type for some elements, move this element to make it a top-level element in the schema. In the following example, the xcustomerrow element is moved to the top layer of the solution. its initial position has been replaced by a reference element: <XSD: Element ref = "xcustomerrow"/>.
<? XML version = "1.0" encoding = "UTF-8"?> <XSD: schema targetnamespace = "Java: // database/customer_db" Xmlns = "Java: // database/customer_db" Xmlns: XSD = "http://www.w3.org/2001/XMLSchema" Xmlns: wld = "http://www.bea.com/2002/10/weblogicdata" Elementformdefault = "qualified" attributeformdefault = "unqualified"> <XSD: element name = "xcustomer" Wld: defaultnamespace = "Java: // database/customer_db" wld: rowset = "true"> <XSD: complextype> <XSD: Choice maxoccurs = "unbounded"> <XSD: Element ref = "xcustomerrow"/> </XSD: Choice> </XSD: complextype> </XSD: Element> <XSD: element name = "xcustomerrow"> <XSD: complextype> <XSD: sequence> <XSD: element name = "custid" type = "XSD: int" wld: jdbctype = "integer" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "name" type = "XSD: string" wld: jdbctype = "varchar" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "Address" type = "XSD: string" wld: jdbctype = "varchar" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "city" type = "XSD: string" wld: jdbctype = "varchar" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "state" type = "XSD: string" wld: jdbctype = "char" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "Zip" type = "XSD: string" wld: jdbctype = "varchar" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "area_code" type = "XSD: string" wld: jdbctype = "char" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> <XSD: element name = "phone" type = "XSD: string" wld: jdbctype = "char" Minoccurs = "0" wld: tablename = "weblogic. Customer" nillable = "true"> </XSD: Element> </XSD: sequence> <XSD: anyattribute namespace = "http://www.bea.com/2002/10/weblogicdata" Processcontents = "Skip"> </XSD: anyattribute> </XSD: complextype> </XSD: Element> </XSD: schema> |
,Document":XcustomerdocumentXmlbeanType Once you generateXmlbeanType, You can import these types to Your Database Control.
Import databasecustomerdb. xcustomerdocument; Import databasecustomerdb. xcustomerdocument. xcustomer; Import databasecustomerdb. xcustomerdocument. factory; |
XmlbeanType can be returned from the control's method.
/** * @ JC: SQL statement = "select custid, name, address from customer" */ Public xcustomerdocument findallcustomersdoc (); |
The data returned from the query is automatically mappedXmlbeanBecause the database field name andXmlbean. Related Topics · Java types generated from user-derived schema types · @ JC: sqlannotation |