mravinale

Handling Concurrency (Versioning)

April 19, 2011

The Problem:

The Scenario is very simple, if we(A user) retrieve from the database some information and before doing an update ,another user(B user) modifies that table before us, Our modifications(A user modifications), will overwrite the B users changes.

Handling the problem: Pessimistic and Optimistic Concurrency

Pessimistic concurrency involves locking the data at the database when you read it.  You essentially lock the database record and don’t allow anyone to touch it until you are done modifying and saving it back to the database.  Here you have 100% assurance that nobody will modify the record while you have it checked out.  Another person will have to wait until you have made your changes.

Optimistic concurrency means that you read the database record, but you don’t lock it.  Anyone can read and modify the record at anytime and you will take your chances that the record is not modified by someone else before you have a chance to modify and save it.  As a developer, the burden is on you to check for changes in the original data ( collisions ) and act accordingly based on any errors that may occur during the update.

Handling the problem with NHibernate and Gsf concurrency models:

Version control – Numeric

image

In this case every time that we do some update, the Version property value will
be incremented, if someone has an older version of the entity and wants to do an update
StaleObjectStateException will be thrown.

image

 

 

Version control – TimeStamp

image

This case is basically the same but using a TimeStamp instead of an integers, is a little bit less secure
but some legacy applications still using this approach and we can reuse the Db.

image

You can do a quick test in order to see how it works, in this case we are using the TimeStamp Case:

image

 

Really hope this could help you.

the GenWise Team

Posted in General, NHibernate | Leave a comment
mravinale

GSF NHibernate extensions – bidirectional mapping

March 20, 2011

We are proud to anounce the new release of GenWise Software Factory(GSF) , we have a lot of new features that we are going to show along of blog posts.

Today we are going to explain how to do bidirectional mapping in our object model from our relational model, when we have a relationship many-to-one in our database.

As is well know in the relational model we have a single reference form one table to another in order to stablish the associations many-to-one(a foreign key in one table is referencing the primary key column(s) of the target table). enaugh to navigate from one to another or retrieve each other information.

Normally with NHibernate we should add the association <many-to-one> into the mapping file with the property unique=true in order to use this association as one-to-one.

Example:

<many-to-one name=Customersclass=Customersunique=true>
<
column name=`CustomerId`/>
</
many-to-one>

With this new release(version 0.1.965) we are able to do this using the GenWise Software Factory(GSF) Business Object Model(BOM).

Let’s try it:

(Click the images to see the full size, and detail)

1 – One’s that we’ve imported the database schema we can see clearly that we’ve a relationship many to one in our dbSchema, let’s test the nhibernate mapping. For that we need to do right click -> tasks -> CreateBOM from DbShema.

image

 

2 – As you can see we have the Object model representation of the entities and relationships, and we have already selected Multiplicity: Many to One.

image

3 – In order to build our Nhibernate bidirectional mapping for data Access, first we need to add the NHibernate extension, and select Is Unique Property to True.

image

4 – Add the inverse relationship from customers to Orders, and we aware that this relationship has to be one-to-one.

image

5 – Ones that we changed the multiplicity from the new relationship, add the unit test extension, it would be nice to see our project working, right?

image

6 – Ok, we have everything ready, lets generate our project.

image

7 – Take a look at the many-to-one setting, this will allow us to use this relationship as one-to-one and be able to do bidirectional navigation.

image

8 – Now be have our entities and test, ready to use!

image

Remember to install Nunit in order to do these test and see how everything is working. Take a look of this image, we know from our order(Entity) which customer is related.

image

And now the inverse case, from customers know wich customer is related, just doing a couple of clicks!

image

I really hope this blog post may help you to build great business applications using the potential of GenWise Software Factory and NHibernate.

GenWise Team.

Posted in GSF, NHibernate | Leave a comment
 
stalamoni

Welcome to the GenWise blogs!!!

September 23, 2010

Hi everybody,

This is my first entry in our new company blog!

We decided to create this space so we can  share our views/ideas over our product, show features using a less formal approach than in our product documentation, talk  in general about .NET development techniques, etc.

We have worked hard the last couple of months to get to this point. We are closing down v1.00 of GSF (GenWise Software Factory).

I hope you find the content useful and we definitively appreciate your feedback!

Posted in General, GSF, Highlight | Leave a comment