OOAD and Cassandra. How? - cassandra

I am trying to wrap my head around doing object oriented analysis and design when your canonical data source is Cassandra.
Specifically:
How do I maintain data consistency if data is duplicated among the denormalized cassandra tables?
How do I maintain a clean object design? Do I have to have a reference diagram that shows how my domain models map to the denormalized tables?
Thanks.

Essentially, the same way you would if you used a RDBMS as the data-store. Create OO domain-model classes. Access the data-store through an abstract interface, the persistence layer, which accepts and provides objects of those classes. Internally, have the persistence layer convert to and from your domain-model classes and Cassandra tables.

Related

Could someone please explain this quote, preferably in beginner's language?

On SQLAlchemy's documentation page the author starts with a philosophy,
SQL databases behave less like object collections the more size and
performance start to matter; object collections behave less like
tables and rows the more abstraction starts to matter.
I'm scratching my head trying to understand the idea behind these two sentences, but failed. Could someone give an example illustrate the idea here? Thanks.
When you are creating an application using an Object Oriented language and a SQL database, you are simultaneously working with two very different conceptual models for storing information:
The relational model says how to store data in tables and rows and how to link elements through keys and joins.
The object model establishes a way to store entities with attributes in memory (usually) and how to set links between them using pointers or references.
So, let's say that you have an User entity that is linked to addresses and other users in your application. Those entities will need to be stored in the form several tables in the database (users table, addresses table and a many to many table for associating users to users, for instance). At the same time, if your code uses object oriented constructs, users and addresses will exist in memory in the form of objects with references between them, pointing to objects of the same or different kind.
The thing is, moving information between those two different worlds is much much more difficult than it looks at first:
You might associate one object with one row in a table, but that is not always possible and sometimes a single object must be associated to multiple rows in different tables.
Inheritance and polymorphic behavior are particularly difficult to map to a relational model.
Traversing objects and querying the database are vastly different actions.
Performance factors to take into account in an object model and a relational model are completely different.
And those are just a few examples. ORMs such as SQLAlchemy are essentially translators that convert information from one world into the other and back.
What I think that Mike Bayer was trying to convey is: the more you adapt your entity information to the object model (lots of inheritance, polymorphism, traversal of objects, ...), the farther it will resemble the natural structure in a relational model and the more performance concessions you will be making. And the other way around: the more you design your tables to perform well and be optimized for your queries, the less they will adapt to a natural structure of objects.
Martin Fowler has a nice write-up about the need of this translation in this article: ORM Hate (from which I took the above image).
Edit: further clarification on the abstraction vs performance issue
At the end, I think that the bottom line of that SQLAlchemy presentation text is: many ORMs hide the relational side of the relational-object oriented translation to make things easier. With them you only have to worry about the object oriented side, and the library is in charge of taking away the burden of dealing with the database. You get persistence for your objects without having to deal with SQL. However, they incur in a performance penalty in doing so, because the details of working with the database are abstracted away and you have no control over them. And those details are essential when you have to optimize performance. SQLAlchemy takes the opposite approach. It hides nothign of the relational side, you are in control of how SQL is generated and when and when not use joins, subqueries and other SQL constructs. That makes it a much more complex library to learn, but at the same time you are in control of the whole relational-object oriented translation process.

How to keep data in Object

I have a table or tables in sqlServer. I want to take data from database and keep this table's data into objects like class, but I dont want to keep this data into dataset.
What are those ways to keep data into objects taking data from database?
How can I pass data into object but not in dataset or datatable?
ORM is what you should be looking for.
For .Net framework you can look into
Entity Framework
LINQ to SQL
NHibernate
Dapper
ORM is the solution as mentioned above.....
Better use entity frame work that is good for this purpose.......it will creates entity classes with all your tables in the database.
In short: as it is suggested in the comment, some type of ORM (Object relational mapping) will do that magic for you.
Good references on this topic are the followings:
4 Benefits of Object-Relational Mapping (ORM)
ORM mapping data to objects
DataObjects.Net - ORM Framework for RAD - Introduction
Edit: To choose the right ORM for your problem, look at this Wikipedia article
List of object-relational mapping software.

Whats the difference between ORM and ORP?

What is the difference between Object Relational Mapping(ORM) and Object Relational Persistence(ORP)?
From what i know ORM is a framework for mapping relational tables to application domain objects and relationships between them. So in ORM you would already have a Persistent data structure?
ORP consists of:
Entities
Database connection
Database
Mapping (ORM)
Etc..
We could almost say it is the same thing since ORM is a term which is used as ORP. Both are used to indicate the same thing.

Creating a meta model using UML convention and creating a data model out of it

Sorry if the question sounds too vague. I will improve based on your feedback.
I have managed to prepare a UML model of a problem domain. This is essentially a class diagram describing class attributes and aggregation relationships amongst classes. Intention now is to fill data.
For example, class-A aggregates N instances of Class-B. I would like to create a data model that has data for one instance Class-A and 5 instances of Class-B.
Basically, data pertaining to this meta model is available in a document (e.g. xls, framemaker) and it should be possible to read the source and populate the data model.
Are there tools that will let me create this data model? Please advise.
You have two options to creates your database model from our UML model.
You can use the UML model and then add a code generator to generate the database then finally reverse it with a database modeling tool such as erwin.
Another approach is to use the database modeling profile inside your UML model. It means that ypu model and add database stereotype related to java ORM.
Both works pretty well.

Whats the difference between Object Role Modeling and Object-relational mapping?

I have learn about Object role modeling but not about Object-relational mapping and I want to know if they are two ways of doing the same thing and what are the pros and cons? To me Object role modeling makes a lot more sense. Could you make a brief but easy to understand comparison if they can be compared. Cheers
Object Role Modeling: software modeling notation to, specially, define domain models. You can think of this language as an alternative to using UML class diagrams to design your database. More info here: http://www.orm.net/
Object-relational mapping: a set of strategies to bridge the gap between object-oriented programs and relational databases. It aims to allow the persistent storage of objects in a relational database structure
Object Role Modeling was invented by a team at Control Data around 1973, and named by Falkenberg. It is a modeling method rooted in linguistic analysis, and was formalised as a first-order logic by Terry Halpin, see http://orm.net. ORM is thus the original user of the acronym. ORM and related modeling languages are distinguished by being attribute-free. These languages contain only objects and object types (kinds of things), facts and fact types (relationships between individual things) and constraints (rules about what things and relationships may exist). No relationship has the master-slave characteristic like entity-attribute - this is a notion that only arises during physical mapping, as it's irrelevant to the underlying semantics of the domain.
Object Relational Mapping (which I always write O/RM) is a name for a method or family of tools that help translate data between relational form and object-oriented form. Both these forms use aggregate or composite things based on attributes (entity/attribute or object/attribute), but the principles for aggregation differ between the two approaches, so the same underlying semantics results in different data structures; hence the need for tools to help automate the translation. Furthermore, in ER or O-O analysis, the need to make early decisions about which things are objects/entities and which are attributes is forced, and this gives rise to a whole class of modeling errors that simply does not occur with ORM.
Of course, both relational and o-o models can be automatically derived from an ORM model, and the mapping between the derived forms is also automatic and painless. I suppose that's not done more often because it would make life too easy.
You are comapring Apples to Oranges.
Object Relational Mapping is all about trying to overcome the impedance msimatch between the object world and relational databases.
Activerecord for example is a ORM that wraps a row in a database.
Hibernate is another popular ORM
Just google for ORM wikipedia explains it much better
http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch

Resources