List of usage examples for org.apache.ibatis.mapping StatementType PREPARED
StatementType PREPARED
To view the source code for org.apache.ibatis.mapping StatementType PREPARED.
Click Source Link
From source file:com.baomidou.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
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; }/* w w w . j a va 2s .c om*/ /* ? */ 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); }
From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java
License:Apache License
void parseStatement(Method method) { Class<?> parameterTypeClass = getParameterType(method); LanguageDriver languageDriver = getLanguageDriver(method); SqlSource sqlSource = getSqlSourceFromAnnotations(method, parameterTypeClass, languageDriver); if (sqlSource != null) { Options options = method.getAnnotation(Options.class); final String mappedStatementId = type.getName() + "." + method.getName(); Integer fetchSize = null; Integer timeout = null;/*from ww w .ja v a2s.c o m*/ StatementType statementType = StatementType.PREPARED; ResultSetType resultSetType = ResultSetType.FORWARD_ONLY; SqlCommandType sqlCommandType = getSqlCommandType(method); boolean isSelect = sqlCommandType == SqlCommandType.SELECT; boolean flushCache = !isSelect; boolean useCache = isSelect; KeyGenerator keyGenerator; String keyProperty = "id"; String keyColumn = null; if (SqlCommandType.INSERT.equals(sqlCommandType) || SqlCommandType.UPDATE.equals(sqlCommandType)) { // first check for SelectKey annotation - that overrides everything else SelectKey selectKey = method.getAnnotation(SelectKey.class); if (selectKey != null) { keyGenerator = handleSelectKeyAnnotation(selectKey, mappedStatementId, getParameterType(method), languageDriver); keyProperty = selectKey.keyProperty(); } else if (options == null) { keyGenerator = configuration.isUseGeneratedKeys() ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE; } else { keyGenerator = options.useGeneratedKeys() ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE; keyProperty = options.keyProperty(); keyColumn = options.keyColumn(); } } else { keyGenerator = NoKeyGenerator.INSTANCE; } if (options != null) { if (FlushCachePolicy.TRUE.equals(options.flushCache())) { flushCache = true; } else if (FlushCachePolicy.FALSE.equals(options.flushCache())) { flushCache = false; } useCache = options.useCache(); fetchSize = options.fetchSize() > -1 || options.fetchSize() == Integer.MIN_VALUE ? options.fetchSize() : null; //issue #348 timeout = options.timeout() > -1 ? options.timeout() : null; statementType = options.statementType(); resultSetType = options.resultSetType(); } String resultMapId = null; ResultMap resultMapAnnotation = method.getAnnotation(ResultMap.class); if (resultMapAnnotation != null) { String[] resultMaps = resultMapAnnotation.value(); StringBuilder sb = new StringBuilder(); for (String resultMap : resultMaps) { if (sb.length() > 0) { sb.append(","); } sb.append(resultMap); } resultMapId = sb.toString(); } else if (isSelect) { resultMapId = parseResultMap(method); } assistant.addMappedStatement(mappedStatementId, sqlSource, statementType, sqlCommandType, fetchSize, timeout, // ParameterMapID null, parameterTypeClass, resultMapId, getReturnType(method), resultSetType, flushCache, useCache, // TODO gcode issue #577 false, keyGenerator, keyProperty, keyColumn, // DatabaseID null, languageDriver, // ResultSets options != null ? nullOrEmpty(options.resultSets()) : null); } }
From source file:com.baomidou.mybatisplus.toolkit.TableInfoHelper.java
License:Apache License
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant, String baseStatementId, LanguageDriver languageDriver) { DBType dbType = GlobalConfiguration.getDbType(builderAssistant.getConfiguration()); if (dbType != DBType.ORACLE) throw new IllegalArgumentException("??Oracle?"); String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX; Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz(); Class<?> parameterTypeClass = null; StatementType statementType = StatementType.PREPARED; String keyProperty = tableInfo.getKeyProperty(); String keyColumn = tableInfo.getKeyColumn(); boolean executeBefore = true; boolean useCache = false; KeyGenerator keyGenerator = new NoKeyGenerator(); Integer fetchSize = null;/*from ww w . j a v a 2 s.c om*/ Integer timeout = null; boolean flushCache = false; String parameterMap = null; String resultMap = null; ResultSetType resultSetTypeEnum = null; //??ORACLE???? String sql = "select " + tableInfo.getKeySequence().value() + ".nextval from dual"; SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(), sql.trim(), null); SqlCommandType sqlCommandType = SqlCommandType.SELECT; builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache, false, keyGenerator, keyProperty, keyColumn, null, languageDriver, null); id = builderAssistant.applyCurrentNamespace(id, false); MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false); SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore); builderAssistant.getConfiguration().addKeyGenerator(id, answer); return answer; }
From source file:com.mybatisX.core.MybatisMapperAnnotationBuilder.java
License:Apache License
void parseStatement(Method method) { Class<?> parameterTypeClass = getParameterType(method); LanguageDriver languageDriver = getLanguageDriver(method); SqlSource sqlSource = getSqlSourceFromAnnotations(method, parameterTypeClass, languageDriver); if (sqlSource != null) { Options options = method.getAnnotation(Options.class); final String mappedStatementId = type.getName() + "." + method.getName(); Integer fetchSize = null; Integer timeout = null;/*from w w w . j a v a 2s . com*/ StatementType statementType = StatementType.PREPARED; ResultSetType resultSetType = ResultSetType.FORWARD_ONLY; SqlCommandType sqlCommandType = getSqlCommandType(method); boolean isSelect = sqlCommandType == SqlCommandType.SELECT; boolean flushCache = !isSelect; boolean useCache = isSelect; KeyGenerator keyGenerator; String keyProperty = "id"; String keyColumn = null; if (SqlCommandType.INSERT.equals(sqlCommandType) || SqlCommandType.UPDATE.equals(sqlCommandType)) { // first check for SelectKey annotation - that overrides // everything else SelectKey selectKey = method.getAnnotation(SelectKey.class); if (selectKey != null) { keyGenerator = handleSelectKeyAnnotation(selectKey, mappedStatementId, getParameterType(method), languageDriver); keyProperty = selectKey.keyProperty(); } else if (options == null) { keyGenerator = configuration.isUseGeneratedKeys() ? new Jdbc3KeyGenerator() : new NoKeyGenerator(); } else { keyGenerator = options.useGeneratedKeys() ? new Jdbc3KeyGenerator() : new NoKeyGenerator(); keyProperty = options.keyProperty(); keyColumn = options.keyColumn(); } } else { keyGenerator = new NoKeyGenerator(); } if (options != null) { if (FlushCachePolicy.TRUE.equals(options.flushCache())) { flushCache = true; } else if (FlushCachePolicy.FALSE.equals(options.flushCache())) { flushCache = false; } useCache = options.useCache(); fetchSize = options.fetchSize() > -1 || options.fetchSize() == Integer.MIN_VALUE ? options.fetchSize() : null; // issue // #348 timeout = options.timeout() > -1 ? options.timeout() : null; statementType = options.statementType(); resultSetType = options.resultSetType(); } String resultMapId = null; ResultMap resultMapAnnotation = method.getAnnotation(ResultMap.class); if (resultMapAnnotation != null) { String[] resultMaps = resultMapAnnotation.value(); StringBuilder sb = new StringBuilder(); for (String resultMap : resultMaps) { if (sb.length() > 0) { sb.append(","); } sb.append(resultMap); } resultMapId = sb.toString(); } else if (isSelect) { resultMapId = parseResultMap(method); } assistant.addMappedStatement(mappedStatementId, sqlSource, statementType, sqlCommandType, fetchSize, timeout, // ParameterMapID null, parameterTypeClass, resultMapId, getReturnType(method), resultSetType, flushCache, useCache, // TODO gcode issue #577 false, keyGenerator, keyProperty, keyColumn, // DatabaseID null, languageDriver, // ResultSets options != null ? nullOrEmpty(options.resultSets()) : null); } }
From source file:com.navercorp.pinpoint.web.dao.ibatis.BindingLogPlugin32.java
License:Apache License
private void bindingLog(Invocation invocation) throws SQLException { Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; StatementType statementType = ms.getStatementType(); if (StatementType.PREPARED == statementType || StatementType.CALLABLE == statementType) { Log statementLog = ms.getStatementLog(); if (isDebugEnable(statementLog)) { BoundSql boundSql = ms.getBoundSql(parameterObject); String sql = boundSql.getSql(); List<String> parameterList = getParameters(ms, parameterObject, boundSql); debug(statementLog, "==> BindingLog: " + bindLogFormatter.format(sql, parameterList)); }//from w w w. ja va 2 s .c o m } }
From source file:com.sinotopia.mybatis.plus.toolkit.TableInfoHelper.java
License:Apache License
/** * <p>//from www. j a v a 2 s . c om * KEY ? * </p> */ public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant, String baseStatementId, LanguageDriver languageDriver) { IKeyGenerator keyGenerator = GlobalConfiguration.getKeyGenerator(builderAssistant.getConfiguration()); if (null == keyGenerator) { throw new IllegalArgumentException("not configure IKeyGenerator 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(), keyGenerator.executeSql(tableInfo), 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 answer = new SelectKeyGenerator(keyStatement, true); builderAssistant.getConfiguration().addKeyGenerator(id, answer); return answer; }
From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java
License:Open Source License
private void buildMultiGet(String statementId, String collection) { Integer fetchSize = null;// ww w . j a v a 2 s.c o m Integer timeout = null; Class<?> resultType = entityClass; //~~~~~~~~~~~~~~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); SqlSource sqlSource = new DynamicSqlSource(configuration, getMultiGetSql(collection)); String resultMap = null; Iterator<String> resultMapNames = configuration.getResultMapNames().iterator(); while (resultMapNames.hasNext()) { String name = resultMapNames.next(); ResultMap temp = configuration.getResultMap(name); if (temp.getType().equals(entityClass)) { resultMap = temp.getId(); break; } } assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.SELECT, fetchSize, timeout, null, idField.getType(), resultMap, resultType, null, flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang); }
From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java
License:Open Source License
private void buildBatchDelete(String statementId, String collection) { Integer timeout = null;/* w ww . j a va 2 s . c o m*/ Class<?> parameterType = idField.getType(); //~~~~~~~~~~~~~~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); SqlSource sqlSource = new DynamicSqlSource(configuration, getBatchDeleteSql(collection)); assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.DELETE, null, timeout, null, parameterType, null, null, null, flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang); }
From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java
License:Open Source License
private void buildBatchInsert(String statementId, String collection) { Integer fetchSize = null;//from ww w .j a v a 2 s .c om Integer timeout = null; Class<?> parameterType = entityClass; ///~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); String keyProperty = null; String keyColumn = null; Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass); GeneratedValue generatedValue = AnnotationUtils.findDeclaredAnnotation(GeneratedValue.class, entityClass); if (id != null) { String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX; if (!sharded) { if (containSn) snGenerators.put(statementId, new SnGenerator()); if (configuration.hasKeyGenerator(keyStatementId)) { keyGenerator = configuration.getKeyGenerator(keyStatementId); } else if (generatedValue != null) { if (generatedValue.strategy() == GenerationType.UUID) { keyGenerator = new UuidKeyGenerator(generatedValue.length()); } } else { keyGenerator = id.generatedKeys() ? new Jdbc4KeyGenerator() : new NoKeyGenerator(); } } else { if (containSn) shardSnGenerators.put(statementId, new ShardSnGenerator()); if (generatedValue != null) { if (generatedValue.strategy() == GenerationType.UUID) { shardedKeyGenerators.put(statementId, new ShardUuidKeyGenerator(generatedValue.length())); } else if (generatedValue.strategy() == GenerationType.TABLE || generatedValue.strategy() == GenerationType.AUTO) { shardedKeyGenerators.put(statementId, new ShardJdbc4KeyGenerator()); } } } keyProperty = idField.getName(); keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName()) : id.column(); } List<SqlNode> contents = new ArrayList<SqlNode>(); contents.add(this.getBatchInsertSql(collection)); SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents)); assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.INSERT, fetchSize, timeout, null, parameterType, null, null, null, flushCache, useCache, resultOrdered, keyGenerator, keyProperty, keyColumn, databaseId, lang); }
From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java
License:Open Source License
public void refresh(MappedStatement mappedStatement) { Integer timeout = null;//w ww . j av a 2 s .c o m Class<?> parameterType = entityClass; ///~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); String keyProperty = null; String keyColumn = null; Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass); GeneratedValue generatedValue = AnnotationUtils.findDeclaredAnnotation(GeneratedValue.class, entityClass); if (id != null) { String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX; if (!sharded) { if (containSn) snGenerators.put(mappedStatement.getId(), new SnGenerator()); if (configuration.hasKeyGenerator(keyStatementId)) { keyGenerator = configuration.getKeyGenerator(keyStatementId); } else if (generatedValue != null) { if (generatedValue.strategy() == GenerationType.UUID) { keyGenerator = new UuidKeyGenerator(generatedValue.length()); } } else { keyGenerator = id.generatedKeys() ? new Jdbc4KeyGenerator() : new NoKeyGenerator(); } } else { if (containSn) shardSnGenerators.put(mappedStatement.getId(), new ShardSnGenerator()); if (generatedValue != null) { if (generatedValue.strategy() == GenerationType.UUID) { shardedKeyGenerators.put(mappedStatement.getId(), new ShardUuidKeyGenerator(generatedValue.length())); } else if (generatedValue.strategy() == GenerationType.TABLE || generatedValue.strategy() == GenerationType.AUTO) { shardedKeyGenerators.put(mappedStatement.getId(), new ShardJdbc4KeyGenerator()); } } // shardedKeyGenerators.put(statementId, new shardeduu) } keyProperty = idField.getName(); keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName()) : id.column(); } SqlSource sqlSource = mappedStatement.getSqlSource(); String parameterMap = null; Iterator<String> parameterMapNames = configuration.getParameterMapNames().iterator(); while (parameterMapNames.hasNext()) { String name = parameterMapNames.next(); ParameterMap temp = configuration.getParameterMap(name); if (temp.getType().equals(entityClass)) { parameterMap = temp.getId(); break; } } assistant.addMappedStatement(mappedStatement.getId(), sqlSource, StatementType.PREPARED, SqlCommandType.INSERT, null, timeout, parameterMap, parameterType, null, null, null, flushCache, useCache, resultOrdered, keyGenerator, keyProperty, keyColumn, databaseId, lang); }