ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maarten Meijer <mjmei...@xs4all.nl>
Subject Using Ibatis as core for an Eclipse SQL plugin
Date Thu, 14 Feb 2008 15:55:39 GMT
Hi,

I'm working on Eclipse Mylyn bug 184532: [connector] Generic SQL  
connector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=184532

As I have some experience with Ibatis as database connection for a  
servlet I try to use it here again.
Benefits of ibatis for this bug:
The XML configurable SQL result sets makes it possible to map from  
almost any accessible database to the Mylyn task model.

I've succeeded in opening the SqlMapConfix.xml with parameters in a  
properties file using the following code:

public class TasksSqlMapConfig {
	private static SqlMapClient sqlMap = null;

	public static SqlMapClient getSqlMapInstance() throws CoreException {
		if (null == sqlMap) {
			try {
				InputStream resource = null;
				Path mapPath = new Path("maps/SqlMapConfig.xml");
				resource =  
FileLocator.openStream(IbatisCorePlugin.getDefault().getBundle(),  
mapPath, false);
				// replace with read from pref later
				Path propPath = new Path("maps/db.properties");
				InputStream propStream =  
FileLocator.openStream(IbatisCorePlugin.getDefault().getBundle(),  
propPath,
						false);
				Properties properties = new Properties();
				properties.load(propStream);

				sqlMap = SqlMapClientBuilder.buildSqlMapClient(resource,  
properties);
			} catch (Exception e) {
				Status init = new Status(IStatus.ERROR,  
IbatisCorePlugin.PLUGIN_ID, "Could not initialize SqlMaps", e);
				StatusHandler.log(init);
				throw new CoreException(init);
			}
		}
		return sqlMap;
	}

	private TasksSqlMapConfig() {
		super();	// Singleton
	}
}

This will start to parse the XML alright and use the properties as  
replacement. However when it is time to locate the Sqlmap.xml files  
referenced in the SqlMapConfig.xml an error occurs. Eclipse bundles  
all have their own class path so maybe ibatis has problems locating  
the resource.

Is it possible to insert a replacement or additional class loader?
I've tries using Resources.setDefaultClassLoader but this isn't used  
anywhere,  
likecom 
.ibatis.common.resources.Resources.getResourceAsStream(ClassLoader,  
String)

Is this option fully implemented? Is there a tutorial available, I  
have "Ibaqtis in Action" but haven't found anything.


Mime
View raw message