You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by de...@gmx.de on 2012/11/01 11:06:33 UTC

Re: use symbol value in POJO

> PS. Which version of Cayenne are you using?

Cayenne 3.1B1, Tapestry 5.3.6 and tapestry5-cayenne-server 0.5-SNAPSHOT

> PPS. Don't use CayenneService as a DAO for deleting/saving, either.

I don't even know what CayenneService is ;)
For deleting/committing I inject an ObjectContext (with annotation @OCType(...) or ObjectContextProvider from tapestry5-cayenne-server


> public class TapestryCayenneService
> {
>     @Inject @Symbol(value="...") ...
> 
>     public Foo newFoo(ObjectContext oc)
>     {
>         Foo foo = oc.newObject(Foo.class);
>         // Set values in foo from injected symbols...
>         return foo;
>     }

I don't actually need the symbol to set database backed values. The setters are mostly in the classes auto generated by the CayenneModeler.
I need the value in other get methods, to return a value that would be the symbol concatenated with a property of the object.
  
For example: 

public class Foo extends _Foo {
  
@Inject @Symbol(value="...")

  public String getAbsoluteLocalFilepath(String baseDir) {
      
      return baseDir + "/" + getUserId() + "/" + getFilename();
    }
}



My problem ties into another problem: accessing files outside of webapp. 






> The other approach would be to use a servlet filter, which is much
> more complex.  You'd probably have to register a thread local to bind
> your Tapestry symbol values into and then retrieve them inside your
> CayenneDataObject subclasses (Foo, Bar, etc) using a lifecycle
> callback.  I think this approach would be more work and more magic
> (harder to implement and understand/maintain later), but if you would
> like to explore this avenue instead of a Tapestry service, just ask.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: use symbol value in POJO

Posted by Michael Gentry <mg...@masslight.net>.
On Thu, Nov 1, 2012 at 6:06 AM,  <de...@gmx.de> wrote:
> I don't even know what CayenneService is ;)

A typo on my part.  I was trying to reference the previous
TapestryCayenneService.

> For deleting/committing I inject an ObjectContext (with annotation @OCType(...) or ObjectContextProvider from tapestry5-cayenne-server

I haven't used the tapestry5-cayenne-server stuff, so I can't help you
there.  Hopefully it is working well for you, though.

mrg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: use symbol value in POJO

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 01 Nov 2012 08:46:42 -0200, <de...@gmx.de> wrote:

> getAbsoluteLocalFilepath() is called in page classes, e. g. to store a  
> file under this path. Another example for a method in Foo could be
> public InlineFileStreamResponse getImageAsStream() ...
> where we also need the baseDir.

With the above information in mind, I see no reason for injecting this  
configuration symbol into the entity classes. Just change  
getAbsoluteLocalFilepath() to receive the base path as a parameter. Or  
just create another method that returns the relative path and add the  
absolute path somewhere else.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: use symbol value in POJO

Posted by Michael Gentry <mg...@masslight.net>.
On Thu, Nov 1, 2012 at 6:46 AM,  <de...@gmx.de> wrote:
> public class Foo extends _Foo {
>
>    @Inject @Symbol(value="baseDir")  // not possible
>    String baseDir;
>
>    public String getAbsoluteLocalFilepath() {
>
>        return baseDir + "/" + toUser.getId() + "/" + getFilename();
>      }
> }
>
> The return value is a path to a file. The files get uploaded by users and each user has their own folder inside of baseDir. Each foo object has a relation to a user object and a field filename.
>
> baseDir is a symbol read from myApp.properties. On the production server it could be /var/myApp/userfiles/, on another machine it could be /home/username/myApp/userfiles, set in eclipse as VM argument -DbaseDir=...
>
> getAbsoluteLocalFilepath() is called in page classes, e. g. to store a file under this path. Another example for a method in Foo could be
> public InlineFileStreamResponse getImageAsStream() ...
> where we also need the baseDir.
>
> The files are uploaded by users. They can't be Assets and we don't want blobs in the database.


If you are going to do -DbaseDir=... as a VM argument, why not just
use System.getProperty("baseDir") to read the value?  No need to
@Inject it.


>> > The other approach would be to use a servlet filter, which is much
>> > more complex.  You'd probably have to register a thread local to bind
>> > your Tapestry symbol values into and then retrieve them inside your
>> > CayenneDataObject subclasses (Foo, Bar, etc) using a lifecycle
>> > callback.  I think this approach would be more work and more magic
>> > (harder to implement and understand/maintain later), but if you would
>> > like to explore this avenue instead of a Tapestry service, just ask.
>
> There are few methods like the example above and the baseDir and a second value are injected in page classes since the example with the Inject doesn't work. Then the baseDir is passed to the method:
> getAbsoluteLocalFilepath(baseDir);
>
>
> If I wrote a TapestryCayenneService, would I have to use it for the creation of every Cayenne object? There are 13 classes and only two of them would use two injected symbol values.


I think you are trying to do something different that I initially
thought, so I'd skip the service part for now and just keep creating
your Cayenne objects the way you are currently creating them.


mrg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: use symbol value in POJO

Posted by de...@gmx.de.
I'm sorry, I inadvertently sent the mail, but I wasn't finished writing yet :(

continued:
> For example: 
 
public class Foo extends _Foo {
   
   @Inject @Symbol(value="baseDir")  // not possible
   String baseDir;

   public String getAbsoluteLocalFilepath() {
       
       return baseDir + "/" + toUser.getId() + "/" + getFilename();
     }
}

The return value is a path to a file. The files get uploaded by users and each user has their own folder inside of baseDir. Each foo object has a relation to a user object and a field filename. 

baseDir is a symbol read from myApp.properties. On the production server it could be /var/myApp/userfiles/, on another machine it could be /home/username/myApp/userfiles, set in eclipse as VM argument -DbaseDir=...

getAbsoluteLocalFilepath() is called in page classes, e. g. to store a file under this path. Another example for a method in Foo could be 
public InlineFileStreamResponse getImageAsStream() ...
where we also need the baseDir.

The files are uploaded by users. They can't be Assets and we don't want blobs in the database.


> > The other approach would be to use a servlet filter, which is much
> > more complex.  You'd probably have to register a thread local to bind
> > your Tapestry symbol values into and then retrieve them inside your
> > CayenneDataObject subclasses (Foo, Bar, etc) using a lifecycle
> > callback.  I think this approach would be more work and more magic
> > (harder to implement and understand/maintain later), but if you would
> > like to explore this avenue instead of a Tapestry service, just ask.

There are few methods like the example above and the baseDir and a second value are injected in page classes since the example with the Inject doesn't work. Then the baseDir is passed to the method:
getAbsoluteLocalFilepath(baseDir);


If I wrote a TapestryCayenneService, would I have to use it for the creation of every Cayenne object? There are 13 classes and only two of them would use two injected symbol values.
Would it still be possible to use BeanEditForm to create objects?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org