You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by WONDER <mm...@web.de> on 2006/04/01 19:33:14 UTC

where to put Cayenne.xml

Hello,
I use Cayenne in WebObjects 5.2.4

In Eclipse, i just add the Directery as Class Folder in the Project, and
Cayenne.xml is found.

One the Server this does not look to work.

Where should i put the xml files to be found?

Thanks.


Re: where to put Cayenne.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/1/06, WONDER <mm...@web.de> wrote:
> Adding the xml files to Class directory worked. Unfortunateley They must be
> directly in the src directery, I cant put them in thier own directery like
> "Model.Cayenne". Similer to EOF.

Actually, you can.  You just need to specify your own Configuration options:

For instance, I use a ServletContextListener that sets this up.   For
WO, you could probably call this from the Application constructor.

    public void contextInitialized(ServletContextEvent event)
    {
        DefaultConfiguration conf = new DefaultConfiguration();
        conf.addClassPath("com/xyz/cayenne/model");
        Configuration.initializeSharedConfiguration(conf);
    }

============================================================================
> 1: WO need NSArray for repetion something like customer.projects
> Solutions: use custom subclass.vm

Yep.

============================================================================
> 2: WO uses the NSMutableDictionary, and its very handy to use it as
> lookup.name, lookup.password, etc..
> Cayenne needs Map.
> Solution: Convert the lookup into Map:

Yep.

============================================================================
> 3: I had an existing Application and then decided to switch, I think you
> want to do the same.
> i.e. You have to change all xxx.saveChange() into xxx.commitChanges. No
> need. here is the solution :)

Yep.


> BTW: i still dont understand why and when should i say removeToManyTarget(
> relName, value,     FALSE     ); !!!

Generally, you wouldn't.   But the possibility is there if you need it.


============================================================================
> 4: Session has the DefaultEditingContext, I think everybody who uses WO, can
> not develop without using the defaultEditiongContext from the Session. so
> here is it for Cayenne :).

Actually,  you should return the default cayenne session data context instead:

        return ServletUtil.getSessionContext(session);

But I can't remember how accessible the HttpSession is under 5.2.

============================================================================
> Till now I am very happy using Cayenne. I think I will never go back to EOF.
> Cayenne is really good and has very great level comparing to Tapestry which
> still has not the parellel
> "WebObjects Builder" tool .  And the PlugIn Spindle still uses Tapestry 3.
> Cayenne has great GUI and its alomost even better than EOF GUI tool. For
> example Cayenne uses the last JDBC drivers. EOF still needs the old once.
>
> You will face minor problems, and as a WO developer you will learn Cayenne
> in about 2 or 3 days. depends of course on you WO experiences.
>
> HTH.
>
> Maybe Its good idea to have a WebSite on Cayenne WebSite for WO developers
> who want to switch. Should ask Andrus :)

See http://www.objectstyle.org/cayenne/userguide/misc.html

This page hasn't been ported over to the Cayenne wiki yet.   It'd be
great if you'd do so and also add in the helpful tips you provided
above!

Actually, most of it has been ported, so you'd just need to add more
to this page:

http://www.objectstyle.org/confluence/display/CAY/From+WebObject+to+Cayenne

Thanks.

Re: where to put Cayenne.xml

Posted by WONDER <mm...@web.de>.
Hi,

Adding the xml files to Class directory worked. Unfortunateley They must be
directly in the src directery, I cant put them in thier own directery like
"Model.Cayenne". Similer to EOF.


Sure, here are the points I faced and solved.
Its REALLY worth to try.


============================================================================
1: WO need NSArray for repetion something like customer.projects
Solutions: use custom subclass.vm

----------------------------------------------------------------------------
----------------------------------------

#if( ${classGen.isUsingPackage()} )
package ${classGen.packageName};
#end

#if( ${classGen.isUsingSuperPackage()} )
import
${classGen.superPackageName}.${classGen.superPrefix}${classGen.className};
#end
import org.objectstyle.cayenne.access.*;


public class ${classGen.className} extends
${classGen.superPrefix}${classGen.className}
{
    public ${classGen.className} ()
    {
        super();
    }
    public ${classGen.className}(DataContext ec) throws CustomException
    {
        ec.registerNewObject( this );
        this.setDefaultValues();
    }
    public void setDefaultValues( )
    {

    }
}
----------------------------------------------------------------------------
----------------------------------------
and custom superclass.vm




#if( ${classGen.isUsingPackage()} )
package ${classGen.packageName};

#end
#if( ${classGen.isContainingDeclaredListProperties()} )
import java.util.List;
import com.webobjects.foundation.NSArray;
#end
import de.mrer.base.CayenneCustomDataObject;
/** Class ${classGen.superPrefix}${classGen.className} was generated by
Cayenne.
  * It is probably a good idea to avoid changing this class manually,
  * since it may be overwritten next time code is regenerated.
  * If you need to make any customizations, please use subclass.
  */
public class ${classGen.superPrefix}${classGen.className} extends
$classGen.superClassName {

## Create property names
#foreach( $attr in ${classGen.Entity.DeclaredAttributes} )
#set( $classGen.Prop = $attr.Name )## let controller know about current
property
    public static final String ${classGen.propAsConstantName}_PROPERTY =
"${attr.Name}";
#end
#foreach( $rel in ${classGen.Entity.DeclaredRelationships} )
#set( $classGen.Prop = $rel.Name )## let controller know about current
property
    public static final String ${classGen.propAsConstantName}_PROPERTY =
"${rel.Name}";
#end

#if( $classGen.Entity.DbEntity )
#foreach( $idAttr in ${classGen.Entity.DbEntity.PrimaryKey} )
#set( $classGen.Prop = $idAttr.Name )## let controller know about current
property
    public static final String ${classGen.propAsConstantName}_PK_COLUMN =
"${idAttr.Name}";
#end
#end

## Create attribute set/get methods
#foreach( $attr in ${classGen.Entity.DeclaredAttributes} )
#set( $classGen.Prop = $attr.Name )## let controller know about current
property
#if ("true" != "${classGen.getEntity().isReadOnly()}")
    public void
set${classGen.cappedProp}($classGen.formatJavaType(${attr.Type})
$classGen.formatVariableName(${attr.Name}))
    {
        writeProperty("${attr.Name}",
$classGen.formatVariableName(${attr.Name}));
    }
#end
    public $classGen.formatJavaType(${attr.Type}) ${attr.Name}()
    {
        return
($classGen.formatJavaType(${attr.Type}))readProperty("${attr.Name}");
    }

    public $classGen.formatJavaType(${attr.Type})
get${classGen.cappedProp}()
    {
        return
($classGen.formatJavaType(${attr.Type}))readProperty("${attr.Name}");
    }
#end
##
## Create list add/remove/get methods
#foreach( $rel in ${classGen.Entity.DeclaredRelationships} )
#set( $classGen.Prop = $rel.Name )## let controller know about current
property
#if( $rel.ToMany )
#if ( ! $rel.ReadOnly )
    public void
addTo${classGen.cappedProp}($classGen.formatJavaType(${rel.TargetEntity.Clas
sName}) obj)
    {
        addToManyTarget("${rel.name}", obj, true);
    }
    public void
removeFrom${classGen.cappedProp}($classGen.formatJavaType(${rel.TargetEntity
.ClassName}) obj)
    {
        removeToManyTarget("${rel.name}", obj, true);
    }
#end
    public List ${rel.name}()
    {
        return (List)readProperty("${rel.name}");
    }

    public NSArray wo${classGen.cappedProp}()
    {
        List l = this.${rel.name}();
        return new NSArray( l.toArray() );
    }

    public List get${classGen.cappedProp}()
    {
        return (List)readProperty("${rel.name}");
    }
#else
#if ( !${classGen.getEntity().isReadOnly()} && !$rel.ReadOnly )
    public void
set${classGen.cappedProp}($classGen.formatJavaType(${rel.TargetEntity.ClassN
ame}) $classGen.formatVariableName(${rel.name}))
    {
        setToOneTarget("${rel.name}",
$classGen.formatVariableName(${rel.name}), true);
    }
#end

    public $classGen.formatJavaType(${rel.TargetEntity.ClassName})
${rel.name}()
    {
        return
($classGen.formatJavaType(${rel.TargetEntity.ClassName}))readProperty("${rel
.name}");
    }

    public $classGen.formatJavaType(${rel.TargetEntity.ClassName})
get${classGen.cappedProp}()
    {
        return
($classGen.formatJavaType(${rel.TargetEntity.ClassName}))readProperty("${rel
.name}");
    }
#end


#end
}

----------------------------------------------------------------------------
----------------------------------------
============================================================================
2: WO uses the NSMutableDictionary, and its very handy to use it as
lookup.name, lookup.password, etc..
Cayenne needs Map.
Solution: Convert the lookup into Map:



    private static Map convertDicToMap(NSMutableDictionary lookup)
    {
        Map<String, Object> params = new HashMap<String, Object>();
        if( lookup.count() < 1 )
        {
            return params;
        }
        NSArray keys = lookup.allKeys();

        for(int i = 0; i < keys.count(); i++)
        {
            String key = (String)keys.objectAtIndex( i );
            Object value = lookup.objectForKey( key );
            if( value instanceof String )
            {
                value = ((String)value).trim();
            }
            params.put( key, value );
        }
        return params;
    }

============================================================================
3: I had an existing Application and then decided to switch, I think you
want to do the same.
i.e. You have to change all xxx.saveChange() into xxx.commitChanges. No
need. here is the solution :)


    public BaseComponent saveChanges( ) throws CustomException
    {
        return this.commitChanges();
    }

prallel with addToManyTargets and AddToBothSides....




    public void addObjectToBothSidesOfRelationshipWithKey(DataObject value,
String relName)
    {
        super.addToManyTarget( relName, value, true);
    }

    public void removeObjectFromBothSidesOfRelationshipWithKey(DataObject
value, String relName)
    {
        super.removeToManyTarget( relName, value, true );
    }


BTW: i still dont understand why and when should i say removeToManyTarget(
relName, value,     FALSE     ); !!!
However.

============================================================================
4: Session has the DefaultEditingContext, I think everybody who uses WO, can
not develop without using the defaultEditiongContext from the Session. so
here is it for Cayenne :).

    public CayenneCustomSession(DataDomain domain)
    {
        super();

        this.defaultDataContext = domain.createDataContext();
    }


============================================================================
Till now I am very happy using Cayenne. I think I will never go back to EOF.
Cayenne is really good and has very great level comparing to Tapestry which
still has not the parellel
"WebObjects Builder" tool .  And the PlugIn Spindle still uses Tapestry 3.
Cayenne has great GUI and its alomost even better than EOF GUI tool. For
example Cayenne uses the last JDBC drivers. EOF still needs the old once.

You will face minor problems, and as a WO developer you will learn Cayenne
in about 2 or 3 days. depends of course on you WO experiences.

HTH.

Maybe Its good idea to have a WebSite on Cayenne WebSite for WO developers
who want to switch. Should ask Andrus :)

peaSakoe





----- Original Message ----- 
From: "Mike Kienenberger" <mk...@gmail.com>
To: <ca...@incubator.apache.org>
Sent: Friday, March 31, 2006 7:41 PM
Subject: Re: where to put Cayenne.xml


On 4/1/06, WONDER <mm...@web.de> wrote:
> I use Cayenne in WebObjects 5.2.4
>
> In Eclipse, i just add the Directery as Class Folder in the Project, and
Cayenne.xml is found.
> One the Server this does not look to work.
> Where should i put the xml files to be found?

What about adding the directory to your jar file's classes folder so
it remains on the classpath?   This is how I do it in both Eclipse and
out of eclipse.   Actually, I add the files to the source folder, and
they're automatically copied over into the classes folder.

Please keep us up-to-date on using Cayenne with WO5.2.4.   I have a
5.2.4 project I'd like to convert over to using Cayenne instead of EOF
myself!


Re: where to put Cayenne.xml

Posted by WONDER <mm...@web.de>.
I use now Cayenne in 2 Applications sucessfully. Its great, to keep away
from EOF.
Unfortunately you can not use Cayenne in Framework which hast its own
Cayenne.xml with application has also its own Cayenne.xml
"At least not yet. Andrus, talked about a solution coming in the next
release. He also gave me a solution, wich I didnt want to try it."
However, Its great. You will love it.

I had the following problems I had to change:
============================================================================
1. WO need NSArray or a Vector.  best solution you use your customed
subclass.vm



----------------------------------------------------------------------------
-------------------------------------------------------

----------------------------------------------------------------------------
-------------------------------------------------------
----------------------------------------------------------------------------
-------------------------------------------------------=====================
=======================================================
============================================================================
============================================================================
============================================================================
============================================================================
============================================================================



----- Original Message ----- 
From: "Mike Kienenberger" <mk...@gmail.com>
To: <ca...@incubator.apache.org>
Sent: Friday, March 31, 2006 7:41 PM
Subject: Re: where to put Cayenne.xml


On 4/1/06, WONDER <mm...@web.de> wrote:
> I use Cayenne in WebObjects 5.2.4
>
> In Eclipse, i just add the Directery as Class Folder in the Project, and
Cayenne.xml is found.
> One the Server this does not look to work.
> Where should i put the xml files to be found?

What about adding the directory to your jar file's classes folder so
it remains on the classpath?   This is how I do it in both Eclipse and
out of eclipse.   Actually, I add the files to the source folder, and
they're automatically copied over into the classes folder.

Please keep us up-to-date on using Cayenne with WO5.2.4.   I have a
5.2.4 project I'd like to convert over to using Cayenne instead of EOF
myself!


Re: where to put Cayenne.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/1/06, WONDER <mm...@web.de> wrote:
> I use Cayenne in WebObjects 5.2.4
>
> In Eclipse, i just add the Directery as Class Folder in the Project, and Cayenne.xml is found.
> One the Server this does not look to work.
> Where should i put the xml files to be found?

What about adding the directory to your jar file's classes folder so
it remains on the classpath?   This is how I do it in both Eclipse and
out of eclipse.   Actually, I add the files to the source folder, and
they're automatically copied over into the classes folder.

Please keep us up-to-date on using Cayenne with WO5.2.4.   I have a
5.2.4 project I'd like to convert over to using Cayenne instead of EOF
myself!