本文整理汇总了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;
}