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


Java MetaObject.setValue方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: intercept

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
	StatementHandler statementHandler = (StatementHandler) invocation.getTarget(); 
	if(statementHandler instanceof RoutingStatementHandler){
		RoutingStatementHandler routeStatementHandler = (RoutingStatementHandler)statementHandler;
		MetaObject metaObject = SystemMetaObject.forObject(routeStatementHandler);
		int offset = Integer.valueOf(String.valueOf(metaObject.getValue("delegate.rowBounds.offset")));
		int limit = Integer.valueOf(String.valueOf(metaObject.getValue("delegate.rowBounds.limit")));
		if(offset == RowBounds.NO_ROW_OFFSET && limit == RowBounds.NO_ROW_LIMIT){
			return invocation.proceed();
		}
		String sql = String.valueOf(metaObject.getValue("delegate.boundSql.sql")).trim();
		if(StringUtils.isBlank(sql) || !sql.toLowerCase().startsWith("select")){
			return invocation.proceed();
		}
		String pagedSql = this.buildPagedSql(sql, offset, limit);
		metaObject.setValue("delegate.boundSql.sql", pagedSql);
		metaObject.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
		metaObject.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
	}else{
		return invocation.proceed(); 
	}
	return invocation.proceed();
}
 
開發者ID:ls960972314,項目名稱:report,代碼行數:25,代碼來源:MybatisPagedInterceptor.java

示例4: applyAutomaticMappings

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap, MetaObject metaObject, String columnPrefix) throws SQLException {
  List<UnMappedColumnAutoMapping> autoMapping = createAutomaticMappings(rsw, resultMap, metaObject, columnPrefix);
  boolean foundValues = false;
  if (autoMapping.size() > 0) {
    for (UnMappedColumnAutoMapping mapping : autoMapping) {
      final Object value = mapping.typeHandler.getResult(rsw.getResultSet(), mapping.column);
      if (value != null) {
        foundValues = true;
      }
      if (value != null || (configuration.isCallSettersOnNulls() && !mapping.primitive)) {
        // gcode issue #377, call setter on nulls (value is not 'found')
        metaObject.setValue(mapping.property, value);
      }
    }
  }
  return foundValues;
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:18,代碼來源:DefaultResultSetHandler.java

示例5: prepareCompositeKeyParameter

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private Object prepareCompositeKeyParameter(ResultSet rs, ResultMapping resultMapping, Class<?> parameterType, String columnPrefix) throws SQLException {
  final Object parameterObject = instantiateParameterObject(parameterType);
  final MetaObject metaObject = configuration.newMetaObject(parameterObject);
  boolean foundValues = false;
  for (ResultMapping innerResultMapping : resultMapping.getComposites()) {
    final Class<?> propType = metaObject.getSetterType(innerResultMapping.getProperty());
    final TypeHandler<?> typeHandler = typeHandlerRegistry.getTypeHandler(propType);
    final Object propValue = typeHandler.getResult(rs, prependPrefix(innerResultMapping.getColumn(), columnPrefix));
    // issue #353 & #560 do not execute nested query if key is null
    if (propValue != null) {
      metaObject.setValue(innerResultMapping.getProperty(), propValue);
      foundValues = true;
    }
  }
  return foundValues ? parameterObject : null;
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:17,代碼來源:DefaultResultSetHandler.java

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

示例7: applyAutomaticMappings

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap, MetaObject metaObject, String columnPrefix) throws SQLException {
  List<UnMappedColumnAutoMapping> autoMapping = createAutomaticMappings(rsw, resultMap, metaObject, columnPrefix);
  boolean foundValues = false;
  if (autoMapping.size() > 0) {
    for (UnMappedColumnAutoMapping mapping : autoMapping) {
      final Object value = mapping.typeHandler.getResult(rsw.getResultSet(), mapping.column);
      // issue #377, call setter on nulls
      if (value != null || configuration.isCallSettersOnNulls()) {
        if (value != null || !mapping.primitive) {
          metaObject.setValue(mapping.property, value);
        }
        foundValues = true;
      }
    }
  }
  return foundValues;
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:18,代碼來源:DefaultResultSetHandler.java

示例8: 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();
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:42,代碼來源:MybatisDefaultParameterHandler.java

示例9: 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();
  }
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:43,代碼來源:PaginationInterceptor.java

示例10: insertFill

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
     * 測試 user 表 name 字段為空自動填充
     */
    public void insertFill(MetaObject metaObject) {
//		Object name = metaObject.getValue("name");
//		if (null == name) {
//			metaObject.setValue("name", "instert-fill");
//		}

        // 測試下劃線
        Object testType = metaObject.getValue("testType");
        System.err.println("testType==" + testType);
        if (null == testType) {
            metaObject.setValue("testType", 3);
        }
    }
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:17,代碼來源:MyMetaObjectHandler.java

示例11: setResultType

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
 * 設置返回值類型 - 為了讓typeHandler在select時有效,改為設置resultMap
 *
 * @param ms
 * @param entityClass
 */
protected void setResultType(MappedStatement ms, Class<?> entityClass) {
    EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    resultMaps.add(entityTable.getResultMap(ms.getConfiguration()));
    MetaObject metaObject = SystemMetaObject.forObject(ms);
    metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps));
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:14,代碼來源:MapperTemplate.java

示例12: setSqlSource

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
 * 重新設置SqlSource,同時判斷如果是Jdbc3KeyGenerator,就設置為MultipleJdbc3KeyGenerator
 *
 * @param ms
 * @param sqlSource
 */
protected void setSqlSource(MappedStatement ms, SqlSource sqlSource) {
    MetaObject msObject = SystemMetaObject.forObject(ms);
    msObject.setValue("sqlSource", sqlSource);
    //如果是Jdbc3KeyGenerator,就設置為MultipleJdbc3KeyGenerator
    KeyGenerator keyGenerator = ms.getKeyGenerator();
    if (keyGenerator instanceof Jdbc3KeyGenerator) {
        msObject.setValue("keyGenerator", new MultipleJdbc3KeyGenerator());
    }
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:16,代碼來源:MapperTemplate.java

示例13: populateKeys

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
private void populateKeys(ResultSet rs, MetaObject metaParam, String[] keyProperties, TypeHandler<?>[] typeHandlers) throws SQLException {
    for (int i = 0; i < keyProperties.length; i++) {
        TypeHandler<?> th = typeHandlers[i];
        if (th != null) {
            Object value = th.getResult(rs, i + 1);
            metaParam.setValue(keyProperties[i], value);
        }
    }
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:10,代碼來源:MultipleJdbc3KeyGenerator.java

示例14: 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() + ".");
    }
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:14,代碼來源:SelectKeyGenerator.java

示例15: setResultType

import org.apache.ibatis.reflection.MetaObject; //導入方法依賴的package包/類
/**
 * 設置返回值類型
 *
 * @param ms
 * @param entityClass
 */
private static void setResultType(Configuration configuration, MappedStatement ms, Class<?> entityClass) {
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    resultMaps.add(getResultMap(configuration, entityClass));
    MetaObject metaObject = SystemMetaObject.forObject(ms);
    metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps));
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:13,代碼來源:GetByPrimaryKeyBuilder.java


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