incubator-graffito-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christophe Lombart" <christophe.lomb...@gmail.com>
Subject Re: jcr-mapping contribution
Date Thu, 10 Aug 2006 07:45:09 GMT
Aterm,

Thank you very much for your contribution. I'm on vacation until
September. I will review your patch and suggestions ASAP (probably the
first week of september).

If you know someone interested to integrated xwiki with the complete
Graffito stack, I will be very happy to discuss on that Topic. A
couple of month ago I reviewed Xwiki and I think it should be possible
to make a " Xwiki Graffito application".

Kind regards,
Christophe

On 8/9/06, Artem Melentyev <amelentev@gmail.com> wrote:
> Hello.
>
> I'm Google Summer of Code student ( http://code.google.com/soc ) in
> XWiki organization ( http://xwiki.org/ .com )
> I am writing JCR Store backend for XWiki. (XWiki works only on Hibernate
> for now)
>
> I'm using ObjectConverter directly without PersistenceManager (it is too
> high-level, and I don't want to add jcrpath field to beens).
>
> I would like to contribute my small changes. patch relatively svn trunk
> is attached.
>
>  Interface problems if same name siblings used (1,2):
>   1) ObjectConverter.insert method don't returns created Node and
> impossible find it, if where are many nodes with same name.
> I offer:
> public Node insert(Session session, Node parentNode, String nodeName,
> Object object);
>
>   2) ObjectConverter.update method uses "parentNode.getNode(nodeName)",
> but if there are many nodes with same name?
> I added following method:
> public void update(Session session, Node objectNode, Object object)
>
>
>  3) I want to store descendants of some class A, the same as A, without
> putting descendants classes in mappings. How to make it?
> I write in ObjectConverterImpl additional methods insert and update with
> additional parameter Class objclass. Maybe there is a way better?
>
>   Bugs:
>  4) ObjectConverter.retrieveSimpleFields method:
> in if (classDescriptor.usesNodeTypePerHierarchyStrategy() &&
> classDescriptor.hasDiscriminator())
> writed:
>   String value = node.getProperty(propertyName).getValue().getString();
>
> Why only String? I have a exceptions because it. I think should be:
>
>   Value propValue = node.getProperty(propertyName).getValue();
>   AtomicTypeConverter converter =
> getAtomicTypeConverter(fieldDescriptor, initializedBean, fieldName);
>   Object fieldValue = converter.getObject(propValue);
>   ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
>
>
>  5) ManageableCollectionUtil.getManageableCollection:
> Why I can't store non standard, but Collection or Set compatible
> classes? (ex: from org.apache.commons.collections)
> i write following. It works fine for me:
> ...
> if (object instanceof Vector) {
>   ManageableVector manageableVector = new ManageableVector();
>   manageableVector.addAll((Collection) object);
>   return manageableVector;
> }
> if (object instanceof Set) {
>   return new ManageableSet((Set) object);
> }
> if (object instanceof Collection) {
>   ManageableArrayList manageableArrayList = new ManageableArrayList();
>   manageableArrayList.addAll((Collection) object);
>   return manageableArrayList;
> }
> ...
>
>
> --
>   Artem Melentyev. UralSU, CS401.
>
>
>
> Index: src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
     (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
     (working copy)
> @@ -113,39 +113,22 @@
>              if (object == null) {
>                  return null;
>              }
> -
>              if (object instanceof ManageableCollection) {
>                  return (ManageableCollection) object;
> -
>              }
> -            if (object.getClass().equals(ArrayList.class)) {
> -                ManageableArrayList manageableArrayList = new ManageableArrayList();
> -                manageableArrayList.addAll((Collection) object);
> -
> -                return manageableArrayList;
> -            }
> -
> -            if (object.getClass().equals(Vector.class)) {
> -                ManageableVector manageableVector = new ManageableVector();
> -                manageableVector.addAll((Collection) object);
> -
> -                return manageableVector;
> -            }
> -
> -            if (object.getClass().equals(HashSet.class)) {
> +            if (object instanceof Vector) {
> +               ManageableVector manageableVector = new ManageableVector();
> +               manageableVector.addAll((Collection) object);
> +               return manageableVector;
> +            }
> +            if (object instanceof Set) {
>                  return new ManageableSet((Set) object);
>              }
> -
> -            if (object.getClass().equals(Collection.class)
> -                || object.getClass().equals(List.class)) {
> -                ManageableArrayList manageableArrayList = new ManageableArrayList();
> -                manageableArrayList.addAll((Collection) object);
> -
> -                return manageableArrayList;
> +            if (object instanceof Collection) {
> +               ManageableArrayList manageableArrayList = new ManageableArrayList();
> +               manageableArrayList.addAll((Collection) object);
> +               return manageableArrayList;
>              }
> -            if (object.getClass().equals(Set.class)) {
> -                return new ManageableSet((Set) object);
> -            }
>          }
>          catch (Exception e) {
>              throw new JcrMappingException("Impossible to create the manageable collection",
e);
> Index: src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
 (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
 (working copy)
> @@ -139,9 +139,10 @@
>          * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session,
>          *      javax.jcr.Node, java.lang.String, java.lang.Object)
>          */
> -       public void insert(Session session, Node parentNode, String nodeName, Object
object) {
> -               ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(object.getClass());
> -
> +
> +       public Node insert(Session session, Node parentNode, String nodeName, Object
object, Class objclass) {
> +               ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(objclass);
> +
>                 String jcrNodeType = classDescriptor.getJcrNodeType();
>                 if ((jcrNodeType == null) || jcrNodeType.equals("")) {
>                         jcrNodeType = PersistenceConstant.NT_UNSTRUCTURED;
> @@ -198,7 +199,12 @@
>                 storeSimpleFields(session, object, classDescriptor, objectNode);
>                 insertBeanFields(session, object, classDescriptor, objectNode);
>                 insertCollectionFields(session, object, classDescriptor, objectNode);
> +               return objectNode;
>         }
> +
> +       public Node insert(Session session, Node parentNode, String nodeName, Object
object) {
> +               return insert(session, parentNode, nodeName, object, ReflectionUtils.getBeanClass(object));
> +       }
>
>         /**
>          * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session,
> @@ -226,22 +232,28 @@
>          */
>         public void update(Session session, Node parentNode, String nodeName, Object
object) {
>                 try {
> -                       ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
>                         Node objectNode = parentNode.getNode(nodeName);
> +                       update(session, objectNode, object, ReflectionUtils.getBeanClass(object));
> +               } catch (PathNotFoundException e) {
> +                       throw new PersistenceException("Impossible to update the object:
" + nodeName + " at node : " + parentNode, e);
> +               } catch (RepositoryException e) {
> +                       throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible
to update the object: "
> +                                       + nodeName + " at node : " + parentNode, e);
> +               }
> +       }
> +       public void update(Session session, Node node, Object object) {
> +               update(session, node, object, ReflectionUtils.getBeanClass(object));
> +       }
> +       public void update(Session session, Node objectNode, Object object, Class objclass)
{
> +               ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(objclass);
>
> -                       checkNodeType(session, classDescriptor);
> +               checkNodeType(session, classDescriptor);
>
> -                       checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor,
false);
> +               checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor,
false);
>
> -                       storeSimpleFields(session, object, classDescriptor, objectNode);
> -                       updateBeanFields(session, object, classDescriptor, objectNode);
> -                       updateCollectionFields(session, object, classDescriptor, objectNode);
> -               } catch (PathNotFoundException pnfe) {
> -                       throw new PersistenceException("Impossible to update the object:
" + nodeName + " at node : " + parentNode, pnfe);
> -               } catch (RepositoryException re) {
> -                       throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible
to update the object: "
> -                                       + nodeName + " at node : " + parentNode, re);
> -               }
> +               storeSimpleFields(session, object, classDescriptor, objectNode);
> +               updateBeanFields(session, object, classDescriptor, objectNode);
> +               updateCollectionFields(session, object, classDescriptor, objectNode);
>         }
>
>         /**
> @@ -562,8 +574,12 @@
>                                                 if (null == initializedBean) {
>                                                         initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
>                                                 }
> -                                               String value = node.getProperty(propertyName).getValue().getString();
> -                                               ReflectionUtils.setNestedProperty(initializedBean,
fieldName, value);
> +                                               // Why only string?: String value = node.getProperty(propertyName).getValue().getString();
> +                                               Value propValue = node.getProperty(propertyName).getValue();
> +                                               AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor,
initializedBean, fieldName);
> +                                               Object fieldValue = converter.getObject(propValue);
> +
> +                                               ReflectionUtils.setNestedProperty(initializedBean,
fieldName, fieldValue);
>                                         } else {
>                                                 throw new PersistenceException("Class
'" + classDescriptor.getClassName()
>                                                                 + "' have not a discriminator
property.");
> Index: src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
> ===================================================================
> --- src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
  (revision 429285)
> +++ src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
  (working copy)
> @@ -101,7 +101,7 @@
>          * @param object the object to insert
>          * @throws PersistenceException when it is not possible to insert the object
>          */
> -    public void insert(Session session, Node parentNode, String nodeName, Object object)
throws PersistenceException;
> +    public Node insert(Session session, Node parentNode, String nodeName, Object object)
throws PersistenceException;
>
>         /**
>          * Update the object
>
>
>
>


-- 
Best regards,

Christophe

Mime
View raw message