Method from com.ibatis.sqlmap.engine.mapping.result.BasicResultMap Detail: |
public void addGroupByProperty(String name) {
if (groupByProps == null) {
groupByProps = new HashSet();
}
groupByProps.add(name);
}
|
public void addNestedResultMappings(ResultMapping mapping) {
if (nestedResultMappings == null) {
nestedResultMappings = new ArrayList();
}
nestedResultMappings.add(mapping);
}
|
public DataExchange getDataExchange() {
return dataExchange;
}
Getter for the DataExchange object to be used |
public SqlMapExecutorDelegate getDelegate() {
return delegate;
}
Getter for the SqlMapExecutorDelegate |
public Discriminator getDiscriminator() {
return discriminator;
}
|
public String getId() {
return id;
}
|
protected Object getNestedSelectMappingValue(RequestScope request,
ResultSet rs,
BasicResultMapping mapping,
Class targetType) throws SQLException {
try {
TypeHandlerFactory typeHandlerFactory = getDelegate().getTypeHandlerFactory();
String statementName = mapping.getStatementName();
ExtendedSqlMapClient client = (ExtendedSqlMapClient) request.getSession().getSqlMapClient();
MappedStatement mappedStatement = client.getMappedStatement(statementName);
Class parameterType = mappedStatement.getParameterClass();
Object parameterObject = null;
if (parameterType == null) {
parameterObject = prepareBeanParameterObject(rs, mapping, parameterType);
} else {
if (typeHandlerFactory.hasTypeHandler(parameterType)) {
parameterObject = preparePrimitiveParameterObject(rs, mapping, parameterType);
} else if (DomTypeMarker.class.isAssignableFrom(parameterType)) {
parameterObject = prepareDomParameterObject(rs, mapping);
} else {
parameterObject = prepareBeanParameterObject(rs, mapping, parameterType);
}
}
Object result = null;
if (parameterObject != null) {
Sql sql = mappedStatement.getSql();
ResultMap resultMap = sql.getResultMap(request, parameterObject);
Class resultClass = resultMap.getResultClass();
if (resultClass != null && !DomTypeMarker.class.isAssignableFrom(targetType)) {
if (DomCollectionTypeMarker.class.isAssignableFrom(resultClass)) {
targetType = DomCollectionTypeMarker.class;
} else if (DomTypeMarker.class.isAssignableFrom(resultClass)) {
targetType = DomTypeMarker.class;
}
}
result = ResultLoader.loadResult(client, statementName, parameterObject, targetType);
String nullValue = mapping.getNullValue();
if (result == null && nullValue != null) {
TypeHandler typeHandler = typeHandlerFactory.getTypeHandler(targetType);
if (typeHandler != null) {
result = typeHandler.valueOf(nullValue);
}
}
}
return result;
} catch (InstantiationException e) {
throw new NestedSQLException("Error setting nested bean property. Cause: " + e, e);
} catch (IllegalAccessException e) {
throw new NestedSQLException("Error setting nested bean property. Cause: " + e, e);
}
}
|
protected Object getPrimitiveResultMappingValue(ResultSet rs,
BasicResultMapping mapping) throws SQLException {
Object value = null;
TypeHandler typeHandler = mapping.getTypeHandler();
if (typeHandler != null) {
String columnName = mapping.getColumnName();
int columnIndex = mapping.getColumnIndex();
String nullValue = mapping.getNullValue();
if (columnName == null) {
value = typeHandler.getResult(rs, columnIndex);
} else {
value = typeHandler.getResult(rs, columnName);
}
if (value == null && nullValue != null) {
value = typeHandler.valueOf(nullValue);
}
} else {
throw new SqlMapException("No type handler could be found to map the property '" + mapping.getPropertyName() + "' to the column '" + mapping.getColumnName() + "'. One or both of the types, or the combination of types is not supported.");
}
return value;
}
|
public String getResource() {
return resource;
}
Getter for the resource (used to report errors) |
public Class getResultClass() {
return resultClass;
}
|
public int getResultCount() {
return this.getResultMappings().length;
}
Getter for the number of ResultMapping objects |
public ResultMapping[] getResultMappings() {
if (allowRemapping) {
return (ResultMapping[]) remappableResultMappings.get();
} else {
return resultMappings;
}
}
|
public Object[] getResults(RequestScope request,
ResultSet rs) throws SQLException {
ErrorContext errorContext = request.getErrorContext();
errorContext.setActivity("applying a result map");
errorContext.setObjectId(this.getId());
errorContext.setResource(this.getResource());
errorContext.setMoreInfo("Check the result map.");
boolean foundData = false;
Object[] columnValues = new Object[getResultMappings().length];
for (int i = 0; i < getResultMappings().length; i++) {
BasicResultMapping mapping = (BasicResultMapping) getResultMappings()[i];
errorContext.setMoreInfo(mapping.getErrorString());
if (mapping.getStatementName() != null) {
if (resultClass == null) {
throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
} else if (Map.class.isAssignableFrom(resultClass)) {
columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, Object.class);
} else if (DomTypeMarker.class.isAssignableFrom(resultClass)) {
Class javaType = mapping.getJavaType();
if (javaType == null) {
javaType = DomTypeMarker.class;
}
columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType);
} else {
Probe p = ProbeFactory.getProbe(resultClass);
Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName());
columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type);
}
} else if (mapping.getNestedResultMapName() == null) {
columnValues[i] = getPrimitiveResultMappingValue(rs, mapping);
}
foundData = foundData || columnValues[i] != null;
}
request.setRowDataFound(foundData);
return columnValues;
}
|
public Object getUniqueKey(Object[] values) {
if (groupByProps != null) {
StringBuffer keyBuffer = new StringBuffer();
for (int i = 0; i < getResultMappings().length; i++) {
String propertyName = getResultMappings()[i].getPropertyName();
if (groupByProps.contains(propertyName)) {
keyBuffer.append(values[i]);
keyBuffer.append('-');
}
}
if (keyBuffer.length() < 1) {
return null;
} else {
return keyBuffer.toString();
}
} else {
return null;
}
}
|
public String getXmlName() {
return xmlName;
}
Getter (used by DomDataExchange) for the xml name of the results |
public ResultMap resolveSubMap(RequestScope request,
ResultSet rs) throws SQLException {
ResultMap subMap = this;
if (discriminator != null) {
BasicResultMapping mapping = (BasicResultMapping)discriminator.getResultMapping();
Object value = getPrimitiveResultMappingValue(rs, mapping);
subMap = discriminator.getSubMap(String.valueOf(value));
if (subMap == null) {
subMap = this;
} else if (subMap != this) {
subMap = subMap.resolveSubMap(request, rs);
}
}
return subMap;
}
|
public void setDataExchange(DataExchange dataExchange) {
this.dataExchange = dataExchange;
}
Setter for the DataExchange object to be used |
public void setDiscriminator(Discriminator discriminator) {
if (this.discriminator != null) {
throw new SqlMapException ("A discriminator may only be set once per result map.");
}
this.discriminator = discriminator;
}
|
public void setId(String id) {
this.id = id;
}
|
protected void setNestedResultMappingValue(BasicResultMapping mapping,
RequestScope request,
Object resultObject,
Object[] values) {
try {
String resultMapName = mapping.getNestedResultMapName();
ResultMap resultMap = getDelegate().getResultMap(resultMapName);
Class type = mapping.getJavaType();
String propertyName = mapping.getPropertyName();
Collection c = (Collection) PROBE.getObject(resultObject, propertyName);
if (c == null) {
if (type == null) {
type = PROBE.getPropertyTypeForSetter(resultObject, propertyName);
}
if (type == Collection.class || type == List.class || type == ArrayList.class) {
c = new ArrayList();
} else if (type == Set.class || type == HashSet.class) {
c = new HashSet();
} else {
try {
c = (Collection) type.newInstance();
} catch (Exception e) {
throw new SqlMapException("Error instantiating collection property for mapping '" + mapping.getPropertyName() + "'. Cause: " + e, e);
}
}
PROBE.setObject(resultObject, propertyName, c);
}
values = resultMap.getResults(request, request.getResultSet());
if (request.isRowDataFound()) {
Object o = resultMap.setResultObjectValues(request, null, values);
if (o != NO_VALUE) {
c.add(o);
}
}
} catch (SQLException e) {
throw new SqlMapException("Error getting nested result map values for '" + mapping.getPropertyName() + "'. Cause: " + e, e);
}
}
|
public void setResource(String resource) {
this.resource = resource;
}
Setter for the resource (used by the SqlMapBuilder) |
public void setResultClass(Class resultClass) {
this.resultClass = resultClass;
}
Setter for the result class (what the results will be mapped into) |
public void setResultMappingList(List resultMappingList) {
if (allowRemapping) {
this.remappableResultMappings.set((BasicResultMapping[]) resultMappingList.toArray(new BasicResultMapping[resultMappingList.size()]));
} else {
this.resultMappings = (BasicResultMapping[]) resultMappingList.toArray(new BasicResultMapping[resultMappingList.size()]);
}
Map props = new HashMap();
props.put("map", this);
dataExchange = getDelegate().getDataExchangeFactory().getDataExchangeForClass(resultClass);
dataExchange.initialize(props);
}
Setter for a list of the individual ResultMapping objects |
public Object setResultObjectValues(RequestScope request,
Object resultObject,
Object[] values) {
Object ukey = getUniqueKey(values);
Map uniqueKeys = request.getUniqueKeys(this);
if (uniqueKeys != null && uniqueKeys.containsKey(ukey)) {
// Unique key is already known, so get the existing result object and process additional results.
resultObject = uniqueKeys.get(ukey);
applyNestedResultMap(request, resultObject, values);
resultObject = NO_VALUE;
} else if (ukey == null || uniqueKeys == null || !uniqueKeys.containsKey(ukey)) {
// Unique key is NOT known, so create a new result object and then process additional results.
resultObject = dataExchange.setData(request, this, resultObject, values);
// Lazy init key set, only if we're grouped by something (i.e. ukey != null)
if (ukey != null) {
if (uniqueKeys == null) {
uniqueKeys = new HashMap();
request.setUniqueKeys(this, uniqueKeys);
}
uniqueKeys.put(ukey, resultObject);
}
applyNestedResultMap(request, resultObject, values);
} else {
// Otherwise, we don't care about these results.
resultObject = NO_VALUE;
}
return resultObject;
}
|
public void setXmlName(String xmlName) {
this.xmlName = xmlName;
}
Setter (used by the SqlMapBuilder) for the xml name of the results |