本文整理汇总了Java中org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultObjectWrapperFactory类的具体用法?Java DefaultObjectWrapperFactory怎么用?Java DefaultObjectWrapperFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultObjectWrapperFactory类属于org.apache.ibatis.reflection.wrapper包,在下文中一共展示了DefaultObjectWrapperFactory类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
BoundSql boundSql = statementHandler.getBoundSql();
MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
if ((rowBounds != null) && (rowBounds != RowBounds.DEFAULT)) {
Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
Dialect dialect = DialectParser.parse(configuration);
String sql = (String) metaStatementHandler.getValue("delegate.boundSql.sql");
sql = dialect.addLimitString(sql, rowBounds.getOffset(), rowBounds.getLimit());
metaStatementHandler.setValue("delegate.boundSql.sql", sql);
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
}
log.debug("SQL : " + boundSql.getSql());
return invocation.proceed();
}
示例2: intercept
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
List<Sort> sortList = getSortList();
if (sortList == null || sortList.size() == 0) {
return invocation.proceed();
}
Executor executor = (Executor) invocation.getTarget();
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object parameter = args[1];
RowBounds rowBounds = (RowBounds) args[2];
ResultHandler resultHandler = (ResultHandler) args[3];
// 计算修改BoundSql
BoundSql boundSql = ms.getBoundSql(parameter);
MetaObject boundSqlHandler = MetaObject.forObject(boundSql, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
Dialect dialect = DialectParser.parse(ms.getConfiguration());
String sql = (String) boundSqlHandler.getValue("sql");
sql = dialect.addSortString(sql, sortList);
boundSqlHandler.setValue("sql", sql);
// 继续执行原来的代码
CacheKey key = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
return executor.query(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
示例3: QueryInformation
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; //导入依赖的package包/类
/**
* コンストラクタです。
* MyBatisの{@link StatementHandler}の解析に失敗した場合に{@link InternalException}をスローします。
* @param statementHandler {@link StatementHandler}
*/
public QueryInformation(StatementHandler statementHandler) {
try {
this.typeHandlerRegistry = new TypeHandlerRegistry();
this.statementHandler = getConcreteStatementHandler(statementHandler);
this.mappedStatement = getMappedStatement(this.statementHandler);
this.boundSql = this.statementHandler.getBoundSql();
this.parameterObject = this.boundSql.getParameterObject();
this.parameterMappingList = boundSql.getParameterMappings();
this.sqlCommandType = mappedStatement.getSqlCommandType();
this.statementType = mappedStatement.getStatementType();
this.metaObject = parameterObject == null ? null : MetaObject.forObject(parameterObject, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
switch (statementType) {
case STATEMENT:
this.query = boundSql.getSql();
break;
case PREPARED:
this.preparedQuery = boundSql.getSql();
break;
case CALLABLE:
this.callableQuery = boundSql.getSql();
break;
default:
throw new InternalException(QueryInformation.class, "");
}
} catch (Exception e) {
throw new InternalException(QueryInformation.class, "E-JDBC-MYBATIS#0002", e);
}
}
示例4: intercept
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; //导入依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler)invocation.getTarget();
MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
RowBounds rowBounds = (RowBounds)metaStatementHandler.getValue("delegate.rowBounds");
if(rowBounds == null || rowBounds == RowBounds.DEFAULT){
return invocation.proceed();
}
if(dialect == null){
Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
Dialect.Type databaseType = null;
String d = configuration.getVariables().getProperty("dialect");
if(d == null || d.trim().equals("")){
throw new IllegalStateException("No property named with 'dialect' defined in mybatis configuration xml file.");
}
try {
databaseType = Dialect.Type.valueOf(d);
} catch (Exception e) {
throw new IllegalStateException(String.format("No such dialect enum defined in class %s.", Dialect.Type.class));
}
switch (databaseType) {
case MYSQL: // MySQL分页
dialect = new MySQLDialect();
break;
case ORACLE: // Oracle分页
dialect = new OracleDialect();
break;
}
if(dialect == null){
throw new IllegalStateException(String.format("No %s dialect found!", databaseType));
}
}
String originalSql = metaStatementHandler.getValue("delegate.boundSql.sql").toString();
metaStatementHandler.setValue("delegate.boundSql.sql", dialect.getLimitSql(originalSql, rowBounds.getOffset(), rowBounds.getLimit()));
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}