bpapez      2005/12/06 13:11:34 CET

  Modified files:
    core/src/java/org/jahia/services/fields ContentField.java 
    core/src/java/org/jahia/services/containers 
                                                ContentContainer.java 
                                                ContentContainerList.java 
    core/src/java/org/jahia/content JahiaObject.java 
  Log:
  add method(s) to retrieve instances from database and not from cache
  
  Revision  Changes    Path
  1.5       +45 -43    jahia/core/src/java/org/jahia/content/JahiaObject.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/content/JahiaObject.java.diff?r1=1.4&r2=1.5&f=h
  1.23      +9 -0      
jahia/core/src/java/org/jahia/services/containers/ContentContainer.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/containers/ContentContainer.java.diff?r1=1.22&r2=1.23&f=h
  1.16      +9 -0      
jahia/core/src/java/org/jahia/services/containers/ContentContainerList.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/containers/ContentContainerList.java.diff?r1=1.15&r2=1.16&f=h
  1.41      +9 -0      
jahia/core/src/java/org/jahia/services/fields/ContentField.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/fields/ContentField.java.diff?r1=1.40&r2=1.41&f=h
  
  
  
  Index: ContentField.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/fields/ContentField.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- ContentField.java 17 Nov 2005 13:42:05 -0000      1.40
  +++ ContentField.java 6 Dec 2005 12:11:33 -0000       1.41
  @@ -124,6 +124,15 @@
           }
           return null;
       }
  +    
  +    public static ContentObject getChildInstance (String IDInType, boolean 
forceLoadFromDB) {
  +        try {
  +            return getField (Integer.parseInt (IDInType), forceLoadFromDB);
  +        } catch (JahiaException je) {
  +            logger.debug ("Error retrieving field instance for id : " + 
IDInType, je);
  +        }
  +        return null;
  +    }    
   
       public int getAclID () {
           return aclID;
  
  
  
  Index: ContentContainer.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/containers/ContentContainer.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ContentContainer.java     9 Nov 2005 11:02:42 -0000       1.22
  +++ ContentContainer.java     6 Dec 2005 12:11:34 -0000       1.23
  @@ -135,6 +135,15 @@
           return null;
       }
   
  +    public static ContentObject getChildInstance (String IDInType, boolean 
forceLoadFromDB) {
  +        try {
  +            return getContainer (Integer.parseInt (IDInType), 
forceLoadFromDB);
  +        } catch (JahiaException je) {
  +            logger.debug ("Error retrieving container instance for id : " + 
IDInType, je);
  +        }
  +        return null;
  +    }    
  +    
       public ContentContainer (int ID, int jahiaID, int pageID, int ctnDefID, 
int listID,
                                   int aclID, List activeAndStagedEntryStates) {
           super (new ContentContainerKey (ID));
  
  
  
  Index: ContentContainerList.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/containers/ContentContainerList.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ContentContainerList.java 9 Nov 2005 11:02:42 -0000       1.15
  +++ ContentContainerList.java 6 Dec 2005 12:11:34 -0000       1.16
  @@ -77,6 +77,15 @@
           return null;
       }
   
  +    public static ContentObject getChildInstance (String IDInType, boolean 
forceLoadFromDB) {
  +        try {
  +            return getContainerList (Integer.parseInt (IDInType));
  +        } catch (JahiaException je) {
  +            logger.debug ("Error retrieving container list instance for id : 
" + IDInType, je);
  +        }
  +        return null;
  +    }    
  +    
       public ContentContainerList (int ID, int parentContainerID, int pageID, 
int ctnDefID,
                                       int aclID, List activeAndStagedEntries) {
           super (new ContentContainerListKey (ID));
  
  
  
  Index: JahiaObject.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/content/JahiaObject.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JahiaObject.java  5 Jul 2005 15:45:57 -0000       1.4
  +++ JahiaObject.java  6 Dec 2005 12:11:34 -0000       1.5
  @@ -85,47 +85,7 @@
        */
       public static JahiaObject getInstance (ObjectKey objectKey)
           throws ClassNotFoundException {
  -        JahiaObject resultObject = null;
  -        String type = objectKey.getType();
  -        String idStr = objectKey.getIDInType();
  -        if (!keyTypeClassNames.containsKey(type)) {
  -            throw new ClassNotFoundException("No class defined for type [" +
  -                                             type + "]");
  -        }
  -        try {
  -            Class childClass = Class.forName( (String) keyTypeClassNames.
  -                                             get(type));
  -            Class[] childClassParameters = new Class[1];
  -            childClassParameters[0] = String.class;
  -            java.lang.reflect.Method childClassMethod = childClass.
  -                getMethod("getChildInstance", childClassParameters);
  -            Object[] args = new Object[1];
  -            args[0] = idStr;
  -            resultObject = (JahiaObject) childClassMethod.invoke(null, args);
  -        } catch (ClassNotFoundException cnfe) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, cnfe);
  -        } catch (NoSuchMethodException nsme) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, nsme);
  -        } catch (SecurityException se) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, se);
  -        } catch (IllegalAccessException iae) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, iae);
  -        } catch (IllegalArgumentException iae2) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, iae2);
  -        } catch (InvocationTargetException ite) {
  -            logger.error("Error while creating instance of object " +
  -                         objectKey, ite);
  -            logger.error(
  -                "Error while creating instance of object " + objectKey +
  -                ", target exception="
  -                , ite.getTargetException());
  -        }
  -        return resultObject;
  +        return (JahiaObject)getInstanceAsObject(objectKey, false);
       }
   
       /**
  @@ -134,6 +94,24 @@
        *
        * @param objectKey an ObjectKey instance for the object we want to 
retrieve
        * an instance of.
  +     * @param forceLoadFromDB true, if object should not be returned from 
cache 
  +     * @returns a JahiaObject sub class instance that corresponds to the 
given
  +     * object key.
  +     *
  +     * @throws ClassNotFoundException if no class could be found for the type
  +     * passed in the object key
  +     */
  +    public static JahiaObject getInstance (ObjectKey objectKey, boolean 
forceLoadFromDB)
  +        throws ClassNotFoundException {
  +        return (JahiaObject)getInstanceAsObject(objectKey, forceLoadFromDB);
  +    }    
  +
  +    /**
  +     * Instance generator. Build an instance of the appropriate
  +     * class corresponding to the ObjectKey passed described.
  +     *
  +     * @param objectKey an ObjectKey instance for the object we want to 
retrieve
  +     * an instance of.
        * @returns a JahiaObject sub class instance that corresponds to the 
given
        * object key.
        *
  @@ -142,6 +120,24 @@
        */
       public static Object getInstanceAsObject (ObjectKey objectKey)
           throws ClassNotFoundException {
  +        return getInstanceAsObject(objectKey, false);
  +    }
  +    
  +    /**
  +     * Instance generator. Build an instance of the appropriate
  +     * class corresponding to the ObjectKey passed described.
  +     *
  +     * @param objectKey an ObjectKey instance for the object we want to 
retrieve
  +     * an instance of.
  +     * @param forceLoadFromDB true, if object should not be returned from 
cache      
  +     * @returns a JahiaObject sub class instance that corresponds to the 
given
  +     * object key.
  +     *
  +     * @throws ClassNotFoundException if no class could be found for the type
  +     * passed in the object key
  +     */
  +    public static Object getInstanceAsObject (ObjectKey objectKey, boolean 
forceLoadFromDB)
  +        throws ClassNotFoundException {
           Object resultObject = null;
           String type = objectKey.getType();
           String idStr = objectKey.getIDInType();
  @@ -152,12 +148,18 @@
           try {
               Class childClass = Class.forName( (String) keyTypeClassNames.
                                                get(type));
  -            Class[] childClassParameters = new Class[1];
  +            Class[] childClassParameters = new Class[forceLoadFromDB ? 2 : 
1];
               childClassParameters[0] = String.class;
  +            if (forceLoadFromDB){
  +                childClassParameters[1] = boolean.class;                
  +            }
               java.lang.reflect.Method childClassMethod = childClass.
                   getMethod("getChildInstance", childClassParameters);
  -            Object[] args = new Object[1];
  +            Object[] args = new Object[forceLoadFromDB ? 2 : 1];
               args[0] = idStr;
  +            if (forceLoadFromDB){
  +                args[1] = Boolean.valueOf(forceLoadFromDB);                
  +            }
               resultObject = childClassMethod.invoke(null, args);
           } catch (ClassNotFoundException cnfe) {
               logger.error("Error while creating instance of object " +
  

Reply via email to