I have seen the ideas of domain models in UML, but I never got the chance to work with them in actual code. Now I see them in databases, particularly SQL coding, from this article
And there was a quote that mentions domain model classes:
I can design Domain Model classes
containing plain SQL as easily as I
can design classes that operate on the
database via an ORM layer. Keep in
mind that ActiveRecord is not a Domain
Model.
How do I create domain classes then? Does it differ when I'm in the "database context" when I'm in the "modeling context" or even the "programming context"?
A domain model has no notion of a database. It should be the logical representation of a problem domain. You've likely worked with domain models in every one of your projects to some degree.
To tie a domain model to a database, the Repository pattern makes for an excellent mediator.
Did you have a look at one of the Omondo UML examples which show how to use object approach and visualize your domain in an UML diagram ?
It seems to me that ORM modeling with UML is not a well established technology because only Omondo EclipseUML provides these ORM features ? The other UML tools can not generate Java annotation or reverse them. They generate code from a model but not ORM or JPA annotations because they directly generate a kind of database which is not for me an object approach. This is a non sense if UML tools generate database because database is not an object ? This is why the Omondo approach to generate ORM annotations and let the mapper do its job is what should be done. In my company we have created our model then let the database admin to add the UML stereotypes which are synchronized with the java annotation. finally we have passed all the project to the developer team. The code was very clean and easy to integrate later. It was a continuous integration from a model to the database using Eclipse and maven. It worked very well.
I have used UML and ORM in my last few projects. It is really very powerful !! I think that we will see more project in the future using ORM and UML modelling.
Related
I'm working on a project that need to run on App Engine and other Java Application Server. In App Engine we use datastore, and in other environment we will use traditional relational database (mostly MySQL).
I want know if it's possible that "have one JDO/JPA model that works on both".
If it's possible. How? Specifically, how do we handle the Key? Datastore required us to use it's own Key object or using "Key as encoded string", how do we port those keys to relational database.
If not, what would be the best practice? The idea we have right now is define abstract DAO, and have two set of DAO implementations. I believe the best way is using Objectify for datastore and JPA for relational database. But that way we could not leverage GWT RequestFactory (another technology we are using). Or can we?
Clearly JDO is designed to work on all datastores, whether RDBMS, ODBMS, document, map-based, web-based, document-based, file-based ... blah blah. Yes such portability is realistic. If you don't want portability you could use Objectify, but you say you want portability so that's not an option (so no idea why you think its the "best way"). You can use a String as PK in all datastores.
I don't know about GAE but I know JDO should be datastore independent so you can map your classes using JDO annotations and make sure while you are doing that, you aren't using any RDBMS based extensions (i.e. Datanucleus), i'm not sure if there are such extensions in the first place.
For keys, well obviously you shouldn't use GAE's but again, I'm not sure if it's a must or not.
I find it really hard to match the same "persistence" model on both a relational database and hierarchical database (the datastore here) since most of the time it requires thinking/structuring your data in a different way.
For example, you might need to duplicate data accross many entities in order to be able to run queries on it with the datastore.
From the few you said about your project, if you need to have it both in Google App Engine AND traditional servers (tomcat, JBOSS, WebSphere, whatever...) I would use Google Cloud SQL to keep my data model the same...
Or if you need a hierarchical database in both cases, install an open source one with your "traditional" servers...
What kind of projects are we talking about in the first place ? :)
If I choose RavenDB for a fairly standard CMS-like web application, what do I lose compared to SQL Server?
EDIT: There is a word "benefits" in the title which is a little controversial term. Maybe I should have said something like "possibilities" or "features", hope it's clear what I'm after.
A few things that come to mind (but I'm new to RavenDB so this is just a few suggestions, some may be wrong, I hope someone would provide a more complete and accurate list):
Quick but customizable administrative interface using ASP.NET Dynamic Data (there is some built-in Silverlight admin application but I'm quite sure that it wouldn't replace a full-fledged admin section in my case)
Possibly some querying capabilities? Or can Raven indexes replace virtually every SQL query I might think of?
Entity Framework integration (I know some people hate EF but I think that being an EF provider means that you can easily publish the data as OData, use EF code-first etc., right?)
Azure deployment (not true according to comments)
Myriad of SQL querying / management tools
A more complete / accurate list would be greatly appreciated.
(Note: I'm not saying that I will need all (or any) of those, I'd just like to understand what's going to be unavailable if I choose RavenDB. Also, please don't discuss RavenDB strengths, I am aware of them and they are easily digestible from the official website.)
You may want to look # these 2 recent blog posts by Ayende (RavenDB creator) on when you should use RavenDB and when you shouldn't.
When should you use ravendb
When should you not use ravendb
Beyond the technology, you should consider your team members as RavenDB is an adjustment in thinking for those of us who have backgrounds in RDBMS. What type of stretch will this be for those involved? Will your users expect reports and what will the say when you tell them that you did not consider answering the questions that they want answered when you create the indexes for the document database? While you get a big boost in productivity when designing and implementing your domain, document databases are different than SQL.
Quick but customizable administrative interface using ASP.NET Dynamic
Data (there is some built-in Silverlight admin application but I'm
quite sure that it wouldn't replace a full-fledged admin section in my
case)
ASP.NET MVC supports scaffolding based on POCOs since second version. But it's not so quick'n'dirty solution.
Possibly some querying capabilities? Or can Raven indexes replace
virtually every SQL query I might think of?
You should to think about your queries first. Raven DB is not reporting database.
Entity Framework integration (I know some people hate EF but I think
that being an EF provider means that you can easily publish the data
as OData, use EF code-first etc., right?)
You are so focused on tools. Code First is the way how you work with document databases. Why you need OData? RavenDB has REST API out of the box.
WCF RIA Services (Silverlight).
You'll need to do all that WCF plumbing work.
Initially we wanted to clearly separate our database into logically separated entities. However we ran into several conflicts with our domain service classes.
Now it seems that the best approach for working with complex database models is to load all tables/stored procedures/views into one entity model and then separating the functionality through the domain service classes/repository classes.
Thoughts ?
What are your architecture approaches for laying out entities ?
Also are there any performance pros/cons of having everything in one model ?
Maybe separating model into several diagrams is a good idea?
The latest build of Entity Developer gives an opportunity to create independent diagrams containing different entities from the model.
I'm a little confused here.
I have my POCO classes created with the entity framework modeled from the datbase.
Obviously, I'd like to use these classes in the client too (and any bookkeeping on them would be nice if I'd like to send them back and re-attach)
I looked through the classes generated for the WCF service reference and it seems a bit verbose to be sending over the internet, but it doesn't look like there's anything risky in there security-wise.
And yet, I can't find anything online about doing this. Am I going down a completely awful path?
Help?
EDIT : I suppose they're technically they're not POCO classes if i had them generated by the EntityFramework from the database; just to clear up any possible confusion.
This is a difficult question to answer without knowing more details about your system, but ultimately whether exposing your EF entities in the WCF service contract is the right path or not is influenced by the scope and requirements of the application you are developing.
Perhaps ask yourself the following questions which will hopefully guide your decision:
Is it likely your relational model and object model will need to diverge? This can be driven by a number of factors, but most commonly reporting requirements may enforce a certain design on your database schema (for performance) that you do not want to reflect in your application object model. Using the DB generated EF entities throughout the application layers can bind you to this database design
Are you concerned that changes to your database schema may require your clients to regenerate their service references? Again, using the EF entities throughout your application tiers means any changes implemented in your DB schema (whether of concern to the client or not) may bubble up to the service interface, potentially breaking client compatability with that interface
Is performance a concern? As you mentioned, the generated classes are verbose. You are likely to be transporting unnecessary baggage across the wire, which could be optimized.
Are you concerned about exposing the implementation details of your database schema and persistence mechanism on the wire and to your clients? Given you have generated the model from the database there are likely to be properties that expose information about your schema and persistence mechanism that are redundant from a client's perspective.
In summary there may be a limited number of cases where exposing the EF entities may be acceptable but typically I would design for change and implement some sort of pattern where you map your EF entities to light-weight "persistence-ignorant" POCOs at your repository layer. EF 4.0 does provide the ability to code up a context that returns POCOs, but on my current project we use the codegen'd context and then use automapper to map the EF entities to our data contracts. Outside of the repository layer nothing is aware of the EF entities and I feel this allows for a more maintainable and robust design.
...What is it called?
More elaborate: For my application I created a nice business model to work with as in-memory objects. It's storage and view agnostic. Now, for the storage layer, there's a database: I'll construct SQL queries (the fewer the better) that selects/joins etc. all data I need from the relevant tables. A kind of "middle layer" takes the query(s) result and constructs business objects with all relations.
Questions: What do you call this approach? What are the best practices?
This takes place in a .NET C# project but that's not relevant to this design question.
(I found question 441532 to be very similar but I'm interested in more design input)
Note: I do not take the ORM approach that relies on tools that do this automatically because the application requires only selected data from a relatively large database.
I think it's called ORM, or object-relational mapping.
NHibernate is one example of just such a thing.
It's generally called DDD - Domain Driven Design.
https://stackoverflow.com/questions/tagged/ddd
https://stackoverflow.com/questions/tagged/domain-driven-design
There are different ORM tools. Linq to SQL do a 1:1, which is not what you want.
What you're talking about overlaps with Domain Driven Design, where your design is driven by the domain, not the Database.
In this case, if you are using a relational Database you still need an ORM, and ORMs like Entity Framework and NHibernate allow you to flexibly "map" your entities to your database in any way you want, in a way that, if your Database needs to change for whatever reason, or you Entities have to change, for whatever reason, all you need to change is the middle "mapping" layer.
take a look at fluent nhibernate