Skip to Content.
Sympa Menu

grouper-dev - RE: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction

Subject: Grouper Developers Forum

List archive

RE: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction


Chronological Thread 
  • From: Chris Hyzer <>
  • To: "" <>
  • Cc: Grouper Dev <>
  • Subject: RE: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction
  • Date: Sat, 14 Feb 2009 12:24:52 -0500
  • Accept-language: en-US
  • Acceptlanguage: en-US

Btw, two more things:

 

1.       You can just call group.getExtension() to get an extension… that will be the 1.5 way when they aren’t attributes anymore

2.       If you don’t want to upgrade, or if you just feel like it, you can always get from DB yourself in a new transaction (the point of the builtin is it doesn’t have as many queries… as long as things work J ).   Heres an example of going to the DB yourself in a different transaction

 

  public void groupPostUpdate(final HooksContext hooksContext,

      final HooksGroupBean postUpdateBean) {

 

    final Group group = postUpdateBean.getGroup();

    LOGGER.debug("Current extension: " + group.getAttributeOrNull(EXTENSION));

    LOGGER.debug("Previous extension: "

        + group.dbVersion().getAttributeOrNull(EXTENSION));

   

    Group dbGroup = (Group)GrouperTransaction.callbackGrouperTransaction(GrouperTransactionType.READONLY_NEW,

        new GrouperTransactionHandler() {

 

      public Object callback(GrouperTransaction grouperTransaction)

          throws GrouperDAOException {

       

        GrouperSession grouperSession = null;

        try {

          grouperSession = GrouperSession.startRootSession(false);

          Group dbGroup = GroupFinder.findByUuid(grouperSession, group.getUuid());

          //load from db

          dbGroup.getExtension();

          return dbGroup;

        } catch (GroupNotFoundException gnfe) {

          return null;

        } catch (Exception e) {

          throw new RuntimeException(e);

        } finally {

          GrouperSession.stopQuietly(grouperSession);

        }

      }

   

    });

    if (dbGroup != null) {

      LOGGER.debug("From db group extension: " + dbGroup.getExtension());

    }

  }

 

 

From: Chris Hyzer
Sent: Friday, February 13, 2009 4:09 PM
To: ''
Cc: Grouper Dev
Subject: RE: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction

 

Arnaud, thanks for the detailed test case.  Sorry, this is a bug.

 

https://bugs.internet2.edu/jira/browse/GRP-225

 

I fixed this in grouper 1.4 branch, can you get the latest from CVS?

 

cvs -d:pserver::/home/cvs/i2mi login

 

cvs -d:pserver::/home/cvs/i2mi export -r GROUPER_1_4_BRANCH grouper

 

 

There is a test case in grouper and the issue is fixed, now it works.

 

It is a little complex.

 

1. The dbVersion (clone of data) is snapshotted when an object is retrieved from the DB

2. The group attributes (including extension) are not part of the group object, they are a one to many.  Note that in grouper 1.5 the extension is moving to not be an attribute, and is part of the group object.

3. The group attributes are lazy loaded.  So what was occurring was the group was retrieved with null attributes initially, that was copied to the dbVersion, then later on the attributes were lazy loaded from the DB, but the dbVersion of the attributes were never updated (still null).  This is why reading an attribute changed the state of things

4. I changed it so that when the attributes are lazy loaded, if the dbVersion has a null attribute map, it will get updated to whatever was retrieved from the DB.  The test case now works.

 

I believe there is still an issue though, if you read the attributes of the dbVersion and never read the attributes of the real object (not sure why you would do that), I think things would still be out of sync.  I documented that in the Group dbVersion javadoc.  I believe we could figure out a way to link the dbVersion and real object further to fix this issue, but I think the complexity involved to do that for the payoff is not worth it.

 

I will say that the attribute hook would be less complex, so it might be better to use... but not in this case for extension since in 1.5 you will have to move it back to group hook anyway :)

 

Let me know if this works for you.

 

Regards,

Chris

 

From: Arnaud Deman [mailto:]
Sent: Friday, February 13, 2009 9:36 AM
To: Chris Hyzer
Cc: Grouper Dev
Subject: Re: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction

 

The hooks is attached. And this is the output when both groupPreUpdate and groupPostUpdate are active and when I change the group extension:


Creation of an hooks of class: ESCOGroupHooks.
groupPreUpdate call isExtensionUpdate
isExtensionUpdate (1) => [attribute__Définition, modifyTime, name, displayName, extension, displayExtension, description]
isExtensionUpdate (2) => [modifyTime, name, extension]
isExtensionUpdate

Creation of an hooks of class: ESCOGroupHooks.
Current extension: Dyn_Eleve_MODIFIED
Previous extension: Dyn_Eleve


And this is the output I obtain when the method groupPreUpdate is commented:

Creation of an hooks of class: ESCOGroupHooks.
Current extension: Dyn_Eleve_MODIFIED
Previous extension: Dyn_Eleve_MODIFIED

Thanks,
Arnaud.

Chris Hyzer a écrit :

Can you send me the hooks you are trying to use, and show me which line does not do the expected behavior?

 

Thanks,

Chris

 

From: Arnaud Deman []
Sent: Friday, February 13, 2009 8:35 AM
Cc: Grouper Dev
Subject: Re: [grouper-dev] dbVersionDifferentFields and getAttributeOrNull interraction

 

Hi,

I still have the same kind of problem, even with the transactional support activated.


For instance, in the groupPreUpdate method and it looks like if the set returned by dbVersionDifferentFields was correct only after the first call of getAttributeOrNull.

The second point is that it changes the behaviour of the groupPostUpdate method. If there is a call of getAttributeOrNull in groupPreUpdate method, I can retrieve the previous values of the group in groupPostUpdate via dbVersion. If the method is commented I cannot: there is no difference between the previous and the current values of the group.

I don't know if another configuration error could be the cause of this behaviour...

Regards,
Arnaud.

Chris Hyzer a écrit :

I answer to myself,
 
I have made a mistake with the mysql db (MyISAM instead of InnoDB) :-[
.
I think this could explain my problems !
    
 
That is weird... and I am very glad you figured it out!  :)
 
Chris
 
 
  
Thanks,
Arnaud.
 
 
Arnaud Deman a écrit :
    
Hi everyone,
 
Is it normal that call of the method dbVersion change the result of
the method dbVersionDifferentFields ?
 
For instance the code :
 
       final String currentExtension =
group.getAttributeOrNull(EXTENSION);
       LOGGER.debug(" (1) ==> " + group.dbVersionDifferentFields());
 
       final Group previousValues = group.dbVersion();
       LOGGER.debug(" (2) ==> " + group.dbVersionDifferentFields());
 
       final String previousExtension =
previousValues.getAttributeOrNull(EXTENSION);
       LOGGER.debug(" (3) ==> " + group.dbVersionDifferentFields());
 
Produces the output:
 
    (1) ==> [attribute__Définition, modifyTime, name, displayName,
extension, displayExtension, description]
    (2) ==> [attribute__Définition, modifyTime, name, displayName,
extension, displayExtension, description]
    (3) ==> [modifyTime]
 
I am trying to use the dbVersionDifferentField to determine when my
hooks should be executed and I have several tests but the first one
changes the results of the other tests. I think I could work with a
clone of the set returned by dbVersionDifferentFields but I would
      
like
    
to understand.
 
I have also noticed that a single change in a group (via the
grouper-UI) can trigger several time the same method in a GroupHooks
class. One time with the attributes and one time with only the
modifyTime attribute.
 
 
Thanks,
Arnaud.
      



-- 
 
Arnaud Deman
GIP RECIA
Parc d'activités les Aulnaies
151 rue de la Juine - 45160 OLIVET
Tel : 02 38 42 14 63 



-- 
 
Arnaud Deman
GIP RECIA
Parc d'activités les Aulnaies
151 rue de la Juine - 45160 OLIVET
Tel : 02 38 42 14 63 



Archive powered by MHonArc 2.6.16.

Top of Page