Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 2002, Ronald Bourret, XML-DBMS Middleware for XML and databases Ronald Bourret O'Reilly Open.

Similar presentations


Presentation on theme: "Copyright 2002, Ronald Bourret, XML-DBMS Middleware for XML and databases Ronald Bourret O'Reilly Open."— Presentation transcript:

1 Copyright 2002, Ronald Bourret, http://www.rpbourret.com XML-DBMS Middleware for XML and databases Ronald Bourret http://www.rpbourret.com O'Reilly Open Source Convention, Marina II

2 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Overview Introduction Object-relational mapping Mapping language Using XML-DBMS

3 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Introduction

4 Copyright 2002, Ronald Bourret, http://www.rpbourret.com XML-DBMS Transfers data between XML documents and RDBMSs »Has capabilities similar to HiT Allora, DB/XML Transform, SQL Server, DB2, Oracle 8i Based on an object-relational mapping Best for data-centric documents »Can handle document-centric documents Open Source / public domain Available in Java (1.x, 2.0) and PERL (1.x)

5 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Features (version 2.0) Command line and programmatic interfaces XML-based mapping language »Automatic map generation from DTDs and database schemas Inserts, updates, deletes, and selects Heterogenous joins Customizable string formatting and key generation Parser and database independent

6 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Object-Relational Mapping

7 Copyright 2002, Ronald Bourret, http://www.rpbourret.com A simple example There is an obvious mapping from this document... bbb ccc ddd

8 Copyright 2002, Ronald Bourret, http://www.rpbourret.com A simple example (cont.)... to this object... bbb ccc ddd object A { B = "bbb" C = "ccc" D = "ddd" }

9 Copyright 2002, Ronald Bourret, http://www.rpbourret.com A simple example (cont.)... to a row in this table bbb ccc ddd object A { B = "bbb" C = "ccc" D = "ddd" } Table A B C D......... bbb ccc ddd.........

10 Copyright 2002, Ronald Bourret, http://www.rpbourret.com A more complex example Gallagher Industries 020915 A-10 12 10.95 B-43 600 3.99 This XML document...

11 Copyright 2002, Ronald Bourret, http://www.rpbourret.com A more complex example (cont.) object Order { number = 1234; customer = "Gallagher Industries"; date = 020915; items = {ptrs to Item objects}; } object Item { number = 1; part = "A-10"; quantity = 12; price = 10.95; } object Item { number = 2; part = "B-43"; quantity = 600; price = 3.99; }... maps to these objects...

12 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Orders Number Customer Date 1234 Gallagher Industries 020915......... Items SONumber Item Part Quantity Price 1234 1 A-10 12 10.95 1234 2 B-43 600 3.99............... A more complex example (cont.)... which map to these rows

13 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping performed at schema level Mapping requires “effective” XML schema / DTD Actual XML schema / DTD not required class A { String B; String C; String D; } CREATE TABLE A ( B VARCHAR(10) NOT NULL, C VARCHAR(10) NOT NULL, D VARCHAR(10) NOT NULL )

14 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Objects are data-specific... Different for each DTD (schema) Model the content (data) of the document... 020915... 12 Order Customer Item Part

15 Copyright 2002, Ronald Bourret, http://www.rpbourret.com... not the DOM Same for all XML documents Model the structure of the document Element Attr (Order) (OrderNumber) Element Element Element (Customer) (OrderDate) (Item)............ 020915... 12

16 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Objects not instantiated Data transferred directly between XML and database Objects used only to visualize the mapping XML data binding products instantiate objects »Castor »JAXB »Zeus »...

17 Copyright 2002, Ronald Bourret, http://www.rpbourret.com The basic mapping

18 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Element types are data types “Simple” element types have PCDATA-only content “Complex” element types have element or mixed content and/or attributes <!ATTLIST Customer CustNum CDATA #REQUIRED Name CDATA #REQUIRED Address CDATA #REQUIRED>

19 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping “complex” element types Map complex element types to classes...... which are mapped to tables (class tables) class A {... } class A {... } Table A...

20 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping content models Map references to simple element types to scalar properties...... which are mapped to data columns class A { String b;... } class A { String b;... } Table A Column b...

21 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping content models (cont.) Map references to “complex” element types to pointer/reference properties...... which are mapped to primary / foreign key columns class A { String b; C c;... } Table A Column b Column a_pk... Table C Column a_fk... class C {... } class A { String b; C c;... } class C {... }

22 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping attributes Map attributes to scalar properties...... which are mapped to data columns class A { String b; C c; String f; } class A { String b; C c; String f; } Table A Column b Column a_pk Column f Table C Column a_fk...

23 Copyright 2002, Ronald Bourret, http://www.rpbourret.com The basic mapping: reprise Map “complex” element types to classes, then to tables Map content models to properties, then to columns Map attributes to properties, then to columns Join class tables with primary key / foreign key pairs

24 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Some important points

25 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Map each reference separately Map references separately for each content model True for references to simple types and complex types class Chapter { String title; Section[] sections; } class Appendix { String title; Section[] sections; }

26 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping can change data types Can map “simple” data types to any scalar data type class Part { String number; float price; } CREATE TABLE Part ( number CHAR(10) NOT NULL, price REAL NOT NULL }

27 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping can change names XML schema, object schema, and relational schema can use different names class PartClass { String numberProp; float priceProp; } CREATE TABLE PRT ( PRTNUM CHAR(10) NOT NULL, PRTPRICE REAL NOT NULL )

28 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Primary and foreign keys Primary key on “one” side of one-to-many relationship May be in table of parent or child 123 020915 1 ABC 12.95 3... Table Orders Number, Date Table Parts Number, Price Table Items SONum, Num, Part, Qty

29 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Handling order Object and relational schemas have no concept of order Store order in mapping (has limitations)...... or in separate property / column (no limitations) class A { String b; int bOrder; C c; int cOrder } Mapping for A: B at position 1 C at position 2

30 Copyright 2002, Ronald Bourret, http://www.rpbourret.com No transformations XML and database schemas must have same structure »Use XSLT when they don’t XML XML Database Database XML XML XSLT Map Map XSLT XML query languages can perform transformations

31 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping Language

32 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping language Maps XML schema to relational schema »Declares relational schemaa »Declares object view of XML document »Maps object view to relational schema Many options »Key generation »Character formatting »etc.

33 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Declaring database schema Orders Number CustNumber Date

34 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping complex element types (classes) to tables... property, related class, and inline class maps... Orders Number CustNumber Date...

35 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping simple element types (properties) to columns Orders Number CustNumber Date... 020915...

36 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping attributes (properties) to columns Orders Number CustNumber Date...

37 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Mapping parent/child (inter-class) relationships to keys Orders Number CustNumber Date Items SONumber Number Product Qty... 020915...

38 Copyright 2002, Ronald Bourret, http://www.rpbourret.com “Inlining” complex element types... property, related class, and inline class maps... Customers Number Name Street City... Gallagher, Inc. 123 Main St. Chicago...

39 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Additional mapping features Distribute document across multiple databases Single- and multi-column keys Generate keys in database or custom class Store order in map or database Custom character formatting Support for mixed content Support for namespaces...

40 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using XML-DBMS

41 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using XML-DBMS 1.Write or generate a map file 2.Write an action document (insert, update, delete) 3. Write a filter document (select, delete) 4. Call XML-DBMS from: »Command line »Your application (high- or low-level API)

42 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Generating map files Can generate from DTD or database schema Usually need to customize by hand »Fix names »Optimize mapping (identify keys, inline classes, etc.) »Add formatting »... Can generate CREATE TABLE statements or DTD

43 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Action documents Used by insert, update, and delete Specify default action and per-class actions Supported actions: »Insert »Soft insert »Update »Update-or-insert »Delete »Soft delete »None

44 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Action documents (cont.)

45 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Filter documents Used by select and delete Specify additional WHERE conditions Support named parameters Map + filter = query

46 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Filter documents (cont.) 10" />

47 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using the command line Use the Transfer tool Pass a set of property-value pairs c:> java org.xmlmiddleware.xmldbms.tools.Transfer property=value [property=value...]

48 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using the command line (cont.) Specify properties explicitly...... or store in property files c:> java org.xmlmiddleware.xmldbms.tools.Transfer Driver=sun.jdbc.odbc.JdbcOdbcDriver DataSourceClass=org.xmlmiddleware.db.JDBC1DataSource URL=jdbc:odbc:xmldbms User=ron Password=scrumps ParserUtilsClass= org.xmlmiddleware.xmlutils.external.ParserUtilsXerces Method=StoreDocument MapFile=orders.map ActionFile=orders.act XMLFile=orders.xml c:> java org.xmlmiddleware.xmldbms.tools.Transfer File1=db.props File2=xerces.props File3=storeorder.props

49 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using the high-level API // Create a new Transfer object Properties p = new Properties(); p.load(new FileInputStream("xerces.props")); Transfer t = new Transfer(p); // Initialize the data source p.load(new FileInputStream("db.props")); t.setDatabaseProperties(props); // Store a document t.storeDocument(null, "orders.xml", "orders.map", "orders.act");

50 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using the low-level API // Set up the parser ParserUtils utils = new ParserUtilsXerces(); XMLReader reader = utils.getXMLReader(true); // Create a map object MapCompiler mapCompiler = new MapCompiler(reader); InputSource is = new InputSource(new FileInputStream("orders.map")); XMLDBMSMap map = mapCompiler.compile(is); // Create an action object ActionCompiler actionCompiler = new ActionCompiler(reader); is = new InputSource(new FileInputStream("orders.act")); Actions actions = actionCompiler.compile(map, is);

51 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Using the low-level API (cont.) // Create a data source and data handler for our database, then // bundle these into a TransferInfo object. DataSource ds = new JDBC1DataSource("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:xmldbms"); DataHandler dh = new GenericHandler(ds, null, null); TransferInfo ti = new TransferInfo(map, null, handler); // Create a new DOMToDBMS object, open the document, and call // storeDocument to transfer the data. DOMToDBMS domToDBMS = new DOMToDBMS(); is = new InputSource(new FileInputStream("orders.xml")); Document doc = utils.openDocument(is); domToDBMS.storeDocument(ti, doc, actions);

52 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Current status Java version 1.01 available from Web site Java version 1.02 ships with JBuilder 5 and later PERL version 1.03 available from Web site »Has filtering capabilities Java version 2.0 alpha available from Web site »Feature complete »Needs code cleanup, bug fixes, documentation 500+ people on mailing list

53 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Resources XML-DBMS home page »http://www.rpbourret.com/xmldbms/index.htm XML-DBMS Source Forge site »http://sourceforge.net/projects/xmldbms/ Mapping DTDs to Databases »http://www.xml.com/pub/a/2001/05/09/dtdtodbs.html

54 Copyright 2002, Ronald Bourret, http://www.rpbourret.com Questions? Ronald Bourret http://www.rpbourret.com


Download ppt "Copyright 2002, Ronald Bourret, XML-DBMS Middleware for XML and databases Ronald Bourret O'Reilly Open."

Similar presentations


Ads by Google