You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Borut Bolčina <bo...@najdi.si> on 2006/04/19 20:30:37 UTC

[configuration] dbconfiguration

Hello,

an experimental question I have. Suppose I use database to store 
configuration key and values. The database table has two columns:

key = VARCHAR
value = BLOB

The value is XML serialized from POJO with XStream. I can easily write 
to databse with

    dbconfig.setProperty(someKeyAsString, someValueAsString)


How do I get someValueAsString back from database? It seems I can only use

    Object someValueAsObject = dbconfig.getProperty(someKeyAsString):


But I need String, Reader or InputStream to serialize someValue back to 
POJO.


-Borut

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


Re: [configuration] dbconfiguration

Posted by Oliver Heger <ol...@t-online.de>.
You probably get an instance of an implementation of the java.sql.Blob
interface specific to your JDBC driver. This causes the ClassCastException.

A possible solution could be to create a new class derived from
DatabaseConfiguration and overload the getProperty() method. In this
method you first call the super method and then check if its result is
of type java.sql.Blob. If this is the case, you can use the methods of
the Blob interface to extract the data and return it as String. I assume
this would work.

Oliver

Borut Bolčina wrote:

> Christian Hufgard pravi:
>
>> Hi Borut,
>>
>> what exactly is the type you get, if you invoke
>> dbConfig.getProperty(someKeyAsString).getClass()?
>>   
>
> Casting to String threw ClassCastException. I removed the code
> completely (actualy it lives in byte heavens = svn), so I won't be
> able to answer this question as it would mean reconstructing previous
> enviroment.
>
>>  
>>
>>> Anyway, I solved the problem differenly now.
>>>     
>>
>>
>> In which way?
>>   
>
> Design change. I am not using dbconfiguration anymore, as application
> requirements changed, but I of course continue to use
> CompositeConfiguration for different purposes. Now I use Cayenne for
> storing values which were before in serialized XML.
>
>> Christian
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>   
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


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


Re: [configuration] dbconfiguration

Posted by Borut Bolčina <bo...@najdi.si>.
Christian Hufgard pravi:
> Hi Borut,
>
> what exactly is the type you get, if you invoke
> dbConfig.getProperty(someKeyAsString).getClass()?
>   
Casting to String threw ClassCastException. I removed the code 
completely (actualy it lives in byte heavens = svn), so I won't be able 
to answer this question as it would mean reconstructing previous enviroment.
>   
>> Anyway, I solved the problem differenly now.
>>     
>
> In which way?
>   
Design change. I am not using dbconfiguration anymore, as application 
requirements changed, but I of course continue to use 
CompositeConfiguration for different purposes. Now I use Cayenne for 
storing values which were before in serialized XML.
> Christian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>   


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


Re[2]: [configuration] dbconfiguration

Posted by Christian Hufgard <ch...@gmx.de>.
Hi Borut,

what exactly is the type you get, if you invoke
dbConfig.getProperty(someKeyAsString).getClass()?

> Anyway, I solved the problem differenly now.

In which way?

Christian


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


Re: [configuration] dbconfiguration

Posted by Borut Bolčina <bo...@najdi.si>.
Hello,

Jacob Kjome pravi:
>>> Object someValueAsObject = dbconfig.getProperty(someKeyAsString):
>>>       
>
> Borut,
>
> Wouldn't you be treating the value that you get back from dbconfig as a String,
> which is XStream-serialized XML, and then pass this into XStream to build it
> back into an object again?  
The problem lies in BLOB. If the coloumn was VARCHAR it would work just 
fine. I don't remember now exactly the error message, but the returned 
object was not a String.
> You're not suggesting that commons-configuration
> should do this internally, are you?
>   
No, not at all.
> Once you have the XML String from the config, just do, for instance...
>
> String xml = dbconfig.getString(someKeyAsString):      // ERROR, 
> Person savedPerson = (Person)xstream.fromXML(xml);
>   
This was exactly my intention, but with BLOB as value coloumn type, this 
gives an error. I guess it would work with CLOB, but I did't try. 
Anyway, I solved the problem differenly now.
>
> Jake
>
> Quoting "Oliver.Heger@t-online.de" <Ol...@t-online.de>:
>
>   
>> I don't know the code in DatabaseConfiguration too well because I was
>> not involved in this class. What problems do you have when you call
>> other methods like getString(), getInt() etc.? Is an exception thrown?
>>
>> Oliver
>>
>> -----Original Message-----
>> Date: Wed, 19 Apr 2006 20:30:37 +0200
>> Subject: [configuration] dbconfiguration
>> From: Borut Bol?ina
>> To: Jakarta Commons Users List
>>
>> Hello,
>>
>> an experimental question I have. Suppose I use database to store
>> configuration key and values. The database table has two columns:
>>
>> key = VARCHAR
>> value = BLOB
>>
>> The value is XML serialized from POJO with XStream. I can easily write
>> to databse with
>>
>>     dbconfig.setProperty(someKeyAsString, someValueAsString)
>>
>>
>> How do I get someValueAsString back from database? It seems I can only
>> use
>>
>>     Object someValueAsObject = dbconfig.getProperty(someKeyAsString):
>>
>>
>> But I need String, Reader or InputStream to serialize someValue back to
>> POJO.
>>
>>
>> -Borut
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>     
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>   


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


Re: [configuration] dbconfiguration

Posted by Jacob Kjome <ho...@visi.com>.
>> Object someValueAsObject = dbconfig.getProperty(someKeyAsString):

Borut,

Wouldn't you be treating the value that you get back from dbconfig as a String,
which is XStream-serialized XML, and then pass this into XStream to build it
back into an object again?  You're not suggesting that commons-configuration
should do this internally, are you?

Once you have the XML String from the config, just do, for instance...

String xml = dbconfig.getString(someKeyAsString):
Person savedPerson = (Person)xstream.fromXML(xml);


Jake

Quoting "Oliver.Heger@t-online.de" <Ol...@t-online.de>:

> I don't know the code in DatabaseConfiguration too well because I was
> not involved in this class. What problems do you have when you call
> other methods like getString(), getInt() etc.? Is an exception thrown?
>
> Oliver
>
> -----Original Message-----
> Date: Wed, 19 Apr 2006 20:30:37 +0200
> Subject: [configuration] dbconfiguration
> From: Borut Bol?ina
> To: Jakarta Commons Users List
>
> Hello,
>
> an experimental question I have. Suppose I use database to store
> configuration key and values. The database table has two columns:
>
> key = VARCHAR
> value = BLOB
>
> The value is XML serialized from POJO with XStream. I can easily write
> to databse with
>
>     dbconfig.setProperty(someKeyAsString, someValueAsString)
>
>
> How do I get someValueAsString back from database? It seems I can only
> use
>
>     Object someValueAsObject = dbconfig.getProperty(someKeyAsString):
>
>
> But I need String, Reader or InputStream to serialize someValue back to
> POJO.
>
>
> -Borut
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>




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


Re: [configuration] dbconfiguration

Posted by "Oliver.Heger@t-online.de" <Ol...@t-online.de>.
I don't know the code in DatabaseConfiguration too well because I was
not involved in this class. What problems do you have when you call
other methods like getString(), getInt() etc.? Is an exception thrown?

Oliver

-----Original Message-----
Date: Wed, 19 Apr 2006 20:30:37 +0200
Subject: [configuration] dbconfiguration
From: Borut Bol?ina 
To: Jakarta Commons Users List 

Hello,

an experimental question I have. Suppose I use database to store 
configuration key and values. The database table has two columns:

key = VARCHAR
value = BLOB

The value is XML serialized from POJO with XStream. I can easily write 
to databse with

    dbconfig.setProperty(someKeyAsString, someValueAsString)


How do I get someValueAsString back from database? It seems I can only
use

    Object someValueAsObject = dbconfig.getProperty(someKeyAsString):


But I need String, Reader or InputStream to serialize someValue back to 
POJO.


-Borut

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





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