3 Replies Latest reply on May 28, 2003 10:15 AM by bleupen

    Getting at a sql-type mapping

      I've got some code that needs to drop down into SQL to run some ALTER TABLE statements to alter the tables that my CMP beans back to. I'm trying to do it a mapping-agnostic way such that when I change my type-mapping from one database to another, the code still works. So I think I just need to be able to get at something like getSqlTypeForJavaType on JDBCTypeMappingMetaData. I took a stab at trying to traverse the long chain of objects to get to one of these and failed somewhere along the way. So before I keep trying, I thought I'd just post here and see if anyone has any suggestions on a nice clean way to do this. Doing it all through a JMX call or two would be ideal, but I'll take what I can get. :) Thanks.

        • 1. Re: Getting at a sql-type mapping

          So now I'm trying to get at an instance of JDBCTypeMappingMetaData so I can call getSqlTypeForJavaType() and running into a problem. Here's the only path I've been able to find to get me there (in theory) from an EntityContainer:

          CMPPersistenceManager man = (CMPPersistenceManager) container.getPersistenceManager();
          JDBCStoreManager store = (JDBCStoreManager) man.getPersistenceStore();
          JDBCTypeFactory factory = store.getJDBCTypeFactory();
          return factory.getTypeMapping().getSqlTypeForJavaType(c);

          The problem is, the call to getPersistenceManager() returns an instance of org.jboss.resource.connectionmanager.CachedConnectionInterceptor, which doesn't expose getPersistenceStore(). Looking at the code, it looks like it wraps the real PersistenceManager and then hides it away so there's no way to actually access it. At this point, I'm stuck. Can anyone offer any suggestions on how to get at the PersistenceManager, or some other way to get at the functionality of getSqlTypeForJavaType? Thanks.

          • 2. Re: Getting at a sql-type mapping

            Based on the deafening silence here, I assume nobody has a good answer for me. :) I ended up defining a single "adaptor" entity bean with a different container configuration that removed the CachedConnectionInterceptor, then got at the type mapping through that. Works great. But this is a lame hack, and I still can't get to other bean-specific attributes (e.g. table name) that is on each bean's respective instance of JDBCStoreManager. I filed on bug on this problem at http://sourceforge.net/tracker/?func=detail&aid=740024&group_id=22866&atid=376685

            • 3. Re: Getting at a sql-type mapping
              bleupen

              are you creating an interceptor to do this? if so, the code you have written will work if you put it in the interceptor's create() method and set an instance variable.

              b