當前位置: 首頁>>代碼示例>>Java>>正文


Java MetaObject類代碼示例

本文整理匯總了Java中org.apache.ibatis.reflection.MetaObject的典型用法代碼示例。如果您正苦於以下問題:Java MetaObject類的具體用法?Java MetaObject怎麽用?Java MetaObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MetaObject類屬於org.apache.ibatis.reflection包,在下文中一共展示了MetaObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: intercept

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
    if (!statementTracer.isTraceEnabled()) {
        return invocation.proceed();
    }
    MetaObject metaObject = MetaObjectUtils.findTargetObject(invocation);
    BoundSql boundSql = MetaObjectUtils.getBoundSql(metaObject);
    Configuration configuration = MetaObjectUtils.getConfiguration(metaObject);
    Exception queryException = null;
    try {
        beginTrace(boundSql.getSql(), configuration.getEnvironment());
        return invocation.proceed();
    } catch (Exception ex) {
        queryException = ex;
        throw ex;
    } finally {
        statementTracer.endTrace(0, queryException);
    }
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:20,代碼來源:MybatisTracingInterceptor.java

示例2: 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;
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:23,代碼來源:Example.java

示例3: checkCache

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
/**
 * 檢查是否配置過緩存
 *
 * @param ms
 * @throws Exception
 */
private void checkCache(MappedStatement ms) throws Exception {
    if (ms.getCache() == null) {
        String nameSpace = ms.getId().substring(0, ms.getId().lastIndexOf("."));
        Cache cache;
        try {
            //不存在的時候會拋出異常
            cache = ms.getConfiguration().getCache(nameSpace);
        } catch (IllegalArgumentException e) {
            return;
        }
        if (cache != null) {
            MetaObject metaObject = SystemMetaObject.forObject(ms);
            metaObject.setValue("cache", cache);
        }
    }
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:23,代碼來源:MapperTemplate.java

示例4: 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;
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:25,代碼來源:RollupResultHandler.java

示例5: 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;
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:23,代碼來源:Example.java

示例6: handleMultipleProperties

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
private void handleMultipleProperties(String[] keyProperties,
                                      MetaObject metaParam, MetaObject metaResult) {
    String[] keyColumns = keyStatement.getKeyColumns();

    if (keyColumns == null || keyColumns.length == 0) {
        // no key columns specified, just use the property names
        for (String keyProperty : keyProperties) {
            setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
        }
    } else {
        if (keyColumns.length != keyProperties.length) {
            throw new ExecutorException("If SelectKey has key columns, the number must match the number of key properties.");
        }
        for (int i = 0; i < keyProperties.length; i++) {
            setValue(metaParam, keyProperties[i], metaResult.getValue(keyColumns[i]));
        }
    }
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:19,代碼來源:SelectKeyGenerator.java

示例7: 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();
}
 
開發者ID:wulizhong,項目名稱:mybatis-dao,代碼行數:22,代碼來源:DaoPlugin.java

示例8: getSetterType

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public Class<?> getSetterType(String name) {
  PropertyTokenizer prop = new PropertyTokenizer(name);
  if (prop.hasNext()) {
    MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
    if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
      return Object.class;
    } else {
      return metaValue.getSetterType(prop.getChildren());
    }
  } else {
    if (map.get(name) != null) {
      return map.get(name).getClass();
    } else {
      return Object.class;
    }
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:MapWrapper.java

示例9: getGetterType

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public Class<?> getGetterType(String name) {
  PropertyTokenizer prop = new PropertyTokenizer(name);
  if (prop.hasNext()) {
    MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
    if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
      return Object.class;
    } else {
      return metaValue.getGetterType(prop.getChildren());
    }
  } else {
    if (map.get(name) != null) {
      return map.get(name).getClass();
    } else {
      return Object.class;
    }
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:MapWrapper.java

示例10: hasGetter

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public boolean hasGetter(String name) {
  PropertyTokenizer prop = new PropertyTokenizer(name);
  if (prop.hasNext()) {
    if (map.containsKey(prop.getIndexedName())) {
      MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
      if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
        return true;
      } else {
        return metaValue.hasGetter(prop.getChildren());
      }
    } else {
      return false;
    }
  } else {
    return map.containsKey(prop.getName());
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:MapWrapper.java

示例11: hasGetter

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
public boolean hasGetter(String name) {
	PropertyTokenizer prop = new PropertyTokenizer(name);
	if (prop.hasNext()) {
		if (map.containsKey(prop.getIndexedName())) {
			MetaObject metaValue = metaObject.metaObjectForProperty(prop
					.getIndexedName());
			if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
				return true;
			} else {
				return metaValue.hasGetter(prop.getChildren());
			}
		} else {
			return false;
		}
	} else {
		return map.containsKey(prop.getName());
	}
}
 
開發者ID:yinshipeng,項目名稱:sosoapi-base,代碼行數:19,代碼來源:MapWrapper.java

示例12: hasSetter

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public boolean hasSetter(String name) {
  PropertyTokenizer prop = new PropertyTokenizer(name);
  if (prop.hasNext()) {
    if (metaClass.hasSetter(prop.getIndexedName())) {
      MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
      if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
        return metaClass.hasSetter(name);
      } else {
        return metaValue.hasSetter(prop.getChildren());
      }
    } else {
      return false;
    }
  } else {
    return metaClass.hasSetter(name);
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:BeanWrapper.java

示例13: hasGetter

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public boolean hasGetter(String name) {
  PropertyTokenizer prop = new PropertyTokenizer(name);
  if (prop.hasNext()) {
    if (metaClass.hasGetter(prop.getIndexedName())) {
      MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
      if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
        return metaClass.hasGetter(name);
      } else {
        return metaValue.hasGetter(prop.getChildren());
      }
    } else {
      return false;
    }
  } else {
    return metaClass.hasGetter(name);
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:BeanWrapper.java

示例14: 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);
        }
      }
    }
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:17,代碼來源:BaseExecutor.java

示例15: handleOutputParameters

import org.apache.ibatis.reflection.MetaObject; //導入依賴的package包/類
@Override
public void handleOutputParameters(CallableStatement cs) throws SQLException {
  final Object parameterObject = parameterHandler.getParameterObject();
  final MetaObject metaParam = configuration.newMetaObject(parameterObject);
  final List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
  for (int i = 0; i < parameterMappings.size(); i++) {
    final ParameterMapping parameterMapping = parameterMappings.get(i);
    if (parameterMapping.getMode() == ParameterMode.OUT || parameterMapping.getMode() == ParameterMode.INOUT) {
      if (ResultSet.class.equals(parameterMapping.getJavaType())) {
        handleRefCursorOutputParameter((ResultSet) cs.getObject(i + 1), parameterMapping, metaParam);
      } else {
        final TypeHandler<?> typeHandler = parameterMapping.getTypeHandler();
        metaParam.setValue(parameterMapping.getProperty(), typeHandler.getResult(cs, i + 1));
      }
    }
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:18,代碼來源:DefaultResultSetHandler.java


注:本文中的org.apache.ibatis.reflection.MetaObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。