if (adapter == null)
{
return; // no RDBMS mapping defined for "optional" DataSource, hence no component required
}
final Component component =
new Component(source.getName(), adapter.getClassObject(), Component.CONTEXT);
component.setMetadata(loader.getMetadata());
if (element != null)
{
XMLUtil.withFirstChildElement(element, "SQLHook", false, new ElementHandler()
{
public void handleElement(Element componentElement)
{
Component hook = new Component("<SQLHook:" + source.getName() + ">");
m_loader.loadComponent(componentElement, hook);
component.addComponentPropertyInitializer("SQLHook", hook);
}
});
}
db.setComponent(component);
if (adapter.getVersion() != null)
{
component.addPrimitivePropertyInitializer("version", adapter.getVersion());
}
if (!db.isUnicode())
{
component.addPrimitivePropertyInitializer("unicode", Boolean.FALSE);
}
if (db.isLiteral())
{
component.addPrimitivePropertyInitializer("literal", Boolean.TRUE);
}
if (!loader.isEnvironmentOnly() && !loader.isValidatedOnly())
{
loader.addEnvironmentFixup(new ContextFixup(loader.getHelper())
{
public void fixup()
{
Component cf = null;
for (Iterator fragmentItr = db.getFragmentIterator(); fragmentItr.hasNext();)
{
RelationalDatabaseFragment fragment = (RelationalDatabaseFragment)fragmentItr.next();
if (J2EEUtil.isContained() && db.isEnabled())
{
cf = new Component(source.getName() + ".ConnectionFactory" + fragment.getSuffix(),
loader.getHelper().getClassObject(SysUtil.PACKAGE + ".core.persistence.sql.SQLJNDIConnectionFactory"),
Component.SINGLETON);
cf.addPrimitivePropertyInitializer("dataSource", db.getName() + fragment.getSuffix());
}
else
{
cf = new Component(source.getName() + ".ConnectionFactory" + fragment.getSuffix(),
loader.getHelper().getClassObject(SysUtil.PACKAGE + ".core.persistence.sql.SQLRAConnectionFactory"),
Component.SINGLETON);
SQLAdapter adapterInstance = (SQLAdapter)component.getInstance(null);
cf.addPrimitivePropertyInitializer("fragment", fragment);
cf.addPrimitivePropertyInitializer("initialSQL", adapterInstance.getInitialSQL());
cf.addPrimitivePropertyInitializer("testSQL", adapterInstance.getTestSQL());
}
cf.setMetadata(loader.getMetadata());
fragment.setConnectionFactory(cf);
loader.addSingletonFixup(cf);
}
if (db.getFragmentCount() > 1)
{
cf = new Component(source.getName() + ".FragmentConnectionFactory",
loader.getHelper().getClassObject(SysUtil.PACKAGE + ".core.persistence.sql.SQLFragmentConnectionFactory"),
Component.SINGLETON);
cf.setMetadata(loader.getMetadata());
cf.addPrimitivePropertyInitializer("database", db);
component.addPrimitivePropertyInitializer("fragmented", Boolean.TRUE);
}
component.addComponentPropertyInitializer("connectionFactory", cf);
}