How Open Acces Works exactly

Thread is closed for posting
4 posts, 0 answers
  1. Thomas Kaske
    Thomas Kaske avatar
    7 posts
    Member since:
    Nov 2009

    Posted 18 Nov 2009 Link to this post

    Hello i have a question about how open access works in the background. I have read all the documentation and the blogs but i just dont understand how Open Access Works exactly?

    Well let me begin. Lets say I have a database with 2 tables customer and orders. Each costumer can have more orders (1:n).

    Lets say i have mapped everything put some data inside the table thorugh the scope.

    Now my question is what is happening exactly when i create a new scope in the memory. Writing getNewScope(). What happens. I understood it that in this moment in the memory (RAM) or 1st level cache an object container is created and only one object with the connection is made. When i make a query for example get me all customers who ordered more than once alle the customer objects with the orders are loaded into this objectcontainer?! Now every object has a unique id!is it the primary key or what is it?
    Lets say this query gives me 10 results.
    Now I do another query where i want to hav all customers who ordered mor than twice. Now this result lets say should give me 5 customers. But I have already thos 5 in the cache because of the first query. How does the OR Mapper know that he doesnt have to get those 5 customer object from the database. What is he comparing????

    Second scenario i want to update a customer data. Well i have to open a transaction and change for example the address and then commit it. Well how does he know that something changed? I guess there is a flag but to what does the mapper compare the changed object or does he see taht something is changed and he sets the flag??

    3 Scenario ist what happens if i work on changes for 20 minutes and in this time someone changed the same record in the database, but i am still working on the unchanged what is the OR Mapper doing in that situation when i commit????

    I would really appreciate when someone explains it exactly to me because i am kind of confused about taht whats happening behind the scenes.

    tomek
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Nov 2009 Link to this post

    Hi Thomas Kaske,
    1. You are right. The object in memory knows always about the pk in the database, that is the only way we can find the same row in update and delete cases. With this id/pk in memory we also make sure that the data is loaded only once per object scope. We have a weak reference list per scope that takes care about that.
    2. The enhancer replaces all direct read and write access to persistent fields by a method call. In this method call we mark a field as dirty (and keep the original value if the CC mode is changed) during write and load the data during read if the data is not yet loaded. In scope.txn.commit we collect all those dirty information, plus new and delete and generate the insert, update and delete statements.
    3. It depends which CC mode you are using. In changed mode we only check the values of the dirty fields, in version field mode we have a special counter column that we check. The result for you is an optimistic CC exception which has a reference to the failing object.

    Greetings,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Thomas Kaske
    Thomas Kaske avatar
    7 posts
    Member since:
    Nov 2009

    Posted 19 Nov 2009 Link to this post

    Thank you for the reply. About point 1 i dont really understand tah with the weak reference. I already read this part:

    To achieve this, the scope maintains a dictionary of ObjectId keys and ‘weak‘ references to all objects ‘living’ in the scope. Weak reference is a reference that allows referencing objects that can be collected by the Garbage Collector. Having that in mind, when a reference to an object is followed, the object scope first checks if the dictionary contains such an ObjectID. And if it finds one, the existing weak reference is returned and nothing is fetched from the database.

    I dont really understand that. A weak refernce is a reference on an object which can be collected by the garbage collector so when the scope has just weak references alls the scope objects might get lost??
    So lets say the scope has a list of the object ids and i make a new query and the scope sees that there is a same object in the database he puts it in the scope anyways with a weak refernce?So the scope first gets the objectid from the database and then when necessary the data?
  4. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Nov 2009 Link to this post

    Hi Thomas Kaske,
    If you are still refering th objects they are not GC'ed. But if you release them we do not want to keep a reference as well and the weak references helps us to nevertheless have unique data in the scope.

    We are executing the query in a normal way. By reading the query result we decide if the object should be reused or newly created. If we reuse it we are filling only unfilled fields of the existing object. The result now contains the existing objects, maybe some more fields are loaded.

    Best wishes,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top