本文整理汇总了Java中org.apache.ibatis.mapping.SqlSource类的典型用法代码示例。如果您正苦于以下问题:Java SqlSource类的具体用法?Java SqlSource怎么用?Java SqlSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlSource类属于org.apache.ibatis.mapping包,在下文中一共展示了SqlSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyFromMappedStatement
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
private MappedStatement copyFromMappedStatement(MappedStatement ms,
SqlSource newSqlSource) {
MappedStatement.Builder builder = new MappedStatement.Builder(
ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (null != ms.getKeyProperties()) {
for (String keyProperty : ms.getKeyProperties()) {
builder.keyProperty(keyProperty);
}
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
builder.resultMaps(ms.getResultMaps());
builder.cache(ms.getCache());
return builder.build();
}
示例2: injectDeleteByIdSql
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
/**
* <p>
* 注入删除 SQL 语句
* </p>
*
* @param mapperClass
* @param modelClass
* @param table
*/
protected void injectDeleteByIdSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
SqlMethod sqlMethod = SqlMethod.DELETE_BY_ID;
SqlSource sqlSource;
// 因为后面要通过get方法获取类型,所以这里要获取key的属性值
String idStr = table.getKeyProperty();
if (batch) {
sqlMethod = SqlMethod.DELETE_BATCH_BY_IDS;
StringBuilder ids = new StringBuilder();
ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"list\" separator=\",\">");
ids.append("#{item}");
ids.append("\n</foreach>");
idStr = ids.toString();
}
String sql = String.format(sqlMethod.getSql(), table.getTableName(), table.getKeyColumn(), idStr);
sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
this.addDeleteMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource);
}
示例3: addMappedStatement
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
public MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
String statementName = mapperClass.getName() + "." + id;
if (configuration.hasStatement(statementName)) {
System.err.println("{" + statementName
+ "} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.");
return null;
}
/* 缓存逻辑处理 */
boolean isSelect = false;
if (sqlCommandType == SqlCommandType.SELECT) {
isSelect = true;
}
return builderAssistant.addMappedStatement(id, sqlSource, StatementType.PREPARED, sqlCommandType, null, null, null,
parameterClass, resultMap, resultType, null, !isSelect, isSelect, false, keyGenerator, keyProperty, keyColumn,
configuration.getDatabaseId(), languageDriver, null);
}
示例4: getSqlSourceFromAnnotations
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType, LanguageDriver languageDriver) {
try {
Class<? extends Annotation> sqlAnnotationType = getSqlAnnotationType(method);
Class<? extends Annotation> sqlProviderAnnotationType = getSqlProviderAnnotationType(method);
if (sqlAnnotationType != null) {
if (sqlProviderAnnotationType != null) {
throw new BindingException("You cannot supply both a static SQL and SqlProvider to method named " + method.getName());
}
Annotation sqlAnnotation = method.getAnnotation(sqlAnnotationType);
final String[] strings = (String[]) sqlAnnotation.getClass().getMethod("value").invoke(sqlAnnotation);
return buildSqlSourceFromStrings(strings, parameterType, languageDriver);
} else if (sqlProviderAnnotationType != null) {
Annotation sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
return new ProviderSqlSource(assistant.getConfiguration(), sqlProviderAnnotation);
}
return null;
} catch (Exception e) {
throw new BuilderException("Could not find value method on SQL annotation. Cause: " + e, e);
}
}
示例5: genKeyGenerator
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
/**
* <p>
* 自定义 KEY 生成器
* </p>
*/
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
String baseStatementId, LanguageDriver languageDriver) {
Incrementer incrementer = GlobalConfigUtils.getIncrementer(builderAssistant.getConfiguration());
if (null == incrementer) {
throw new MybatisPlusException("Error: not configure Incrementer implementation class.");
}
String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz();
StatementType statementType = StatementType.PREPARED;
String keyProperty = tableInfo.getKeyProperty();
String keyColumn = tableInfo.getKeyColumn();
SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(),
incrementer.getSequenceQuery(tableInfo.getKeySequence().value()), null);
builderAssistant.addMappedStatement(id, sqlSource, statementType, SqlCommandType.SELECT, null, null, null,
null, null, resultTypeClass, null, false, false, false,
new NoKeyGenerator(), keyProperty, keyColumn, null, languageDriver, null);
id = builderAssistant.applyCurrentNamespace(id, false);
MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false);
SelectKeyGenerator keyGenerator = new SelectKeyGenerator(keyStatement, true);
builderAssistant.getConfiguration().addKeyGenerator(id, keyGenerator);
return keyGenerator;
}
示例6: copyFromMappedStatement
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
// builder.keyProperty((ms.getKeyProperty()));
builder.keyProperty(arrayToStr(ms.getKeyProperties()));
// setStatementTimeout()
builder.timeout(ms.getTimeout());
// setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
// setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
// setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例7: insert
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
public String insert(Class<?> entityType) {
// 命令名称
String statementId = buildStatementId(entityType, "insert");
if (configuration.hasStatement(statementId)) {
return statementId;
}
// 创建命令
String sql = new SqlBuilder(entityType).insert();
SqlSource sqlSource = new RawSqlSource(configuration, sql, null);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, statementId, sqlSource,
SqlCommandType.INSERT);
// 判断是否需要自动生成主键
EntityMetadata metadata = EntityMetadata.get(entityType);
for (IdProperty idProperty : metadata.getIdProperties()) {
KeyGenerator keyGenerator = idProperty.getKeyGenerator();
if (keyGenerator == null) {
continue;
}
String propertyName = idProperty.getName();
String columnName = idProperty.getColumnName();
statementBuilder.keyProperty(propertyName).keyColumn(columnName).keyGenerator(keyGenerator);
}
MappedStatement statement = statementBuilder.build();
StatementResultMapHelper.addMappedStatement(configuration, statement);
return statementId;
}
示例8: build
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver,
EntityInfo entity) {
String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
for (String name : names) {
String msId = entity.getMapperClass().getName() + "." + name;
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
String sql = buildUpdateSql(entityMapper, name.endsWith("Selective"));
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql,
entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
msId, sqlSource, SqlCommandType.UPDATE);
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
}
}
示例9: build
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();
// 从参数对象里提取注解信息
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
// 生成sql
String sql = buildDeleteSql(entityMapper);
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.DELETE);
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
}
示例10: getBoundSql
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
public BoundSql getBoundSql(Object parameterObject) {
DynamicContext context = new DynamicContext(configuration, parameterObject);
rootSqlNode.apply(context);
SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
if (count) {
sqlSource = getCountSqlSource(configuration, sqlSource, parameterObject);
} else {
sqlSource = getPageSqlSource(configuration, sqlSource, parameterObject);
}
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
// 设置条件参数
for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
}
return boundSql;
}
示例11: createSqlSource
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
// issue #3
if (script.startsWith("<script>")) {
XPathParser parser = new XPathParser(script, false, configuration.getVariables(), new XMLMapperEntityResolver());
return createSqlSource(configuration, parser.evalNode("/script"), parameterType);
} else {
// issue #127
script = PropertyParser.parse(script, configuration.getVariables());
TextSqlNode textSqlNode = new TextSqlNode(script);
if (textSqlNode.isDynamic()) {
return new DynamicSqlSource(configuration, textSqlNode);
} else {
return new RawSqlSource(configuration, script, parameterType);
}
}
}
示例12: getSqlSourceFromAnnotations
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType, LanguageDriver languageDriver) {
try {
Class<? extends Annotation> sqlAnnotationType = getSqlAnnotationType(method);
Class<? extends Annotation> sqlProviderAnnotationType = getSqlProviderAnnotationType(method);
if (sqlAnnotationType != null) {
if (sqlProviderAnnotationType != null) {
throw new BindingException("You cannot supply both a static SQL and SqlProvider to method named " + method.getName());
}
Annotation sqlAnnotation = method.getAnnotation(sqlAnnotationType);
final String[] strings = (String[]) sqlAnnotation.getClass().getMethod("value").invoke(sqlAnnotation);
return buildSqlSourceFromStrings(strings, parameterType, languageDriver);
} else if (sqlProviderAnnotationType != null) {
Annotation sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
return new ProviderSqlSource(assistant.getConfiguration(), sqlProviderAnnotation);
}
return null;
} catch (Exception e) {
throw new BuilderException("Could not find value method on SQL annotation. Cause: " + e, e);
}
}
示例13: getBoundSql
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
@Override
public BoundSql getBoundSql(Object parameterObject) {
Map<String, Object> bindings = createBindings(parameterObject, configuration);
VelocityContext context = new VelocityContext(bindings);
StringWriter sw = new StringWriter();
script.merge(context, sw);
VelocitySqlSourceBuilder sqlSourceParser = new VelocitySqlSourceBuilder(configuration);
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
SqlSource sqlSource = sqlSourceParser.parse(sw.toString(), parameterType);
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
for (Map.Entry<String, Object> entry : bindings.entrySet()) {
boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
}
return boundSql;
}
示例14: copyFromMappedStatement
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (ms.getKeyProperties() != null) {
for (String keyProperty : ms.getKeyProperties()) {
builder.keyProperty(keyProperty);
}
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
builder.resultMaps(ms.getResultMaps());
builder.cache(ms.getCache());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例15: getTableName
import org.apache.ibatis.mapping.SqlSource; //导入依赖的package包/类
public static String getTableName(MappedStatement mappedStatement, Object param) {
String re = map.get(mappedStatement);
if (re == null) {
ISqlParser iSqlParser = new DruidSqlParser();
try {
SqlSource sqlSource = mappedStatement.getSqlSource();
if (sqlSource instanceof ExtendedSqlSource) {
iSqlParser.init(((ExtendedSqlSource) sqlSource).getBoundSqlRaw(param).getSql());
re = iSqlParser.getTableName();
map.put(mappedStatement, re);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return re;
}