You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Hervé Agnoux <he...@diaam-informatique.com> on 2011/06/05 21:19:31 UTC
I set a TransientRepository, I get a RepositoryImpl ?
Hi,
If I do that :
package com.hum;
import java.io.File;
import javax.jcr.Session;
import org.apache.jackrabbit.core.TransientRepository;
/**
*
* @author herve
*/
public class Repo
{
public static void main(String[] args) throws Exception
{
TransientRepository trans = new TransientRepository(
new File("/some/sort/of/path"));
Session session = trans.login();
TransientRepository transgetted =
(TransientRepository) session.getRepository();
}
}
I get :
Exception in thread "main" java.lang.ClassCastException:
org.apache.jackrabbit.core.RepositoryImpl cannot be cast to
org.apache.jackrabbit.core.TransientRepository
at com.hum.Repo.main(Repo.java:20)
Is it a bug or a feature ??
* with jackrabbit 2.1.2.
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Jukka Zitting <ju...@gmail.com>.
Hi Hervé,
Rather than get into a debate about the exact semantics of
getRepository() (which is a generally troublesome method for any
repository wrappers like the TransientRepository class), how about
discussing your use case instead?
Why do you need to class-cast the return value of
Session.getRepository(). If you need access to the extra
TransientRepository methods, why not keep a direct reference around
for that?
BR,
Jukka Zitting
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Michael Anstis <mi...@gmail.com>.
IIRC, TransientRepository automatically shutsdown when there are no
sessions.
2011/6/6 Hervé Agnoux <he...@diaam-informatique.com>
> Le lundi 6 juin 2011, Thomas Mueller a écrit :
> > Hi,
> >
> > Actually, the Javadoc for Session.getRepository() is: "Returns the
> > Repository object through which this session was acquired." -
> > http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/index.html - so I
> > guess the Jackrabbit isn't spec compliant when using the
> > TransientRepository.
> >
>
> +1 for me !
>
>
> > But I would also be interested in the use case (more than anything else).
> >
>
> It's not a business use case, it's a coding stuff :-)
>
> I say in my head : "I don't need to declare a variable for the repository,
> because I've session.getRepository(). So, I only need to declare a variable
> for session".
>
> I need to downcasting because there is no shutdown method in
> javax.jcr.Repository.
>
> And it's all. Sorry, my fault :-)
>
>
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Hervé Agnoux <he...@diaam-informatique.com>.
Le lundi 6 juin 2011, Thomas Mueller a écrit :
> Hi,
>
> Actually, the Javadoc for Session.getRepository() is: "Returns the
> Repository object through which this session was acquired." -
> http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/index.html - so I
> guess the Jackrabbit isn't spec compliant when using the
> TransientRepository.
>
+1 for me !
> But I would also be interested in the use case (more than anything else).
>
It's not a business use case, it's a coding stuff :-)
I say in my head : "I don't need to declare a variable for the repository,
because I've session.getRepository(). So, I only need to declare a variable
for session".
I need to downcasting because there is no shutdown method in
javax.jcr.Repository.
And it's all. Sorry, my fault :-)
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Thomas Mueller <mu...@adobe.com>.
Hi,
Actually, the Javadoc for Session.getRepository() is: "Returns the
Repository object through which this session was acquired." -
http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/index.html - so I
guess the Jackrabbit isn't spec compliant when using the
TransientRepository.
But I would also be interested in the use case (more than anything else).
Regards,
Thomas
On 6/6/11 12:15 PM, "Hervé Agnoux" <he...@diaam-informatique.com>
wrote:
>Le lundi 6 juin 2011, Alexander Klimetschek a écrit :
>>
>> session.getRepository() returns a Repository interface. You cannot make
>> any assumption about its implementation. In Jackrabbit's
>
>I don't understand the philosophy.
>
>I init a repository with the implementation I choose, so the jcr MUST get
>back
>the implementation I choose, not other assumption.
>
>
>> TransientRepository case, it's actually a different object than the
>> TransientRepository you start at the beginning, because of some good
>> reason. Since creating/starting the repository (in this case calling
>> Jackrabbit's "new TransientRepository") is not defined by the JCR
>> spec/API, this is ok.
>>
>
>What is ok ? What are these good reasons ? If JCR doesn't define, why
>doesn't
>use the define I choose ?
>
>
>> Might even be to avoid that other (unprivileged) sessions can actually
>> cast back to the TransientRepository to get "control" over the
>>repository,
>> but I don't know for sure.
>>
>
>In this case, session.getRepository() is a mistake in itself. Perhaps
>session.getProxyOrSomethingElseRepository ?
>
>
>> Regards,
>
>Same.
>
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 06.06.11 12:15, "Hervé Agnoux" <he...@diaam-informatique.com>
wrote:
>I init a repository with the implementation I choose, so the jcr MUST get
>back
>the implementation I choose, not other assumption.
Why do you think it MUST? The API defines the Repository interface,
nothing more.
Any casting to implementations is always depending on the implementation,
otherwise what's the sense of interfaces in Java?
>>TransientRepository case, it's actually a different object than the
>> TransientRepository you start at the beginning, because of some good
>> reason. Since creating/starting the repository (in this case calling
>> Jackrabbit's "new TransientRepository") is not defined by the JCR
>> spec/API, this is ok.
>>
>
>What is ok ? What are these good reasons ? If JCR doesn't define, why
>doesn't
>use the define I choose ?
What is your use case anyway? I don't see the problem at all. Just keep
the TransientRepository instance, if you need the implementation-specific
stuff.
Regards,
Alex
--
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Hervé Agnoux <he...@diaam-informatique.com>.
Le lundi 6 juin 2011, Alexander Klimetschek a écrit :
>
> session.getRepository() returns a Repository interface. You cannot make
> any assumption about its implementation. In Jackrabbit's
I don't understand the philosophy.
I init a repository with the implementation I choose, so the jcr MUST get back
the implementation I choose, not other assumption.
> TransientRepository case, it's actually a different object than the
> TransientRepository you start at the beginning, because of some good
> reason. Since creating/starting the repository (in this case calling
> Jackrabbit's "new TransientRepository") is not defined by the JCR
> spec/API, this is ok.
>
What is ok ? What are these good reasons ? If JCR doesn't define, why doesn't
use the define I choose ?
> Might even be to avoid that other (unprivileged) sessions can actually
> cast back to the TransientRepository to get "control" over the repository,
> but I don't know for sure.
>
In this case, session.getRepository() is a mistake in itself. Perhaps
session.getProxyOrSomethingElseRepository ?
> Regards,
Same.
Re: I set a TransientRepository, I get a RepositoryImpl ?
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 05.06.11 21:19, "Hervé Agnoux" <he...@diaam-informatique.com>
wrote:
> TransientRepository trans = new TransientRepository(
> new File("/some/sort/of/path"));
> Session session = trans.login();
> TransientRepository transgetted =
> (TransientRepository) session.getRepository();
>...
>I get :
>
>Exception in thread "main" java.lang.ClassCastException:
>org.apache.jackrabbit.core.RepositoryImpl cannot be cast to
>org.apache.jackrabbit.core.TransientRepository
> at com.hum.Repo.main(Repo.java:20)
>
>Is it a bug or a feature ??
session.getRepository() returns a Repository interface. You cannot make
any assumption about its implementation. In Jackrabbit's
TransientRepository case, it's actually a different object than the
TransientRepository you start at the beginning, because of some good
reason. Since creating/starting the repository (in this case calling
Jackrabbit's "new TransientRepository") is not defined by the JCR
spec/API, this is ok.
Might even be to avoid that other (unprivileged) sessions can actually
cast back to the TransientRepository to get "control" over the repository,
but I don't know for sure.
Regards,
Alex
--
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel