You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Mauricio Montblanch <mm...@uragua.com.uy> on 2005/04/11 16:26:09 UTC

Re: Runtime Connection (PROGRESING BUT... )

Hi, I Keep Having problems

            before the conection  

            MetadataManager metadataManager = MetadataManager.getInstance();
            ConnectionRepository repository = 
metadataManager.readConnectionRepository(getXmlconection(servidor));
            metadataManager.mergeConnectionRepository(repository);
            metadataManager.setDefaultPBKey(new PBKey("postgreSQL"));

      
          the conection

            implementation = OJB.getInstance();
            database = implementation.newDatabase();
            database.open("postgreSQL", Database.OPEN_READ_WRITE);


             (this work if I use the right server name)


             after the fail conection (I used a wrong server name)


               List descriptors = 
metadataManager.connectionRepository().getAllDescriptor();
                for (int i = 0; i < descriptors.size(); i++) {
                    
metadataManager.connectionRepository().removeDescriptor(descriptors.get(i));
                }

             during a second atempt to conect I get

        Default key is already set. Current key is 
org.apache.ojb.broker.PBKey: jcdAlias=postgreSQL, user=null, password=null
        when excecuting
         metadataManager.setDefaultPBKey(new PBKey("postgreSQL"));


    if I do not Execute the line  in the second atempt (the conections 
also fails) any idea of how can I reset the MetadataManager , or any 
other idea

             best regard MM



Armin Waibel escribió:

> Mauricio Montblanch wrote:
>
>> Thanks Again
>>
>> Another cuestion how do I remove a Database profile from the 
>> repositry (so if it incorrect y can add  a new one with the same name);
>>
>
> mm.connectionRepository().removeDescriptor(Object validKey)
>
> argument is a PBKey or the JCD instance itself.
>
> Armin
>
>>
>>
>> Armin Waibel escribió:
>>
>>> Mauricio Montblanch wrote:
>>>
>>>> hi
>>>>    adding  mm.setDefaultPBKey(new PBKey("postgreSQL"))  makes it work
>>>>
>>>
>>> ok, in next version of OJB this will be fixed 
>>> (http://issues.apache.org/jira/browse/OJB-17). Until then you have 
>>> to use the workaround.
>>>
>>> regards,
>>> Armin
>>>
>>>
>>>>
>>>>             Thanks MM
>>>>
>>>> Armin Waibel escribió:
>>>>
>>>>> Hi Mauricio,
>>>>>
>>>>> seems that your jcd is not marked as "default" connection. Did you 
>>>>> tried to do
>>>>> // other steps
>>>>> ....
>>>>> // merge new connection metadata with existing one
>>>>> mm.mergeConnectionRepository(cr);
>>>>> //mm.setDefaultPBKey(new PBKey("postgreSQL", "gsf", "gsf"))
>>>>> // should work too
>>>>> //mm.setDefaultPBKey(new PBKey("postgreSQL"))
>>>>> ...
>>>>>
>>>>> or avoid the use of
>>>>> PersistenceBrokerFactory.defaultPersistenceBroker()
>>>>> method.
>>>>>
>>>>> regards,
>>>>> Armin
>>>>>
>>>>> Mauricio Montblanch wrote:
>>>>>
>>>>>>  
>>>>>> Hi want to use a runtime conection, but OJB never takes the ne 
>>>>>> data as valid
>>>>>>
>>>>>>
>>>>>> this is the metadata I am using in the file bases.txt:
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <!DOCTYPE descriptor-repository SYSTEM "repository.dtd">
>>>>>>
>>>>>> <descriptor-repository version="1.0" 
>>>>>> isolation-level="read-uncommitted">
>>>>>> <jdbc-connection-descriptor
>>>>>>    jcd-alias="postgreSQL"
>>>>>>    default-connection="true"
>>>>>>    platform="postgreSQL"
>>>>>>    jdbc-level="3.0"
>>>>>>    driver="org.postgresql.Driver"
>>>>>>    protocol="jdbc"
>>>>>>    subprotocol="postgresql"
>>>>>>    dbalias="//93.100.10.99:5432/GSF-DB"
>>>>>>    username="gsf"
>>>>>>    password="gsf"
>>>>>>    eager-release="false"
>>>>>>    batch-mode="false"
>>>>>>    useAutoCommit="0"
>>>>>>    ignoreAutoCommitExceptions="false"
>>>>>>    >
>>>>>>
>>>>>>    <connection-pool
>>>>>>        maxActive="5"
>>>>>>        maxIdle="2"
>>>>>>        maxWait="3"
>>>>>>        minEvictableIdleTimeMillis="4"
>>>>>>        numTestsPerEvictionRun="5"
>>>>>>        testOnBorrow="true"
>>>>>>        testOnReturn="true"
>>>>>>        testWhileIdle="true"
>>>>>>        timeBetweenEvictionRunsMillis="6"
>>>>>>        whenExhaustedAction="2"
>>>>>>        validationQuery="SELECT current_date"
>>>>>>        logAbandoned="true"
>>>>>>        removeAbandoned="true"
>>>>>>        removeAbandonedTimeout="8"/>
>>>>>>
>>>>>>    <sequence-manager 
>>>>>> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl"> 
>>>>>>
>>>>>>        <attribute attribute-name="autoNaming" 
>>>>>> attribute-value="true"/>
>>>>>>    </sequence-manager>
>>>>>> </jdbc-connection-descriptor>
>>>>>> </descriptor-repository>
>>>>>>
>>>>>> this is the code (is like the example in the documencion)
>>>>>>
>>>>>>            MetadataManager mm = MetadataManager.getInstance();
>>>>>>
>>>>>>            // read connection metadata from repository file
>>>>>>            ConnectionRepository cr = 
>>>>>> mm.readConnectionRepository("...../bases.txt");
>>>>>>
>>>>>>            // merge new connection metadata with existing one
>>>>>>            mm.mergeConnectionRepository(cr);
>>>>>>
>>>>>>
>>>>>>             //this section works if the file metadata is in 
>>>>>> reopsitory_database.xml
>>>>>>            impl = OJB.getInstance();
>>>>>>            db = impl.newDatabase();
>>>>>>            db.open("postgreSQL", Database.OPEN_READ_WRITE);
>>>>>>
>>>>>>
>>>>>>    this is the error message:
>>>>>>    org.apache.ojb.broker.PBFactoryException: There was no 
>>>>>> default-PBKey specified
>>>>>>    at 
>>>>>> org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersistenceBroker(PersistenceBrokerFactoryBaseImpl.java:157) 
>>>>>>
>>>>>>    at 
>>>>>> org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker(PersistenceBrokerFactory.java:65) 
>>>>>>
>>>>>>    at logica.persistence.Persistence.openManualPersistence
>>>>>>
>>>>>>
>>>>>> any Ideas
>>>>>>
>>>>>>                   Best Regard MM
>>>>>>
>>>>>>
>>>>>> --------------------------------------------------------------------- 
>>>>>>
>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Runtime Connection (PROGRESING BUT... )

Posted by Armin Waibel <ar...@apache.org>.
Hi,

in current OJB version it's not possible to reset the "default 
connection" setting (to avoid side-effects). If try to set the default 
PBKey more than one, you will get an exception.
In the OJB_1_0_RELEASE branch I changed this behavior (MetadataManager + 
ConnectionRepository). You can patch MetadataManager#setDefaultKey to 
allow reset of the key. This should resolve your problem.

regards,
Armin

Mauricio Montblanch wrote:
> Hi, I Keep Having problems
> 
>            before the conection 
>            MetadataManager metadataManager = MetadataManager.getInstance();
>            ConnectionRepository repository = 
> metadataManager.readConnectionRepository(getXmlconection(servidor));
>            metadataManager.mergeConnectionRepository(repository);
>            metadataManager.setDefaultPBKey(new PBKey("postgreSQL"));
> 
>               the conection
> 
>            implementation = OJB.getInstance();
>            database = implementation.newDatabase();
>            database.open("postgreSQL", Database.OPEN_READ_WRITE);
> 
> 
>             (this work if I use the right server name)
> 
> 
>             after the fail conection (I used a wrong server name)
> 
> 
>               List descriptors = 
> metadataManager.connectionRepository().getAllDescriptor();
>                for (int i = 0; i < descriptors.size(); i++) {
>                    
> metadataManager.connectionRepository().removeDescriptor(descriptors.get(i)); 
> 
>                }
> 
>             during a second atempt to conect I get
> 
>        Default key is already set. Current key is 
> org.apache.ojb.broker.PBKey: jcdAlias=postgreSQL, user=null, password=null
>        when excecuting
>         metadataManager.setDefaultPBKey(new PBKey("postgreSQL"));
> 
> 
>    if I do not Execute the line  in the second atempt (the conections 
> also fails) any idea of how can I reset the MetadataManager , or any 
> other idea
> 
>             best regard MM
> 
> 
> 
> Armin Waibel escribió:
> 
>> Mauricio Montblanch wrote:
>>
>>> Thanks Again
>>>
>>> Another cuestion how do I remove a Database profile from the 
>>> repositry (so if it incorrect y can add  a new one with the same name);
>>>
>>
>> mm.connectionRepository().removeDescriptor(Object validKey)
>>
>> argument is a PBKey or the JCD instance itself.
>>
>> Armin
>>
>>>
>>>
>>> Armin Waibel escribió:
>>>
>>>> Mauricio Montblanch wrote:
>>>>
>>>>> hi
>>>>>    adding  mm.setDefaultPBKey(new PBKey("postgreSQL"))  makes it work
>>>>>
>>>>
>>>> ok, in next version of OJB this will be fixed 
>>>> (http://issues.apache.org/jira/browse/OJB-17). Until then you have 
>>>> to use the workaround.
>>>>
>>>> regards,
>>>> Armin
>>>>
>>>>
>>>>>
>>>>>             Thanks MM
>>>>>
>>>>> Armin Waibel escribió:
>>>>>
>>>>>> Hi Mauricio,
>>>>>>
>>>>>> seems that your jcd is not marked as "default" connection. Did you 
>>>>>> tried to do
>>>>>> // other steps
>>>>>> ....
>>>>>> // merge new connection metadata with existing one
>>>>>> mm.mergeConnectionRepository(cr);
>>>>>> //mm.setDefaultPBKey(new PBKey("postgreSQL", "gsf", "gsf"))
>>>>>> // should work too
>>>>>> //mm.setDefaultPBKey(new PBKey("postgreSQL"))
>>>>>> ...
>>>>>>
>>>>>> or avoid the use of
>>>>>> PersistenceBrokerFactory.defaultPersistenceBroker()
>>>>>> method.
>>>>>>
>>>>>> regards,
>>>>>> Armin
>>>>>>
>>>>>> Mauricio Montblanch wrote:
>>>>>>
>>>>>>>  
>>>>>>> Hi want to use a runtime conection, but OJB never takes the ne 
>>>>>>> data as valid
>>>>>>>
>>>>>>>
>>>>>>> this is the metadata I am using in the file bases.txt:
>>>>>>>
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <!DOCTYPE descriptor-repository SYSTEM "repository.dtd">
>>>>>>>
>>>>>>> <descriptor-repository version="1.0" 
>>>>>>> isolation-level="read-uncommitted">
>>>>>>> <jdbc-connection-descriptor
>>>>>>>    jcd-alias="postgreSQL"
>>>>>>>    default-connection="true"
>>>>>>>    platform="postgreSQL"
>>>>>>>    jdbc-level="3.0"
>>>>>>>    driver="org.postgresql.Driver"
>>>>>>>    protocol="jdbc"
>>>>>>>    subprotocol="postgresql"
>>>>>>>    dbalias="//93.100.10.99:5432/GSF-DB"
>>>>>>>    username="gsf"
>>>>>>>    password="gsf"
>>>>>>>    eager-release="false"
>>>>>>>    batch-mode="false"
>>>>>>>    useAutoCommit="0"
>>>>>>>    ignoreAutoCommitExceptions="false"
>>>>>>>    >
>>>>>>>
>>>>>>>    <connection-pool
>>>>>>>        maxActive="5"
>>>>>>>        maxIdle="2"
>>>>>>>        maxWait="3"
>>>>>>>        minEvictableIdleTimeMillis="4"
>>>>>>>        numTestsPerEvictionRun="5"
>>>>>>>        testOnBorrow="true"
>>>>>>>        testOnReturn="true"
>>>>>>>        testWhileIdle="true"
>>>>>>>        timeBetweenEvictionRunsMillis="6"
>>>>>>>        whenExhaustedAction="2"
>>>>>>>        validationQuery="SELECT current_date"
>>>>>>>        logAbandoned="true"
>>>>>>>        removeAbandoned="true"
>>>>>>>        removeAbandonedTimeout="8"/>
>>>>>>>
>>>>>>>    <sequence-manager 
>>>>>>> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl"> 
>>>>>>>
>>>>>>>        <attribute attribute-name="autoNaming" 
>>>>>>> attribute-value="true"/>
>>>>>>>    </sequence-manager>
>>>>>>> </jdbc-connection-descriptor>
>>>>>>> </descriptor-repository>
>>>>>>>
>>>>>>> this is the code (is like the example in the documencion)
>>>>>>>
>>>>>>>            MetadataManager mm = MetadataManager.getInstance();
>>>>>>>
>>>>>>>            // read connection metadata from repository file
>>>>>>>            ConnectionRepository cr = 
>>>>>>> mm.readConnectionRepository("...../bases.txt");
>>>>>>>
>>>>>>>            // merge new connection metadata with existing one
>>>>>>>            mm.mergeConnectionRepository(cr);
>>>>>>>
>>>>>>>
>>>>>>>             //this section works if the file metadata is in 
>>>>>>> reopsitory_database.xml
>>>>>>>            impl = OJB.getInstance();
>>>>>>>            db = impl.newDatabase();
>>>>>>>            db.open("postgreSQL", Database.OPEN_READ_WRITE);
>>>>>>>
>>>>>>>
>>>>>>>    this is the error message:
>>>>>>>    org.apache.ojb.broker.PBFactoryException: There was no 
>>>>>>> default-PBKey specified
>>>>>>>    at 
>>>>>>> org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersistenceBroker(PersistenceBrokerFactoryBaseImpl.java:157) 
>>>>>>>
>>>>>>>    at 
>>>>>>> org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker(PersistenceBrokerFactory.java:65) 
>>>>>>>
>>>>>>>    at logica.persistence.Persistence.openManualPersistence
>>>>>>>
>>>>>>>
>>>>>>> any Ideas
>>>>>>>
>>>>>>>                   Best Regard MM
>>>>>>>
>>>>>>>
>>>>>>> --------------------------------------------------------------------- 
>>>>>>>
>>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org