views:

119

answers:

6

This is targeted at Technical Leads and Architects, but Anyone can answer this - all thoughts are welcome - have fun with it.

I want to abstract a large database store (relational, OLTP) from the application layer by having the application consider the database as a service. The natural way of doing this is by calling sprocs, but traditionally these follow CRUD paradigms and in keeping with my abstraction thinking I want to abstract away all knowledge of data structures within the database and concentrate on business process.

So instead of having 'Save Invoice' business process be this....

  1. Start Transaction
  2. Create Invoice Header
  3. For Invoice Line Items
    1. Create Invoice Line Items
  4. Commit Transaction

... instead I want to pass into the database structured data representing the invoice.

I can pass down an XML document containing the invoice, but this is what I want to avoid on the Database side:

  1. Parsing XML
  2. XML Validation
  3. Parameter extraction and binding into Oracle PL/SQL objects

Off-course, in all cases, no matter the solution, this must be done. However, I don't want to pay the XML document penalty (the angle bracket tax).

Hence the question - what is the most efficient way to send and receive and structure data into Oracle stored procedures?

I would like to hear from those who want to argue for JSON, ATOM or other formats.

Also consider native or binary mechanisms to achieve this. What about constructing and sending in Oracle tables (memory datasets)? Has anyone done this before? What where your experiences?

A: 

You can create a collection, fill it on the client side, pass it into the Oracle procedure and do set-based operations with it:

INSERT
INTO    dest_table
SELECT  *
FROM    TABLE(:mycollection)
Quassnoi
A: 

That depends. You can store the data in any form as a LOB. The main reason why no one is doing this is that you store data in a database so you can search through it. The Internet was a nice idea until Google came around and made it possible to find things.

So you must parse the data in some way. You can parse it on the client and send SQL insert/updates. If you do this with your favorite OO language, you'd have an OR mapper (which can load and save "objects" in plain SQL tables). This way, the heavy lifting (the parsing) is done on many clients while the database just stores and searches the data.

Aaron Digulla
A: 

I want to abstract a large database store (relational, OLTP) from the application layer by having the application consider the database as a service.

That's what DAO layer is for. For application code DAO is a persistence layer (service in your terms). DAO knows how to store a structured document.

I presume you have to do SQL queries against the stored documents.

Though there is an Oracle-specific XML format, I'd refrain from using it as it ties your code to Oracle. As long as standard SQL works, use that.

Vladimir Dyuzhev
Yes, off-course everyone knows DAO objects. They abstract the application from the DB, but are themselves affected by changes in the DB. We can abstract this layer further if we consider only calling stored procedures. This is usually implemented by calling 'CreateInvHeader' and 'CreateInvDetails' as per my example. This is not complete abstraction at the business process level, which is what I am trying to achieve. Now, if I pass the database a structured document I have better abstraction and have little need to build aDAO layer. In large teams with dedicated DB dev's this is may be a plus.
cmdematos.com
Sorry, abstraction should stop somewhere. :) As a Java programmer I prefer to stop it in DAO layer, which knows details of data storage.
Vladimir Dyuzhev
A: 

I don't understand why one would like to do anything like 'parsing' and 'validation' on a database.

It may be that we use very heavily loaded databases at my work so my point of view is kinda subjective, but basically anything that can be done outside of the database is done outside since the database is a bottleneck for most applications (and the 'outside' can be parallelized easily).

Here is what we use at work:

| ID | Index 1 | Index 2 | Index 3 | ... | Big Blob of Data |

Basically, the indexes allow for searchability and the 'Big Blob of Data' is under the control of the applications. It is usually compressed serialized (versioned) data (some teams store about 300KB in this blob ;) ).

Of course, this requires a front-end (or library) to actually perform the serialization+compression or decompression+deserialization in a uniform manner.

It works well, ... but then as I said databases are a bottleneck for us so we try to externalize the load as much as possible.

Matthieu M.
If we pass in json/atom or xml we would need to parse and validate the inbound message. In particular, if we wanted to consider the DB as an (internal) service then we would want to parse and validate the inbound data, not for business rules, but just enough to parsed data to table fields. By your example I see you are considering a relational DB as an ObjectDB. Interesting.
cmdematos.com
Why do you use a database anyway? If you just store a blob with an index, there are other ways to do it, e.g. ISAM files. With your storage scheme, you lose 95% of the RDBMS' functionality anyway.
ammoQ
We do agree... unfortunately the technology choices are limited by the environment. We need a single storage point accessible from a hundred different machines that handles the transaction principle and obey the ACID laws. Throw in the need to support around 1500 read per second. Oracle does it and we already had a lot of Oracle instances.
Matthieu M.
A: 

Maybe investigate Object-Relational views.

See these links for starting points...

Oracle 9i Docs - "Applying an Object Model to Relational Data"

Ask Tom - "Relational VS Object Oriented Database Design"

Paul James
+1  A: 

Since you use Oracle, parsing XML in a stored procedure is not a big deal. IMO there are only three sensible ways to go:

  • Use DAO on the clients that know the database structure
  • Use stored procedure so you have a little bit of abstraction
  • Use XML

Any other structured text format (JSON etc.) is inferior, since XML is the format you already have a parser for in Oracle.

ammoQ