Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get streamed in XML into DAL to parse 1

Status
Not open for further replies.

zooxmusic

Programmer
Nov 24, 2004
96
US
Hi all,
I am very much still a novice at this stuff but I am learning more and more each day. I now understand (I think!) how a DAL works as far as Sql goes but I am now in the realm of xml. I can understand it if there is a static xml file but my problem is this.

My controller receives an xml document
Parse that document into domain object
Add domain object to db

I have the writing stuff done through DAOFactories and whatnut and understand how to do it because there is a datastore variable I get within the DAOSql file's but this xml thing has me upside down. There is no where to go get the xml from within the DAOXml file unless maybe I write it to disk but that seems silly. I have it in memory and don't need it written at all. It is streamed into me from the highest level. I am sure this is something simple I am just missing but never the less I am missing it. Could someone shed some light on how they would do this?

Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Hi again,
It wouldn't make sence to pass in the Document to the DAOFactory would it? Having 2 constructors;

DAOFactory()
and
DAOFactory(Document xml)

and depending on the constructor I can init the appropriate factory?

Doesn't seem right to me but seems that is where I cross over into the DAL and I have to get it in there.


Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Actually they are all static funcs in there so that won't work. I never call a constructor.

Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Now I see my problem, I am trying to use a DAO to gain access to both xml AND a db. What would be the best way to handle this?

Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Brian,
wassup man, where have you been? hehe

Ok, to be honest i didn't understand your Q until the line:

"Now I see my problem, I am trying to use a DAO to gain access to both xml AND a db"

Now let's putt all details aside, are you merely trying to persist/read from a storage medium?

- Edward J. Smith
 
Hey Ed, I have been trying to internalize all that I have been learning. I got a lot further and boy do I love this stuff. Now I look back on some of my questions and say "Jeez where you blind" to myself. So I am trying to see if I can get it without asking so much. Its all good and you and this forum are great.


Here is what I am trying to do:

I get and xml doc posted to me and I need to write that data into a db. Seems simple. But it's killing me.

So far I understand the DAL as far as an AbstractDAOFactory goes. And having an object that represents one row in a db and how to put that together with repositories/managers but every example I have seen that I learned from was mutually exclusive, db, text, xml or memory not more than one. Now it "seems" I have to do both, at least in my mind. In one aspect I have to create the object and read from an XML doc - An XmlDAOFactory and then I have to take that resulting object and write it to a db - a SqlDAOFactory. I guess I am doing something wrong because it didn't fall into place for me. I am trying to use the same DAOFactory class that returns an AbstractDAOFactory to do both -because both are exactly the same except different forms of storage.



So to answer you question - YES ;)




I really am not this long winded when I talk, I am always the one that tries to get to the point the quickest. I just can't do it with this. I suppose I am trying to let you know my thought process so you can straighten it out if it is wrong.


Thanx
Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
1. My controller receives an xml document
>>>This is your input data, except it's
in a more structured form. It's no different from
aggregrating data from many fields on a UI screen
into a composite structure.


2. Parse that document into domain object(s)
>>>Factories build objects from data.
Since you're dealing with an Xml document. Loop
through the nodes and build objects from each
node-set. (a nodeset is-like a row in a table)


3. Add domain object to db
>>> aPersonRepository.Add(aPerson);


Brian, seems like you're almost there. I don't know your main barrier here but, think repository. YES, I can repeat this forever. Repositories are your abstraction for a collection.

Add, Remove and Search for objects via repositories. They hide the ugly outside unobject-oriented world from obscuring your clean domain model.


given an input xml such as:
<CdCollection>
<cd>
<title>Rock: volume 1</title>
</cd>
<cd>
<title>Reggae: volume 2</title>
</cd>
</CdCollection>

I would loop through the "cd" nodes, each cd node will be reconstituted into a CD entity object.(your factory)


Then, hand it to repository:
aCDRepository.Add(aCD);


Repository routes it to DAL.
 
Oh, Ok. I was thinking I should use a DAOFactory to parse the XML into a list of domain objects. But you are saying a repository not a DAOObject correct?

Brian

Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
I got it (I think). Your awesome. Let me play with this and get it into my blood and I'll let you know how it turns out.

You know I actually enjoy this stuff fun when you know it is natural. Its like building a house. All I know is that I have been building houses out of bamboo and bubble gum for years and they would fall apart at the first stiff wind, but not anymore. I am on my way to build a mansion damnit.

Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
DAOFactory does not parse. It also should not create domain objects. Instead, shouldnt it return an instance of a DAO used to store objects? Thats its responsibility.

Your DAO only participates in low-level persistence, no parsing, no object creation.

Your repositories, will hide the DAO from your Domain and act like a collection (true oo). In a true Oo world, there is no relational data, there is only collections for persistence.

Parsing the XML doc into objects is better handled at the application layer. Should it not? Well lets see, Parsing an xml doc into domain entities is:

1. NOT realted to a UI responsibility
1. IS related to an Application specific thing
3. NOT related to the meaning of the Domain
2. NOT related to the infastructure




 
I have been building houses out of bamboo and bubble gum for years and they would fall apart at the first stiff wind, but not anymore.."

nice [thumbsup2]
 
Ok, I think I see my confusion. I have some implicit thought that DAO objects can go to a db, text file, memory and "XML". this last work screwed me up I think. Just because I have some data in an xml file does not mean that I should use a DAO object to access it. Is this correct?

Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
well DAOs do persistence. you may have many DAOS:
XmlDao
OracleDao

So, an XmlDao can access an xml file for storage or retrieval of data. But you mentioned that you get an xml doc from the controller. Since controllers are part of the application, i assumed that this xml doc is just data coming into the system that needs to be persisted.

If its coming into the system, its has to go through the same process as if you had a form for registration of a new Person (fields for firstname,age,lastname,address etc)
 
Right, that is what I messed up on. It is actually coming from my controller but my mind was thinking it is xml. So it must be handled through the DAL. Nice. Got it. Your awesome. Now I have to work on my UML and OOA/OOD because I know putting all of this on paper is the key. Especially because I am just beginning.

Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Hey Ed,
would you mind if I made a small example of what I am currently doing here and send it to you for your critique?

Brian


Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
I just realized I am totally confused on how to build my entity object from the xml. Damn!

MainController->creates IHandler object

***should this happen in the HandlerClass ?**************
IHandler gets EntityFactory
EntityFactory->getCDAssembler() ?
CDEntity cdEntity = CDEntity.build(xml);
CDDAO cdDao = DAOFactory.getCDDAO()
cdDao.add(cdEntity);

************************************
Help!!!
Maybe if you gave me an example like this. Stripped down just the main classes, who does what and name them properly (ie. repository, I don't think I even have one) I am thinking I am missing how to layer it.

Brian




Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
I also believe there are different vocabularies that may/or not be messing me up.

Does:
Repository = Factory which also ='s Assembler ?????


Brian

Spend like you don't need the money,
love like you've never been hurt and dance like nobody's watching!
 
Repository == a collection of something

example,


Cars.FindCarByColor(Color.Black);

Cars is the collection, it is the repository. Repository shields the Domain from the ugly database. Your domain model starts to strengthen naturally because storing items in collections is how the OO world persist data.

Cars.Add(aCar);


as you can see, it sports a rich collection like api. Internally Add() might delegate to a DAL for persisting that object. But you domain model doesnt know this, for all it knows, everthing is held in that repository. So its cleaner.

When, your DAL changes from SQLServer to Oracle next year, the domain model works with the repository in the same manner, the repository just delegates to the appropriate DAL.

let me know if that helps.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top