本文整理匯總了Java中org.apache.ibatis.reflection.MetaObject.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java MetaObject.getValue方法的具體用法?Java MetaObject.getValue怎麽用?Java MetaObject.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ibatis.reflection.MetaObject
的用法示例。
在下文中一共展示了MetaObject.getValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: andEqualTo
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* 將此對象的不為空的字段參數作為相等查詢條件
*
* @param param 參數對象
* @author Bob {@link}[email protected]
* @Date 2015年7月17日 下午12:48:08
*/
public Criteria andEqualTo(Object param) {
MetaObject metaObject = SystemMetaObject.forObject(param);
String[] properties = metaObject.getGetterNames();
for (String property : properties) {
//屬性和列對應Map中有此屬性
if (propertyMap.get(property) != null) {
Object value = metaObject.getValue(property);
//屬性值不為空
if (value != null) {
andEqualTo(property, value);
}
}
}
return (Criteria) this;
}
示例2: coalesceResults
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static Object coalesceResults(Configuration configuration, List<Object> valueObjects, String collectionProperty)
{
// Take the first result as the base value
Object resultObject = null;
MetaObject probe = null;
Collection<Object> collection = null;
for (Object object : valueObjects)
{
if (collection == null)
{
resultObject = object;
probe = configuration.newMetaObject(resultObject);
collection = (Collection<Object>) probe.getValue(collectionProperty);
}
else
{
Collection<?> addedValues = (Collection<Object>) probe.getValue(collectionProperty);
collection.addAll(addedValues);
}
}
// Done
return resultObject;
}
示例3: andAllEqualTo
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* 將此對象的所有字段參數作為相等查詢條件,如果字段為 null,則為 is null
*
* @param param 參數對象
*/
public Criteria andAllEqualTo(Object param) {
MetaObject metaObject = SystemMetaObject.forObject(param);
String[] properties = metaObject.getGetterNames();
for (String property : properties) {
//屬性和列對應Map中有此屬性
if (propertyMap.get(property) != null) {
Object value = metaObject.getValue(property);
//屬性值不為空
if (value != null) {
andEqualTo(property, value);
} else {
andIsNull(property);
}
}
}
return (Criteria) this;
}
示例4: intercept
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
// TODO Auto-generated method stub
if (invocation.getTarget() instanceof RoutingStatementHandler) {
StatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
String mapperId = mappedStatement.getId();
String mapperClassName = mapperId.substring(0, mapperId.lastIndexOf("."));
Class<?> mapperClass = Class.forName(mapperClassName);
if (isDaoMapper(mapperClass)&&mapperId.endsWith(".insertUseReturnGeneratedKeys")) {
BaseStatementHandler baseStatementHandler = (BaseStatementHandler) metaStatementHandler.getValue("delegate");
if ("query".equals(invocation.getMethod().getName())) {
return handPreparedStatementHandlerQuery(invocation, baseStatementHandler);
} else if ("prepare".equals(invocation.getMethod().getName())) {
return handPreparedStatementHandlerPrepare(invocation, baseStatementHandler);
}
}
}
return invocation.proceed();
}
示例5: handleLocallyCachedOutputParameters
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) {
if (ms.getStatementType() == StatementType.CALLABLE) {
final Object cachedParameter = localOutputParameterCache.getObject(key);
if (cachedParameter != null && parameter != null) {
final MetaObject metaCachedParameter = configuration.newMetaObject(cachedParameter);
final MetaObject metaParameter = configuration.newMetaObject(parameter);
for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
if (parameterMapping.getMode() != ParameterMode.IN) {
final String parameterName = parameterMapping.getProperty();
final Object cachedValue = metaCachedParameter.getValue(parameterName);
metaParameter.setValue(parameterName, cachedValue);
}
}
}
}
}
示例6: instantiateCollectionPropertyIfAppropriate
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private Object instantiateCollectionPropertyIfAppropriate(ResultMapping resultMapping, MetaObject metaObject) {
final String propertyName = resultMapping.getProperty();
Object propertyValue = metaObject.getValue(propertyName);
if (propertyValue == null) {
Class<?> type = resultMapping.getJavaType();
if (type == null) {
type = metaObject.getSetterType(propertyName);
}
try {
if (objectFactory.isCollection(type)) {
propertyValue = objectFactory.create(type);
metaObject.setValue(propertyName, propertyValue);
return propertyValue;
}
} catch (Exception e) {
throw new ExecutorException("Error instantiating collection property for result '" + resultMapping.getProperty() + "'. Cause: " + e, e);
}
} else if (objectFactory.isCollection(propertyValue.getClass())) {
return propertyValue;
}
return null;
}
示例7: populateKeys
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* <p>
* 自定義元對象填充控製器
* </p>
*
* @param metaObjectHandler 元數據填充處理器
* @param tableInfo 數據庫表反射信息
* @param ms MappedStatement
* @param parameterObject 插入數據庫對象
* @return Object
*/
protected static Object populateKeys(MetaObjectHandler metaObjectHandler, TableInfo tableInfo,
MappedStatement ms, Object parameterObject) {
if (null == tableInfo || StringUtils.isEmpty(tableInfo.getKeyProperty()) || null == tableInfo.getIdType()) {
/* 不處理 */
return parameterObject;
}
/* 自定義元對象填充控製器 */
MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject);
if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
if (IdType.ID_WORKER.equals(tableInfo.getIdType()) || IdType.UUID.equals(tableInfo.getIdType())) {
Object idValue = metaObject.getValue(tableInfo.getKeyProperty());
/* 自定義 ID */
if (StringUtils.checkValNull(idValue)) {
if (IdType.ID_WORKER.equals(tableInfo.getIdType())) {
metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId());
} else if (IdType.UUID.equals(tableInfo.getIdType())) {
metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.get32UUID());
}
}
}
// 插入填充
if (metaObjectHandler.openInsertFill()) {
metaObjectHandler.insertFill(metaObject);
}
} else if (ms.getSqlCommandType() == SqlCommandType.UPDATE && metaObjectHandler.openUpdateFill()) {
// 更新填充
metaObjectHandler.updateFill(metaObject);
}
return metaObject.getOriginalObject();
}
示例8: intercept
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* Physical Pagination Interceptor for all the queries with parameter {@link org.apache.ibatis.session.RowBounds}
*/
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
// 先判斷是不是SELECT操作
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
return invocation.proceed();
}
RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
/* 不需要分頁的場合 */
if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
return invocation.proceed();
}
BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
String originalSql = boundSql.getSql();
Connection connection = (Connection) invocation.getArgs()[0];
DBType dbType = JdbcUtils.getDbType(connection.getMetaData().getURL());
if (rowBounds instanceof Pagination) {
Pagination page = (Pagination) rowBounds;
if (page.isSearchCount()) {
this.queryTotal(JsqlParserUtils.jsqlparserCount(originalSql), mappedStatement, boundSql, page, connection);
if (page.getTotal() <= 0) {
return invocation.proceed();
}
}
originalSql = DialectFactory.buildPaginationSql(page, originalSql, dbType, null);
} else {
// support physical Pagination for RowBounds
originalSql = DialectFactory.buildPaginationSql(rowBounds, originalSql, dbType, null);
}
/*
* <p> 禁用內存分頁 </p> <p> 內存分頁會查詢所有結果出來處理(這個很嚇人的),如果結果變化頻繁這個數據還會不準。</p>
*/
metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}
示例9: setParameters
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
public void setParameters(PreparedStatement ps) throws SQLException {
ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings != null) {
MetaObject metaObject = parameterObject == null ? null : configuration.newMetaObject(parameterObject);
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) { // issue #448 ask first for additional params
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
value = parameterObject;
} else {
value = metaObject == null ? null : metaObject.getValue(propertyName);
}
TypeHandler typeHandler = parameterMapping.getTypeHandler();
if (typeHandler == null) {
throw new ExecutorException("There was no TypeHandler found for parameter " + propertyName + " of statement " + mappedStatement.getId());
}
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) jdbcType = configuration.getJdbcTypeForNull();
typeHandler.setParameter(ps, i + 1, value, jdbcType);
}
}
}
}
示例10: findTargetObject
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
public static MetaObject findTargetObject(Invocation invocation) {
MetaObject metaObject = MetaObject.forObject(invocation.getTarget(), OBJECT_FACTORY, OBJECT_WRAPPER_FACTORY);
while (metaObject.hasGetter(HANDLER_FIELD)) {
Object o = metaObject.getValue(HANDLER_FIELD);
metaObject = MetaObject.forObject(o, OBJECT_FACTORY, OBJECT_WRAPPER_FACTORY);
if (metaObject.hasGetter(TARGET_FIELD)) {
o = metaObject.getValue(TARGET_FIELD);
metaObject = MetaObject.forObject(o, OBJECT_FACTORY, OBJECT_WRAPPER_FACTORY);
}
}
return metaObject;
}
示例11: getKeyValues
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* @return Returns the values for the {@link RollupResultHandler#keyProperties}
*/
private Object[] getKeyValues(MetaObject probe)
{
Object[] keyValues = new Object[keyProperties.length];
for (int i = 0; i < keyProperties.length; i++)
{
keyValues[i] = probe.getValue(keyProperties[i]);
}
return keyValues;
}
示例12: setValue
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private void setValue(MetaObject metaParam, String property, Object value) {
if (metaParam.hasSetter(property)) {
if(metaParam.hasGetter(property)){
Object defaultValue = metaParam.getValue(property);
if(defaultValue != null){
return;
}
}
metaParam.setValue(property, value);
} else {
throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClass().getName() + ".");
}
}
示例13: getParamValue
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* 從對象中取參數
*
* @param paramsObject
* @param paramName
* @param required
* @return
*/
public static Object getParamValue(MetaObject paramsObject, String paramName, boolean required) {
Object value = null;
if (paramsObject.hasGetter(PARAMS.get(paramName))) {
value = paramsObject.getValue(PARAMS.get(paramName));
}
if (required && value == null) {
throw new RuntimeException("分頁查詢缺少必要的參數:" + PARAMS.get(paramName));
}
return value;
}
示例14: getMapperSql
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* 通過接口獲取sql
* @param mapper
* @param methodName
* @param args
* @return
*/
public static String getMapperSql(Object mapper, String methodName, Object... args) {
MetaObject metaObject = SystemMetaObject.forObject(mapper);
SqlSession session = (SqlSession) metaObject.getValue("h.sqlSession");
Class mapperInterface = (Class) metaObject.getValue("h.mapperInterface");
String fullMethodName = mapperInterface.getCanonicalName() + "." + methodName;
if (args == null || args.length == 0) {
return getNamespaceSql(session, fullMethodName, null);
} else {
return getMapperSql(session, mapperInterface, methodName, args);
}
}
示例15: getNamespaceSql
import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
* 通過命名空間方式獲取sql
* @param session
* @param namespace
* @param params
* @return
*/
public static String getNamespaceSql(SqlSession session, String namespace, Object params) {
Configuration configuration = session.getConfiguration();
MappedStatement mappedStatement = configuration.getMappedStatement(namespace);
TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
BoundSql boundSql = mappedStatement.getBoundSql(params);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
String sql = boundSql.getSql();
if (parameterMappings != null) {
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (params == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(params.getClass())) {
value = params;
} else {
MetaObject metaObject = configuration.newMetaObject(params);
value = metaObject.getValue(propertyName);
}
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) jdbcType = configuration.getJdbcTypeForNull();
sql = replaceParameter(sql, value, jdbcType, parameterMapping.getJavaType());
}
}
}
return sql;
}