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 Sridhar <sn...@dot.state.nc.us> on 2004/04/22 22:21:12 UTC
Description Repositories at Thread level
Hi,
I need to define a repository that needs to work both in Oracle as well as MS-
Access. Some jdbc datatypes like BLOB and CLOB in Oracle maps to LONGVARBINARY
and LONGVARCHAR in access. Also, on some rare occasions I need to copy data
between Access and Oracle. In one case the table names are different (the table
represented by class "LLEAgency"). To overcome I defined the repository for
Oracle data types and change them to access data types when required. This
method is on a class that extends Thread.
public void makeAccessCompatible()
{
MetadataManager mdm = MetadataManager.getInstance();
mdm.setEnablePerThreadChanges(true);
DescriptorRepository dr = mdm.copyOfGlobalRepository();
Iterator ir = dr.iterator();
while(ir.hasNext())
{
ClassDescriptor cd = (ClassDescriptor) ir.next();
if(cd.getClassNameOfObject().endsWith("LLEAgency"))
{
System.out.println(cd.getFullTableName());
cd.setTableName("CODES_DEPARTMENTS");
}
FieldDescriptor[] flds = cd.getFieldDescriptions();
for (int i = 0; i < flds.length; i++)
{
FieldDescriptor fd = flds[i];
if (fd.getColumnType().toLowerCase().equals("blob"))
{
fd.setColumnType("longvarbinary");
}
else if (fd.getColumnType().toLowerCase().equals("clob"))
{
fd.setColumnType("longvarchar");
}
}
}
mdm.setDescriptor(dr);
}
After executing this on one of the threads, I checked the repository on both
the threads and they are exactly same, this is how I checked, compare the
String returned from the 2 threads using
MetadataManager.getInstance().getRepository().toXML();
I have tried setting the
MetadataManager.getInstance().setEnablePerThreadChanges(true);
at various points, including the application startup. But still no luck.
Looks like I am missing something very obvious here. When I get a
copyofGlobalRepository, I assume I get a copy entire repository tree, with the
Class, Field descriptors everything. Am I still working with the same object
references or differet objects/references? Can anyone please help me with this?
Thanks & Regards
Sridhar
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Description Repositories at Thread level
Posted by Sridhar <sn...@dot.state.nc.us>.
Armin Waibel <arminw <at> apache.org> writes:
Armin,
Thank you so much. I had already done everything that you had said, but had
some problems with my Thread execution. Your hint about ThreadLocal helped out.
I was not making/storing the descriptor changes in the run() method of my
thread. I was doing it in some other method of my object that extended Thread,
but the execution was happening in the main() Thread, this caused the default
descriptors to be over-written.
OJB has greatly decreased the time I use to spend on writing sql. Thanks again,
for a great product and excellent "free" support!!!!
Regards,
Sridhar
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Description Repositories at Thread level
Posted by Armin Waibel <ar...@apache.org>.
Hi Sridhar,
in your case you can setup two different repository and read the second
one at runtime (with both jdbc-connection-descriptor declared in the
default repository, in the second one only declare object metadata -
then you don't need to read and merge the second ConnectionRepository)
or you can modify a copy of the default repository object metadata.
http://db.apache.org/ojb/api/org/apache/ojb/broker/metadata/MetadataManager.html
I recommend to use object metadata profiles. You can handle this stuff
in a startup class or something similar. Say you have two
DescriptorRepository instances one for Oracle , one forAccess
MetadataManager mm = MetadataManager.getInstance();
mm.addProfile("access", accessDescriptorRepository);
mm.addProfile("oracle", accessDescriptorRepository);
Now OJB manage three DescriptorRepository instances the "default one"
automatic read by OJB (access or oracle) and two profiles for use in
threaded mode.
Currently OJB allows to enable per thread mode when needed. So you can
enable per thread mode when needed or at startup.
mm.setEnablePerThreadChanges(true);
OJB now support per thread object metadata via a ThreadLocal instance.
But you have to tell the MM which profile to use. If you now obtain a
PersistenceBroker instance from the PBF you will get the "default one".
BEFORE obtain the PB instance call
mm.loadProfile("oracle");
PersistenceBroker broker = PersistenceBrokerFactory.cre....;
Now the object metadata profile for "oracle" is associated with the
obtained PB instance. All further obtained PB instance of the current
thread will now use the oracle profile. If you want to change the
profile for current thread call loadProfile again.
hope this will help you!
regards,
Armin
Sridhar wrote:
> Hi,
>
> I need to define a repository that needs to work both in Oracle as well as MS-
> Access. Some jdbc datatypes like BLOB and CLOB in Oracle maps to LONGVARBINARY
> and LONGVARCHAR in access. Also, on some rare occasions I need to copy data
> between Access and Oracle. In one case the table names are different (the table
> represented by class "LLEAgency"). To overcome I defined the repository for
> Oracle data types and change them to access data types when required. This
> method is on a class that extends Thread.
>
> public void makeAccessCompatible()
> {
> MetadataManager mdm = MetadataManager.getInstance();
> mdm.setEnablePerThreadChanges(true);
> DescriptorRepository dr = mdm.copyOfGlobalRepository();
> Iterator ir = dr.iterator();
> while(ir.hasNext())
> {
> ClassDescriptor cd = (ClassDescriptor) ir.next();
> if(cd.getClassNameOfObject().endsWith("LLEAgency"))
> {
> System.out.println(cd.getFullTableName());
> cd.setTableName("CODES_DEPARTMENTS");
> }
> FieldDescriptor[] flds = cd.getFieldDescriptions();
> for (int i = 0; i < flds.length; i++)
> {
> FieldDescriptor fd = flds[i];
> if (fd.getColumnType().toLowerCase().equals("blob"))
> {
> fd.setColumnType("longvarbinary");
> }
> else if (fd.getColumnType().toLowerCase().equals("clob"))
> {
> fd.setColumnType("longvarchar");
> }
> }
> }
> mdm.setDescriptor(dr);
> }
>
> After executing this on one of the threads, I checked the repository on both
> the threads and they are exactly same, this is how I checked, compare the
> String returned from the 2 threads using
>
> MetadataManager.getInstance().getRepository().toXML();
>
> I have tried setting the
>
> MetadataManager.getInstance().setEnablePerThreadChanges(true);
>
> at various points, including the application startup. But still no luck.
> Looks like I am missing something very obvious here. When I get a
> copyofGlobalRepository, I assume I get a copy entire repository tree, with the
> Class, Field descriptors everything. Am I still working with the same object
> references or differet objects/references? Can anyone please help me with this?
>
> Thanks & Regards
> Sridhar
>
>
> ---------------------------------------------------------------------
> 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