Sorting Question

View: New views
6 Messages — Rating Filter:   Alert me  

Sorting Question

by Michael A. Rose :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm a long time neo user, working on a rather large project using neo. I just ran into a problem with sorting...

Consider the following:

            FetchSpecification fspec = new FetchSpecification();
            fspec.Qualifier = Qualifier.Format(@"TheTitle like 'A%'");
            fspec.Spans = new string[]{ "Publisher" };
            fspec.AddSortOrdering("Publisher.Name", SortDirection.Ascending);
            TitleList mytitles = new TitleFactory(context).Find(fspec);
            Assert.IsTrue(mytitles.Count > 0, "Bad monkey.");


fails with the following error:

Neo.Tests.Fixtures.FindTestsWithStore.FindTests.JoinedObjectSort : System.ArgumentException : Attribute Publisher.Name not found in
class Pubs4.Model.Title (Maybe you are looking for a Relation?)

How would I accomplish this?

Thanks in advance,

PCBender

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Entity locking on concurrent access

by Arif Budimartoyo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I want to implement Entity object locking to avoid concurrent user
problem while maintain a record in multiuser and distributed env.

-Adding field IsLocked (BIT), LockedBy (VARCHAR), LockedSince (DATE) on
each entity. These fields become properties on entity base object.
-Adding .UnLock() and .Lock(string UserID) on entity object.

Are there any other better and simpler solutions rather than mine
above..

Thanks in advance




---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


RE: Entity locking on concurrent access

by Pieter Jansen van Vuuren :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How are you going to handle cases where a record is locked and an error
accurs and the row is not unlocked?

Did you know that NEO will throw an exception (can't remember which one)
if data has been changed when you try and save changes on a row that has
been updated since NEO retrieved the data?  Which covers concurrency in
most cases.  You just need to handle the exception correctly.

-----Original Message-----
From: Arif Budimartoyo [mailto:Arif.Budimartoyo@...]
Sent: Thursday, 31 August 2006 3:51 p.m.
To: user@...
Subject: [neo-user] Entity locking on concurrent access

Hi,

I want to implement Entity object locking to avoid concurrent user
problem while maintain a record in multiuser and distributed env.

-Adding field IsLocked (BIT), LockedBy (VARCHAR), LockedSince (DATE) on
each entity. These fields become properties on entity base object.
-Adding .UnLock() and .Lock(string UserID) on entity object.

Are there any other better and simpler solutions rather than mine
above..

Thanks in advance




---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


RE: Entity locking on concurrent access

by Arif Budimartoyo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I just want to know (and disable the all input controls), on who has
been locking the record and display it on the screen, also since when it
has been being locked.
Unlocking mechanism might be performed by AutoUnlock-worker which will
work in the background, checking the locked record reach the lock expiry
time limit.  Is that makes sense?
I just don't want to get the message "It's have been locked by some one.
You can try it next time." only.



-----Original Message-----
From: Pieter Jansen van Vuuren [mailto:PieterJ@...]
Sent: Thursday, August 31, 2006 1:22 PM
To: user@...
Subject: RE: [neo-user] Entity locking on concurrent access

How are you going to handle cases where a record is locked and an error
accurs and the row is not unlocked?

Did you know that NEO will throw an exception (can't remember which one)
if data has been changed when you try and save changes on a row that has
been updated since NEO retrieved the data?  Which covers concurrency in
most cases.  You just need to handle the exception correctly.

-----Original Message-----
From: Arif Budimartoyo [mailto:Arif.Budimartoyo@...]
Sent: Thursday, 31 August 2006 3:51 p.m.
To: user@...
Subject: [neo-user] Entity locking on concurrent access

Hi,

I want to implement Entity object locking to avoid concurrent user
problem while maintain a record in multiuser and distributed env.

-Adding field IsLocked (BIT), LockedBy (VARCHAR), LockedSince (DATE) on
each entity. These fields become properties on entity base object.
-Adding .UnLock() and .Lock(string UserID) on entity object.

Are there any other better and simpler solutions rather than mine
above..

Thanks in advance




---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: Sorting Question

by Jay Herrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello PCBender,

We ran into the same problem.  The following patch updates the
GetProperty method used by the sorting algorithm to handle a "dotted"
property path by recursively grabbing the left most object and
shortening the property string.  If you use this patch make sure you
span all the properties you will hit in your sort or it might run a
little slow.

Good luck,

-Jay

mrose@... wrote:

> I'm a long time neo user, working on a rather large project using neo. I just ran into a problem with sorting...
>
> Consider the following:
>
>             FetchSpecification fspec = new FetchSpecification();
>             fspec.Qualifier = Qualifier.Format(@"TheTitle like 'A%'");
>             fspec.Spans = new string[]{ "Publisher" };
>             fspec.AddSortOrdering("Publisher.Name", SortDirection.Ascending);
>             TitleList mytitles = new TitleFactory(context).Find(fspec);
>             Assert.IsTrue(mytitles.Count > 0, "Bad monkey.");
>
>
> fails with the following error:
>
> Neo.Tests.Fixtures.FindTestsWithStore.FindTests.JoinedObjectSort : System.ArgumentException : Attribute Publisher.Name not found in
> class Pubs4.Model.Title (Maybe you are looking for a Relation?)
>
> How would I accomplish this?
>
> Thanks in advance,
>
> PCBender
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>  

Index: C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs
===================================================================
--- C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs (revision 588)
+++ C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs (working copy)
@@ -101,26 +101,52 @@
 
  public static object GetProperty(object anObject, string prop, ref Type lastType, ref PropertyInfo propInfo)
  {
- Type objType = anObject.GetType();
- if(objType != lastType)
- {
- if((propInfo = objType.GetProperty(prop)) == null)
- throw new InvalidPropertyException(String.Format("{0} is not a valid property for class {1}", prop, objType), null);
- lastType = objType;
+ string[] parts = prop.Split('.');
+
+ //To subdivide or not to subdivide
+ if (parts.Length > 1)
+ {
+ //Get the reference to the object
+ object left = GetProperty(anObject, parts[0]);
+
+ //the remaining property path
+ string newprop = "";
+
+ for(int x = 1; x < parts.Length; x++)
+ {
+ newprop += parts[x];
+ if (x != parts.Length - 1)
+ {
+ newprop += ".";
+ }
+ }
+
+ //resurse
+ return GetProperty(left, newprop, ref lastType, ref propInfo);
  }
- try
+ else
  {
- return propInfo.GetValue(anObject, null);
- }
- catch(TargetInvocationException e)
- {
- if(e.InnerException == null)
- throw e;
+ Type objType = anObject.GetType();
+ if(objType != lastType)
+ {
+ if((propInfo = objType.GetProperty(prop)) == null)
+ throw new InvalidPropertyException(String.Format("{0} is not a valid property for class {1}", prop, objType), null);
+ lastType = objType;
+ }
+ try
+ {
+ return propInfo.GetValue(anObject, null);
+ }
+ catch(TargetInvocationException e)
+ {
+ if(e.InnerException == null)
+ throw e;
 
- if(e.InnerException is InvalidDbNullException)
- return null;
- else
- throw e.InnerException;
+ if(e.InnerException is InvalidDbNullException)
+ return null;
+ else
+ throw e.InnerException;
+ }
  }
  }
 



---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Re: Sorting Question

by PC :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks. I went down a similar path...

In PropertyComparer:

        public virtual int Compare(object x, object y)
        {
            object xval;
            object yval;
            if (propName.Contains ("."))
            {
                string[] propArray = propName.Split('.');
                Queue<string> propQueueX = new Queue<string>(propArray);
                Queue<string> propQueueY = new Queue<string>(propArray);
                xval = ObjectHelper.GetProperty(x, propQueueX);
                yval = ObjectHelper.GetProperty(y, propQueueY);
            }
            else
            {
                xval = ObjectHelper.GetProperty (x, propName, ref lastType, ref propInfo);
                yval = ObjectHelper.GetProperty(y, propName, ref lastType, ref propInfo);
            }

            if((direction & InvertDirection) == 0)
                return comparer.Compare(xval, yval);
            else
                return comparer.Compare(yval, xval);
        }

And in ObjectHelper added:

        public static object GetProperty(object anObject, Queue<string> propQueue)
        {
            PropertyInfo propInfo;
           
            Type objType = anObject.GetType();
            string prop = propQueue.Dequeue();

            if ((propInfo = objType.GetProperty (prop)) == null)
            {
                throw new InvalidPropertyException(String.Format("{0} is not a valid property for class {1}", prop, objType), null);
            }
           
            try
            {
                Object obj = propInfo.GetValue(anObject, null);
                if((propQueue.Count > 0) && (obj != null))
                {
                    return GetProperty(obj, propQueue);
                }
                else
                {
                    return obj;
                }
            }
            catch (TargetInvocationException e)
            {
                if ( e.InnerException == null)
                    throw e;

                if (e.InnerException is InvalidDbNullException)
                    return null;
                else
                    throw e.InnerException ;
            }
        }

Of course, this is a 2.0 framework patch.

Thanks again,

PC


On 9/5/06, Jay Herrick <jherrick@...> wrote:
Hello PCBender,

We ran into the same problem.  The following patch updates the
GetProperty method used by the sorting algorithm to handle a "dotted"
property path by recursively grabbing the left most object and
shortening the property string.  If you use this patch make sure you
span all the properties you will hit in your sort or it might run a
little slow.

Good luck,

-Jay

mrose@... wrote:

> I'm a long time neo user, working on a rather large project using neo. I just ran into a problem with sorting...
>
> Consider the following:
>
>             FetchSpecification fspec = new FetchSpecification();
>             fspec.Qualifier = Qualifier.Format(@"TheTitle like 'A%'");
>             fspec.Spans = new string[]{ "Publisher" };
>             fspec.AddSortOrdering("Publisher.Name", SortDirection.Ascending);
>             TitleList mytitles = new TitleFactory(context).Find(fspec);
>             Assert.IsTrue(mytitles.Count > 0, "Bad monkey.");
>
>
> fails with the following error:
>
> Neo.Tests.Fixtures.FindTestsWithStore.FindTests.JoinedObjectSort : System.ArgumentException : Attribute Publisher.Name not found in
> class Pubs4.Model.Title (Maybe you are looking for a Relation?)
>
> How would I accomplish this?
>
> Thanks in advance,
>
> PCBender
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>


Index: C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs
===================================================================
--- C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs     (revision 588)
+++ C:/Source/neo/src/Neo/Core.Util/ObjectHelper.cs     (working copy)
@@ -101,26 +101,52 @@

                public static object GetProperty(object anObject, string prop, ref Type lastType, ref PropertyInfo propInfo)
                {
-                       Type objType = anObject.GetType();
-                       if(objType != lastType)
-                       {
-                               if((propInfo = objType.GetProperty (prop)) == null)
-                                       throw new InvalidPropertyException(String.Format("{0} is not a valid property for class {1}", prop, objType), null);
-                               lastType = objType;
+                       string[] parts = prop.Split('.');
+
+                       //To subdivide or not to subdivide
+                       if (parts.Length > 1)
+                       {
+                               //Get the reference to the object
+                               object left = GetProperty(anObject, parts[0]);
+
+                               //the remaining property path
+                               string newprop = "";
+
+                               for(int x = 1; x < parts.Length; x++)
+                               {
+                                       newprop += parts[x];
+                                       if (x != parts.Length - 1)
+                                       {
+                                               newprop += ".";
+                                       }
+                               }
+
+                               //resurse
+                               return GetProperty(left, newprop, ref lastType, ref propInfo);
                        }
-                       try
+                       else
                        {
-                               return propInfo.GetValue(anObject, null);
-                       }
-                       catch(TargetInvocationException e)
-                       {
-                               if(e.InnerException == null)
-                                       throw e;
+                               Type objType = anObject.GetType();
+                               if(objType != lastType)
+                               {
+                                       if((propInfo = objType.GetProperty(prop)) == null)
+                                               throw new InvalidPropertyException(String.Format ("{0} is not a valid property for class {1}", prop, objType), null);
+                                       lastType = objType;
+                               }
+                               try
+                               {
+                                       return propInfo.GetValue(anObject, null);
+                               }
+                               catch(TargetInvocationException e)
+                               {
+                                       if(e.InnerException == null)
+                                               throw e;

-                               if(e.InnerException is InvalidDbNullException)
-                                       return null;
-                               else
-                                       throw e.InnerException;
+                                       if( e.InnerException is InvalidDbNullException)
+                                               return null;
+                                       else
+                                               throw e.InnerException ;
+                               }
                        }
                }





---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email