7 Replies Latest reply: Nov 6, 2012 2:12 AM by Nitin Khare RSS

    Creating Custom persisted properties?

    RMishra
      Hi All,
      As as read atg.adapter.gsa.GSAPropertyDescriptor class will be use to create custom persisted properties. Then what is difference b/w custom persisted property, that we creating using property-type = sub class of above class and simple property that is in any table?
      Hint: custom persisted property is declared in .xml file outside of table just like transient property.
      -RMishra
        • 1. Re: Creating Custom persisted properties?
          Nooruddin Shaik
          You cannot have any kind of persistent properties outside of <table> tag.

          Custom persistent properties are similar to regular persistent properties but lets you define your own class implementation.
          For example the data-type enum is user-defined property and it stays inside the <table> tag.
          Here is its source code:
          <ATG9dir>/DAS/src/Java/atg/adapter/gsa/EnumPropertyDescriptor

          Don't get confused becoz enum doesn't use property-type, but ATG internally manages it.

          Peace
          Shaik
          • 2. Re: Creating Custom persisted properties?
            Nitin Khare
            Hint: custom persisted property is declared in .xml file outside of table just like transient property.
            You can not have a persistent property outside <table>. If you do that your repository definition xml validation will fail during startup.
            As as read atg.adapter.gsa.GSAPropertyDescriptor class will be use to create custom persisted properties. Then what is difference b/w custom persisted property, >that we creating using property-type = sub class of above class and simple property that is in any table?
            Any regular persistent property in your repository is going to be handled through GSAPropertyDescriptor or its sub-class. In case you specify property-type as a sub-class of GSAPropertyDescriptor, then in that case some additional methods like rawToReal() and realToRaw() come into picture while calling getPropertyValue() and setPropertyValue() respectively.

            rawToReal() - converts from the database value to the property value as returned by RepositoryItem.getPropertyValue(). E.g. for a property that specifies a reference to another item, we can convert the ID stored in database of an item into the RepositoryItem itself to be returned from getPropertyValue().

            realToRaw() - converts from the value given to setPropertyValue into the value given to which will actually be stored in the database. E.g. a property that specifies a reference to another item, we can convert from the RepositoryItem object passed in () to its ID.

            The above default implementations are already provided in ATG Repository APIs and if you want to customize or change the default behavior then you can extend GSAPropertyDescriptor and define that class as property-type.

            As Shaik mentioned, one GSAPropertyDescriptor customization is already there in form of EnumPropertyDescriptor which comes into picture for "enumerated" data types. It is done by not specifying the class name in property-type but through an indirect approach where a type name for a repository property can be registered with this method:

            RepositoryPropertyDescriptor.registerPropertyDescriptorClass(String typeName, Class propertyDescriptorClass)

            Hope it helps.
            • 3. Re: Creating Custom persisted properties?
              RMishra
              Thnaks Nitin and Shaik.
              • 4. Re: Creating Custom persisted properties?
                Jitendra Vishnoi
                Hi Nitin,

                Where can we use this method

                RepositoryPropertyDescriptor.registerPropertyDescriptorClass(String typeName, Class propertyDescriptorClass)

                I am not getting which point of time. because XML is parsed when server startup.

                Thanks,
                jitendra
                • 5. Re: Creating Custom persisted properties?
                  Nitin Khare
                  Where can we use this method

                  RepositoryPropertyDescriptor.registerPropertyDescriptorClass(String typeName, Class propertyDescriptorClass)
                  You have to use it in your PropertyDescriptor implementation class within a static block. Here typeName would be same as the name of user defined property and propertyDescriptorClass will be the Class object for your PropertyDescriptor implementation class.

                  When the repository XML definition is parsed during server startup any user-defined property type declared there will also be resolved and its class will loaded. So having the registerPropertyDescriptorClass() call within the static block will cause its execution at class loading and the custom PropertyDescriptor implementation class will be registered for the user defined property.
                  • 6. Re: Creating Custom persisted properties?
                    Jitendra Vishnoi
                    Hi Nitin,

                    I tried both direct and indirect ways. But for each property when xml is parsed a new object is being created for pPropertyDescriptorClass/property-type. In my application there are about 1000 properties. I have to evaluate the property value at run time from some session objects. Is there any way I can stop ATG to create objects of pPropertyDescriptorClass/property-type and a single object could serve all request for property evaluation.
                    Appreciate all your support.

                    Thanks,
                    Jitendra
                    • 7. Re: Creating Custom persisted properties?
                      Nitin Khare
                      Hi Jitendra,

                      I guess you would be using property descriptor approach for some of the properties and not all. Ain't you? I don't think it would be the case where all the properties are getting populated from session objects through property descriptors only. If so then may be overall application design and flow needs to be looked at again. If all the values are coming from session object to repository item through property-descriptors only then what is the point of having that repository item? You could have directly used a value object kind of a thing instead of defining a repository item for that.

                      Regarding object instances, yes if you specify same property descriptor class to several properties then there will be as many instances created. I do not think there is any way available which will create single object instance to serve for several properties. Imagine a single object serving to many properties then there could be lots of state management logic also which can creep into the implementation depending on the properties and from design point of view it may not be good to have state within a property descriptor.

                      Even if you write a single class to handle multiple properties and pass attributes from the repository XML to your property descriptor implementation class so that it can know which property it is serving at any time; again there will be as many instances as many times you specify the class as the property-descriptor and your implementation would also have to incorporate if-else stuff to handle the getPropertyValue()/setPropertyValue() operations based on the attributes passed.

                      Thanks.