当前位置: 首页>>代码示例>>Java>>正文


Java SystemMetaObject.forObject方法代码示例

本文整理汇总了Java中org.apache.ibatis.reflection.SystemMetaObject.forObject方法的典型用法代码示例。如果您正苦于以下问题:Java SystemMetaObject.forObject方法的具体用法?Java SystemMetaObject.forObject怎么用?Java SystemMetaObject.forObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.reflection.SystemMetaObject的用法示例。


在下文中一共展示了SystemMetaObject.forObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例2: andEqualTo

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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.SystemMetaObject; //导入方法依赖的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: andAllEqualTo

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例5: intercept

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例6: plugin

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
@Override
public Object plugin(Object target) {
    if (target instanceof StatementHandler) {
        StatementHandler statementHandler = (StatementHandler) target;
        MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
        String sql = statementHandler.getBoundSql().getSql();
        Pager pager = Pager.getAndReset();
        if (pager != null && sql.trim().toLowerCase().startsWith("select")) {
            String newSql = EasyOrmSqlBuilder.getInstance()
                    .getActiveDatabase().getDialect()
                    .doPaging(sql, pager.pageIndex(), pager.pageSize());
            metaStatementHandler.setValue("delegate.boundSql.sql", newSql);
        }
    }
    return Plugin.wrap(target, this);
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:17,代码来源:PagerInterceptor.java

示例7: processMappedStatement

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
/**
 * 修改SqlSource
 *
 * @param ms
 * @throws Throwable
 */
public void processMappedStatement(MappedStatement ms) throws Throwable {
    SqlSource sqlSource = ms.getSqlSource();
    MetaObject msObject = SystemMetaObject.forObject(ms);
    SqlSource pageSqlSource;
    if (sqlSource instanceof StaticSqlSource) {
        pageSqlSource = new PageStaticSqlSource((StaticSqlSource) sqlSource);
    } else if (sqlSource instanceof RawSqlSource) {
        pageSqlSource = new PageRawSqlSource((RawSqlSource) sqlSource);
    } else if (sqlSource instanceof ProviderSqlSource) {
        pageSqlSource = new PageProviderSqlSource((ProviderSqlSource) sqlSource);
    } else if (sqlSource instanceof DynamicSqlSource) {
        pageSqlSource = new PageDynamicSqlSource((DynamicSqlSource) sqlSource);
    } else {
        throw new RuntimeException("无法处理该类型[" + sqlSource.getClass() + "]的SqlSource");
    }
    msObject.setValue("sqlSource", pageSqlSource);
    //由于count查询需要修改返回值,因此这里要创建一个Count查询的MS
    msCountMap.put(ms.getId(), MSUtils.newCountMappedStatement(ms));
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:26,代码来源:SqlUtil.java

示例8: setProperties

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
@Override
public void setProperties(final Properties properties) {
    final Properties driverProperties = new Properties();
    final MetaObject metaDataSource = SystemMetaObject.forObject(dataSource);
    for (final Object key : properties.keySet()) {
        final String propertyName = (String) key;
        if (metaDataSource.hasSetter(propertyName)) {
            final String value = (String) properties.get(propertyName);
            /** 对没有设置值的属性跳过设置 */
            if (StringUtils.isNotEmpty(value) && value.startsWith("${") && value.endsWith("}")) {
                continue;
            }

            final Object convertedValue = convertValue(metaDataSource, propertyName, value);
            metaDataSource.setValue(propertyName, convertedValue);
        } else {
            throw new DataSourceException("Unknown DataSource property: " + propertyName);
        }
    }

    if (driverProperties.size() > 0) {
        metaDataSource.setValue("driverProperties", driverProperties);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:25,代码来源:AbstractDataSourceFactory.java

示例9: orEqualTo

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
/**
 * 将此对象的不为空的字段参数作为相等查询条件
 *
 * @param param 参数对象
 * @author Bob {@link}[email protected]
 * @Date 2015年7月17日 下午12:48:08
 */
public Criteria orEqualTo(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) {
                orEqualTo(property, value);
            }
        }
    }
    return (Criteria) this;
}
 
开发者ID:abel533,项目名称:Mapper,代码行数:23,代码来源:Example.java

示例10: orAllEqualTo

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
/**
 * 将此对象的所有字段参数作为相等查询条件,如果字段为 null,则为 is null
 *
 * @param param 参数对象
 */
public Criteria orAllEqualTo(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) {
                orEqualTo(property, value);
            } else {
                orIsNull(property);
            }
        }
    }
    return (Criteria) this;
}
 
开发者ID:abel533,项目名称:Mapper,代码行数:23,代码来源:Example.java

示例11: realTarget

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的package包/类
/**
 * 获得真正的处理对象,可能多层代理.
 */
public static Object realTarget(Object target) {
    if (Proxy.isProxyClass(target.getClass())) {
        MetaObject metaObject = SystemMetaObject.forObject(target);
        return realTarget(metaObject.getValue("h.target"));
    }
    return target;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:11,代码来源:PluginUtils.java

示例12: intercept

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例13: setResultType

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例14: setSqlSource

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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

示例15: getMapperSql

import org.apache.ibatis.reflection.SystemMetaObject; //导入方法依赖的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);
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:19,代码来源:SqlHelper.java


注:本文中的org.apache.ibatis.reflection.SystemMetaObject.forObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。