package org.jboss.ejb.plugins.cmp.jdbc.metadata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Method;
import org.jboss.deployment.DeploymentException;
import org.jboss.metadata.EntityMetaData;
import org.jboss.metadata.MetaData;
import org.jboss.metadata.QueryMetaData;
import org.jboss.mx.util.MBeanServerLocator;
import org.w3c.dom.Element;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanServer;
public final class JDBCEntityMetaData
{
private final JDBCApplicationMetaData jdbcApplication;
private final String dataSourceName;
private final String datasourceMappingName;
private final JDBCTypeMappingMetaData datasourceMapping;
private final String entityName;
private final String abstractSchemaName;
private final Class entityClass;
private final Class homeClass;
private final Class remoteClass;
private final Class localHomeClass;
private final Class localClass;
private final boolean isCMP1x;
private final String tableName;
private final boolean createTable;
private final boolean removeTable;
private final boolean alterTable;
private final ArrayList tablePostCreateCmd;
private final boolean rowLocking;
private final boolean readOnly;
private final int readTimeOut;
private final boolean primaryKeyConstraint;
private final Class primaryKeyClass;
private final String primaryKeyFieldName;
private final Map cmpFieldsByName = new HashMap();
private final List cmpFields = new ArrayList();
private final Map loadGroups = new HashMap();
private final String eagerLoadGroup;
private final List lazyLoadGroups = new ArrayList();
private final Map queries = new HashMap();
private final JDBCQueryMetaDataFactory queryFactory;
private final JDBCReadAheadMetaData readAhead;
private final boolean cleanReadAheadOnLoad;
private final int listCacheMax;
private final int fetchSize;
private final JDBCEntityCommandMetaData entityCommand;
private final JDBCOptimisticLockingMetaData optimisticLocking;
private final JDBCAuditMetaData audit;
private final Class qlCompiler;
private final boolean throwRuntimeExceptions;
public JDBCEntityMetaData(JDBCApplicationMetaData jdbcApplication,
EntityMetaData entity)
throws DeploymentException
{
this.jdbcApplication = jdbcApplication;
entityName = entity.getEjbName();
listCacheMax = 1000;
fetchSize = 0;
try
{
entityClass = getClassLoader().loadClass(entity.getEjbClass());
}
catch(ClassNotFoundException e)
{
throw new DeploymentException("entity class not found: " + entityName);
}
try
{
primaryKeyClass = getClassLoader().loadClass(entity.getPrimaryKeyClass());
}
catch(ClassNotFoundException e)
{
throw new DeploymentException(
"could not load primary key class: " +
entity.getPrimaryKeyClass()
);
}
isCMP1x = entity.isCMP1x();
if(isCMP1x)
{
abstractSchemaName = (entity.getAbstractSchemaName() == null ? entityName : entity.getAbstractSchemaName());
}
else
{
abstractSchemaName = entity.getAbstractSchemaName();
}
primaryKeyFieldName = entity.getPrimKeyField();
String home = entity.getHome();
if(home != null)
{
try
{
homeClass = getClassLoader().loadClass(home);
}
catch(ClassNotFoundException e)
{
throw new DeploymentException("home class not found: " + home);
}
try
{
remoteClass = getClassLoader().loadClass(entity.getRemote());
}
catch(ClassNotFoundException e)
{
throw new DeploymentException(
"remote class not found: " +
entity.getRemote()
);
}
}
else
{
homeClass = null;
remoteClass = null;
}
String localHome = entity.getLocalHome();
if(localHome != null)
{
try
{
localHomeClass = getClassLoader().loadClass(localHome);
}
catch(ClassNotFoundException e)
{
throw new DeploymentException(
"local home class not found: " +
localHome
);
}
try
{
localClass = getClassLoader().loadClass(entity.getLocal());
}
catch(ClassNotFoundException e)
{
throw new DeploymentException(
"local class not found: " +
entity.getLocal()
);
}
}
else
{
if(home == null)
{
throw new DeploymentException(
"Entity must have atleast a home " +
"or local home: " + entityName
);
}
localHomeClass = null;
localClass = null;
}
tableName = entityName.replace('.', '_');
dataSourceName = null;
datasourceMapping = null;
datasourceMappingName = null;
createTable = false;
removeTable = false;
alterTable = false;
rowLocking = false;
primaryKeyConstraint = false;
readOnly = false;
readTimeOut = -1;
tablePostCreateCmd = null;
qlCompiler = null;
throwRuntimeExceptions = false;
List nonPkFieldNames = new ArrayList();
for(Iterator i = entity.getCMPFields(); i.hasNext();)
{
String cmpFieldName = (String) i.next();
JDBCCMPFieldMetaData cmpField = new JDBCCMPFieldMetaData(this, cmpFieldName);
cmpFields.add(cmpField);
cmpFieldsByName.put(cmpFieldName, cmpField);
if(!cmpField.isPrimaryKeyMember())
{
nonPkFieldNames.add(cmpFieldName);
}
}
if(primaryKeyClass == java.lang.Object.class)
{
JDBCCMPFieldMetaData upkField = new JDBCCMPFieldMetaData(this);
cmpFields.add(upkField);
cmpFieldsByName.put(upkField.getFieldName(), upkField);
}
eagerLoadGroup = "*";
queryFactory = new JDBCQueryMetaDataFactory(this);
for(Iterator queriesIterator = entity.getQueries(); queriesIterator.hasNext();)
{
QueryMetaData queryData = (QueryMetaData) queriesIterator.next();
Map newQueries = queryFactory.createJDBCQueryMetaData(queryData);
queries.putAll(newQueries);
}
readAhead = JDBCReadAheadMetaData.DEFAULT;
cleanReadAheadOnLoad = false;
entityCommand = null;
optimisticLocking = null;
audit = null;
}
public JDBCEntityMetaData(JDBCApplicationMetaData jdbcApplication,
Element element,
JDBCEntityMetaData defaultValues)
throws DeploymentException
{
this.jdbcApplication = jdbcApplication;
entityName = defaultValues.getName();
entityClass = defaultValues.getEntityClass();
primaryKeyClass = defaultValues.getPrimaryKeyClass();
isCMP1x = defaultValues.isCMP1x;
primaryKeyFieldName = defaultValues.getPrimaryKeyFieldName();
homeClass = defaultValues.getHomeClass();
remoteClass = defaultValues.getRemoteClass();
localHomeClass = defaultValues.getLocalHomeClass();
localClass = defaultValues.getLocalClass();
queryFactory = new JDBCQueryMetaDataFactory(this);
if(isCMP1x)
{
abstractSchemaName = (defaultValues.getAbstractSchemaName() == null ?
entityName : defaultValues.getAbstractSchemaName());
}
else
{
abstractSchemaName = defaultValues.getAbstractSchemaName();
}
String dataSourceNameString = MetaData.getOptionalChildContent(element, "datasource");
if(dataSourceNameString != null)
{
dataSourceName = dataSourceNameString;
}
else
{
dataSourceName = defaultValues.getDataSourceName();
}
String datasourceMappingString = MetaData.getOptionalChildContent(element, "datasource-mapping");
if(datasourceMappingString != null)
{
datasourceMappingName = datasourceMappingString;
datasourceMapping = jdbcApplication.getTypeMappingByName(datasourceMappingString);
if(datasourceMapping == null)
{
throw new DeploymentException(
"Error in jbosscmp-jdbc.xml : "
+
"datasource-mapping "
+ datasourceMappingString +
" not found"
);
}
}
else if(defaultValues.datasourceMappingName != null && defaultValues.datasourceMapping != null)
{
datasourceMappingName = null;
datasourceMapping = defaultValues.datasourceMapping;
}
else
{
datasourceMappingName = null;
datasourceMapping = obtainTypeMappingFromLibrary(dataSourceName);
}
String tableStr = MetaData.getOptionalChildContent(element, "table-name");
if(tableStr != null)
{
tableName = tableStr;
}
else
{
tableName = defaultValues.getDefaultTableName();
}
String createStr = MetaData.getOptionalChildContent(element, "create-table");
if(createStr != null)
{
createTable = Boolean.valueOf(createStr).booleanValue();
}
else
{
createTable = defaultValues.getCreateTable();
}
String removeStr = MetaData.getOptionalChildContent(element, "remove-table");
if(removeStr != null)
{
removeTable = Boolean.valueOf(removeStr).booleanValue();
}
else
{
removeTable = defaultValues.getRemoveTable();
}
String alterStr = MetaData.getOptionalChildContent(element, "alter-table");
if(alterStr != null)
{
alterTable = Boolean.valueOf(alterStr).booleanValue();
}
else
{
alterTable = defaultValues.getAlterTable();
}
Element posttc = MetaData.getOptionalChild(element, "post-table-create");
if(posttc != null)
{
Iterator it = MetaData.getChildrenByTagName(posttc, "sql-statement");
tablePostCreateCmd = new ArrayList();
while(it.hasNext())
{
Element etmp = (Element) it.next();
tablePostCreateCmd.add(MetaData.getElementContent(etmp));
}
}
else
{
tablePostCreateCmd = defaultValues.getDefaultTablePostCreateCmd();
}
String readOnlyStr = MetaData.getOptionalChildContent(element, "read-only");
if(readOnlyStr != null)
{
readOnly = Boolean.valueOf(readOnlyStr).booleanValue();
}
else
{
readOnly = defaultValues.isReadOnly();
}
String readTimeOutStr = MetaData.getOptionalChildContent(element, "read-time-out");
if(readTimeOutStr != null)
{
try
{
readTimeOut = Integer.parseInt(readTimeOutStr);
}
catch(NumberFormatException e)
{
throw new DeploymentException(
"Invalid number format in " +
"read-time-out '" + readTimeOutStr + "': " + e
);
}
}
else
{
readTimeOut = defaultValues.getReadTimeOut();
}
String sForUpStr = MetaData.getOptionalChildContent(element, "row-locking");
if(sForUpStr != null)
{
rowLocking = !isReadOnly() && (Boolean.valueOf(sForUpStr).booleanValue());
}
else
{
rowLocking = defaultValues.hasRowLocking();
}
String pkStr = MetaData.getOptionalChildContent(element, "pk-constraint");
if(pkStr != null)
{
primaryKeyConstraint = Boolean.valueOf(pkStr).booleanValue();
}
else
{
primaryKeyConstraint = defaultValues.hasPrimaryKeyConstraint();
}
String listCacheMaxStr = MetaData.getOptionalChildContent(element, "list-cache-max");
if(listCacheMaxStr != null)
{
try
{
listCacheMax = Integer.parseInt(listCacheMaxStr);
}
catch(NumberFormatException e)
{
throw new DeploymentException(
"Invalid number format in read-" +
"ahead list-cache-max '" + listCacheMaxStr + "': " + e
);
}
if(listCacheMax < 0)
{
throw new DeploymentException(
"Negative value for read ahead " +
"list-cache-max '" + listCacheMaxStr + "'."
);
}
}
else
{
listCacheMax = defaultValues.getListCacheMax();
}
String fetchSizeStr = MetaData.getOptionalChildContent(element, "fetch-size");
if(fetchSizeStr != null)
{
try
{
fetchSize = Integer.parseInt(fetchSizeStr);
}
catch(NumberFormatException e)
{
throw new DeploymentException(
"Invalid number format in " +
"fetch-size '" + fetchSizeStr + "': " + e
);
}
if(fetchSize < 0)
{
throw new DeploymentException(
"Negative value for fetch size " +
"fetch-size '" + fetchSizeStr + "'."
);
}
}
else
{
fetchSize = defaultValues.getFetchSize();
}
String compiler = MetaData.getOptionalChildContent(element, "ql-compiler");
if(compiler == null)
{
qlCompiler = defaultValues.qlCompiler;
}
else
{
try
{
qlCompiler = GetTCLAction.getContextClassLoader().loadClass(compiler);
}
catch(ClassNotFoundException e)
{
throw new DeploymentException("Failed to load compiler implementation: " + compiler);
}
}
String throwRuntimeExceptionsStr = MetaData.getOptionalChildContent(element, "throw-runtime-exceptions");
if(throwRuntimeExceptionsStr != null)
{
throwRuntimeExceptions = Boolean.valueOf(throwRuntimeExceptionsStr).booleanValue();
}
else
{
throwRuntimeExceptions = defaultValues.getThrowRuntimeExceptions();
}
for(Iterator cmpFieldIterator = defaultValues.cmpFields.iterator();
cmpFieldIterator.hasNext();)
{
JDBCCMPFieldMetaData cmpField = new JDBCCMPFieldMetaData(this, (JDBCCMPFieldMetaData) cmpFieldIterator.next());
cmpFields.add(cmpField);
cmpFieldsByName.put(cmpField.getFieldName(), cmpField);
}
for(Iterator i = MetaData.getChildrenByTagName(element, "cmp-field"); i.hasNext();)
{
Element cmpFieldElement = (Element) i.next();
String fieldName = MetaData.getUniqueChildContent(cmpFieldElement, "field-name");
JDBCCMPFieldMetaData oldCMPField = (JDBCCMPFieldMetaData) cmpFieldsByName.get(fieldName);
if(oldCMPField == null)
{
throw new DeploymentException("CMP field not found : fieldName=" + fieldName);
}
JDBCCMPFieldMetaData cmpFieldMetaData = new JDBCCMPFieldMetaData(
this,
cmpFieldElement,
oldCMPField
);
cmpFieldsByName.put(fieldName, cmpFieldMetaData);
int index = cmpFields.indexOf(oldCMPField);
cmpFields.remove(oldCMPField);
cmpFields.add(index, cmpFieldMetaData);
}
if(primaryKeyClass == java.lang.Object.class)
{
Element upkElement = MetaData.getOptionalChild(element, "unknown-pk");
if(upkElement != null)
{
JDBCCMPFieldMetaData oldUpkField = null;
for(Iterator iter = cmpFields.iterator(); iter.hasNext();)
{
JDBCCMPFieldMetaData cmpField = (JDBCCMPFieldMetaData) iter.next();
if(cmpField.isUnknownPkField())
{
oldUpkField = cmpField;
break;
}
}
if(oldUpkField == null)
{
oldUpkField = new JDBCCMPFieldMetaData(this);
}
JDBCCMPFieldMetaData upkField = new JDBCCMPFieldMetaData(this, upkElement, oldUpkField);
cmpFieldsByName.remove(oldUpkField.getFieldName());
cmpFieldsByName.put(upkField.getFieldName(), upkField);
int oldUpkFieldInd = cmpFields.indexOf(oldUpkField);
cmpFields.remove(oldUpkField);
cmpFields.add(oldUpkFieldInd, upkField);
}
}
loadGroups.putAll(defaultValues.loadGroups);
loadLoadGroupsXml(element);
Element eagerLoadGroupElement = MetaData.getOptionalChild(element, "eager-load-group");
if(eagerLoadGroupElement != null)
{
String eagerLoadGroupTmp = MetaData.getElementContent(eagerLoadGroupElement);
if(eagerLoadGroupTmp != null && eagerLoadGroupTmp.trim().length() == 0)
{
eagerLoadGroupTmp = null;
}
if(eagerLoadGroupTmp != null
&& !eagerLoadGroupTmp.equals("*")
&& !loadGroups.containsKey(eagerLoadGroupTmp))
{
throw new DeploymentException(
"Eager load group not found: " +
"eager-load-group=" + eagerLoadGroupTmp
);
}
eagerLoadGroup = eagerLoadGroupTmp;
}
else
{
eagerLoadGroup = defaultValues.getEagerLoadGroup();
}
lazyLoadGroups.addAll(defaultValues.lazyLoadGroups);
loadLazyLoadGroupsXml(element);
Element readAheadElement = MetaData.getOptionalChild(element, "read-ahead");
if(readAheadElement != null)
{
readAhead = new JDBCReadAheadMetaData(readAheadElement, defaultValues.getReadAhead());
}
else
{
readAhead = defaultValues.readAhead;
}
String value = MetaData.getOptionalChildContent(element, "clean-read-ahead-on-load");
if("true".equalsIgnoreCase(value))
{
cleanReadAheadOnLoad = true;
}
else if("false".equalsIgnoreCase(value))
{
cleanReadAheadOnLoad = false;
}
else if(value == null)
{
cleanReadAheadOnLoad = defaultValues.cleanReadAheadOnLoad;
}
else
{
throw new DeploymentException("Failed to deploy " + entityName +
": allowed values for clean-read-ahead-on-load are true and false but got " + value);
}
Element optimisticLockingEl = MetaData.getOptionalChild(element, "optimistic-locking");
if(optimisticLockingEl != null)
{
optimisticLocking = new JDBCOptimisticLockingMetaData(this, optimisticLockingEl);
}
else
{
optimisticLocking = defaultValues.getOptimisticLocking();
}
Element auditElement = MetaData.getOptionalChild(element, "audit");
if(auditElement != null)
{
audit = new JDBCAuditMetaData(this, auditElement);
}
else
{
audit = defaultValues.getAudit();
}
for(Iterator queriesIterator = defaultValues.queries.values().iterator();
queriesIterator.hasNext();)
{
JDBCQueryMetaData query = JDBCQueryMetaDataFactory.createJDBCQueryMetaData(
(JDBCQueryMetaData) queriesIterator.next(),
readAhead, qlCompiler
);
queries.put(query.getMethod(), query);
}
for(Iterator queriesIterator = MetaData.getChildrenByTagName(element, "query");
queriesIterator.hasNext();)
{
Element queryElement = (Element) queriesIterator.next();
Map newQueries = queryFactory.createJDBCQueryMetaData(
queryElement,
defaultValues.queries,
readAhead
);
queries.putAll(newQueries);
}
Element entityCommandEl = MetaData.getOptionalChild(element, "entity-command");
if(entityCommandEl != null)
{
String entityCommandName = entityCommandEl.getAttribute("name");
JDBCEntityCommandMetaData defaultEntityCommand = defaultValues.getEntityCommand();
if((defaultEntityCommand == null)
|| (!entityCommandName.equals(defaultEntityCommand.getCommandName())))
{
defaultEntityCommand = jdbcApplication.getEntityCommandByName(entityCommandName);
}
if(defaultEntityCommand != null)
{
entityCommand = new JDBCEntityCommandMetaData(entityCommandEl, defaultEntityCommand);
}
else
{
entityCommand = new JDBCEntityCommandMetaData(entityCommandEl);
}
}
else
{
entityCommand = defaultValues.getEntityCommand();
}
}
private void loadLoadGroupsXml(Element element)
throws DeploymentException
{
Element loadGroupsElement = MetaData.getOptionalChild(element, "load-groups");
if(loadGroupsElement == null)
{
return;
}
if(isCMP1x)
{
throw new DeploymentException(
"load-groups are only allowed " +
"for CMP 2.x"
);
}
Iterator groups = MetaData.getChildrenByTagName(loadGroupsElement, "load-group");
while(groups.hasNext())
{
Element groupElement = (Element) groups.next();
String loadGroupName = MetaData.getUniqueChildContent(groupElement, "load-group-name");
if(loadGroups.containsKey(loadGroupName))
{
throw new DeploymentException(
"Load group already defined: " +
" load-group-name=" + loadGroupName
);
}
if(loadGroupName.equals("*"))
{
throw new DeploymentException(
"The * load group is automatically " +
"defined and can't be overriden"
);
}
ArrayList group = new ArrayList();
Iterator fields = MetaData.getChildrenByTagName(groupElement, "field-name");
while(fields.hasNext())
{
String fieldName = MetaData.getElementContent((Element) fields.next());
JDBCCMPFieldMetaData field = getCMPFieldByName(fieldName);
if(field != null && field.isPrimaryKeyMember())
{
throw new DeploymentException(
"Primary key fields can not be"
+
" a member of a load group: "
+
" load-group-name="
+ loadGroupName +
" field-name=" + fieldName
);
}
group.add(fieldName);
}
loadGroups.put(loadGroupName, Collections.unmodifiableList(group));
}
}
private void loadLazyLoadGroupsXml(Element element)
throws DeploymentException
{
Element lazyLoadGroupsElement = MetaData.getOptionalChild(element, "lazy-load-groups");
if(lazyLoadGroupsElement == null)
{
return;
}
if(isCMP1x)
{
throw new DeploymentException("lazy-load-groups is only allowed for CMP 2.x");
}
Iterator loadGroupNames = MetaData.getChildrenByTagName(lazyLoadGroupsElement, "load-group-name");
while(loadGroupNames.hasNext())
{
String loadGroupName = MetaData.getElementContent((Element) loadGroupNames.next());
if(!loadGroupName.equals("*") && !loadGroups.containsKey(loadGroupName))
{
throw new DeploymentException(
"Lazy load group not found: " +
"load-group-name=" + loadGroupName
);
}
lazyLoadGroups.add(loadGroupName);
}
}
public JDBCApplicationMetaData getJDBCApplication()
{
return jdbcApplication;
}
public String getDataSourceName()
{
return dataSourceName;
}
public JDBCTypeMappingMetaData getTypeMapping() throws DeploymentException
{
if(datasourceMapping == null)
{
throw new DeploymentException("type-mapping is not initialized: " + dataSourceName
+ " was not deployed or type-mapping was not configured.");
}
return datasourceMapping;
}
public String getName()
{
return entityName;
}
public String getAbstractSchemaName()
{
return abstractSchemaName;
}
public ClassLoader getClassLoader()
{
return jdbcApplication.getClassLoader();
}
public Class getEntityClass()
{
return entityClass;
}
public Class getHomeClass()
{
return homeClass;
}
public Class getRemoteClass()
{
return remoteClass;
}
public Class getLocalHomeClass()
{
return localHomeClass;
}
public Class getLocalClass()
{
return localClass;
}
public boolean isCMP1x()
{
return isCMP1x;
}
public List getCMPFields()
{
return Collections.unmodifiableList(cmpFields);
}
public String getEagerLoadGroup()
{
return eagerLoadGroup;
}
public List getLazyLoadGroups()
{
return Collections.unmodifiableList(lazyLoadGroups);
}
public Map getLoadGroups()
{
return Collections.unmodifiableMap(loadGroups);
}
public List getLoadGroup(String name) throws DeploymentException
{
List group = (List) loadGroups.get(name);
if(group == null)
{
throw new DeploymentException("Unknown load group: name=" + name);
}
return group;
}
public JDBCOptimisticLockingMetaData getOptimisticLocking()
{
return optimisticLocking;
}
public JDBCAuditMetaData getAudit()
{
return audit;
}
public JDBCCMPFieldMetaData getCMPFieldByName(String name)
{
return (JDBCCMPFieldMetaData) cmpFieldsByName.get(name);
}
public String getDefaultTableName()
{
return tableName;
}
public boolean getCreateTable()
{
return createTable;
}
public boolean getRemoveTable()
{
return removeTable;
}
public boolean getAlterTable()
{
return alterTable;
}
public ArrayList getDefaultTablePostCreateCmd()
{
return tablePostCreateCmd;
}
public boolean hasPrimaryKeyConstraint()
{
return primaryKeyConstraint;
}
public boolean hasRowLocking()
{
return rowLocking;
}
public int getListCacheMax()
{
return listCacheMax;
}
public int getFetchSize()
{
return fetchSize;
}
public Collection getQueries()
{
return Collections.unmodifiableCollection(queries.values());
}
public JDBCQueryMetaData getQueryMetaDataForMethod(Method method)
{
return (JDBCQueryMetaData) queries.get(method);
}
public Collection getRelationshipRoles()
{
return jdbcApplication.getRolesForEntity(entityName);
}
public Class getPrimaryKeyClass()
{
return primaryKeyClass;
}
public JDBCEntityCommandMetaData getEntityCommand()
{
return entityCommand;
}
public boolean isReadOnly()
{
return readOnly;
}
public int getReadTimeOut()
{
return readTimeOut;
}
public String getPrimaryKeyFieldName()
{
return primaryKeyFieldName;
}
public JDBCReadAheadMetaData getReadAhead()
{
return readAhead;
}
public Class getQLCompiler()
{
return qlCompiler;
}
public boolean isThrowRuntimeExceptions()
{
return throwRuntimeExceptions;
}
public boolean getThrowRuntimeExceptions()
{
return throwRuntimeExceptions;
}
public boolean isCleanReadAheadOnLoad()
{
return cleanReadAheadOnLoad;
}
public static JDBCTypeMappingMetaData obtainTypeMappingFromLibrary(String dataSourceName)
throws DeploymentException
{
JDBCTypeMappingMetaData typeMapping = null;
String datasource;
if(dataSourceName.startsWith("java:"))
{
datasource = dataSourceName.substring("java:".length());
if(datasource.startsWith("/"));
{
datasource = datasource.substring(1);
}
}
else
{
datasource = dataSourceName;
}
final ObjectName metadataService;
final String str = "jboss.jdbc:service=metadata,datasource=" + datasource;
try
{
metadataService = new ObjectName(str);
}
catch(MalformedObjectNameException e)
{
throw new DeploymentException("Failed to create ObjectName for datasource metadata MBean: " + str, e);
}
try
{
final MBeanServer server = MBeanServerLocator.locateJBoss();
if(server.isRegistered(metadataService))
{
typeMapping = (JDBCTypeMappingMetaData)server.getAttribute(metadataService, "TypeMappingMetaData");
}
}
catch(Exception e)
{
throw new DeploymentException("Failed to obtain type-mapping metadata from the metadata library MBean: " +
e.getMessage(), e);
}
return typeMapping;
}
public boolean equals(Object o)
{
if(o instanceof JDBCEntityMetaData)
{
JDBCEntityMetaData entity = (JDBCEntityMetaData) o;
return entityName.equals(entity.entityName) &&
jdbcApplication.equals(entity.jdbcApplication);
}
return false;
}
public int hashCode()
{
int result = 17;
result = 37 * result + jdbcApplication.hashCode();
result = 37 * result + entityName.hashCode();
return result;
}
public String toString()
{
return "[JDBCEntityMetaData : entityName=" + entityName + "]";
}
}