List of usage examples for org.apache.ibatis.mapping SqlCommandType DELETE
SqlCommandType DELETE
To view the source code for org.apache.ibatis.mapping SqlCommandType DELETE.
Click Source Link
From source file:com.baomidou.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
public MappedStatement addDeleteMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource) { return this.addMappedStatement(mapperClass, id, sqlSource, SqlCommandType.DELETE, null, null, Integer.class, new NoKeyGenerator(), null, null); }
From source file:com.baomidou.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * initDelete// ww w .j a v a 2s.c om */ private void initDelete() { if (hasMappedStatement(SqlRunner.DELETE)) { logger.warn("MappedStatement 'SqlRunner.Delete' Already Exists"); return; } SqlSource sqlSource = languageDriver.createSqlSource(configuration, SqlRunner.SQLScript, Map.class); createUpdateMappedStatement(SqlRunner.DELETE, sqlSource, SqlCommandType.DELETE); }
From source file:com.baomidou.mybatisplus.plugins.SqlExplainInterceptor.java
License:Apache License
public Object intercept(Invocation invocation) throws Throwable { /**/*from www . ja va2 s .c o m*/ * ? DELETE UPDATE ? */ MappedStatement ms = (MappedStatement) invocation.getArgs()[0]; if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) { Executor executor = (Executor) invocation.getTarget(); Configuration configuration = ms.getConfiguration(); Object parameter = invocation.getArgs()[1]; BoundSql boundSql = ms.getBoundSql(parameter); Connection connection = executor.getTransaction().getConnection(); String databaseVersion = connection.getMetaData().getDatabaseProductVersion(); if (GlobalConfiguration.getDbType(configuration).equals(DBType.MYSQL) && VersionUtils.compare(minMySQLVersion, databaseVersion)) { logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!"); return invocation.proceed(); } /** * SQL ? */ sqlExplain(configuration, ms, boundSql, connection, parameter); } return invocation.proceed(); }
From source file:com.jeebase.common.base.component.DataPermissionInterceptor.java
License:Apache License
/** * Physical Page Interceptor for all the queries with parameter {@link RowBounds} */// w w w . j a v a 2 s . c o m @SuppressWarnings("unchecked") @Override public Object intercept(Invocation invocation) throws Throwable { StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget()); MetaObject metaObject = SystemMetaObject.forObject(statementHandler); // SQL ? this.sqlParser(metaObject); // rowBounds?mapper?? BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); Object paramObj = boundSql.getParameterObject(); // ??DataPermission DataPermissionCondition dataPermissionCondition = null; if (paramObj instanceof DataPermissionCondition) { dataPermissionCondition = (DataPermissionCondition) paramObj; } else if (paramObj instanceof Map) { for (Object arg : ((Map) paramObj).values()) { if (arg instanceof DataPermissionCondition) { dataPermissionCondition = (DataPermissionCondition) arg; break; } } } /* * ????? */ if (null == dataPermissionCondition) { return invocation.proceed(); } // ?orgId?? if (StringUtils.isEmpty(dataPermissionCondition.getOrgIdAlias())) { dataPermissionCondition.setOrgIdAlias("organiaztion_id"); } String orgIdAlias = dataPermissionCondition.getOrgIdAlias(); List<String> orgIdList = dataPermissionCondition.getOrgIdList(); String userIdAlias = dataPermissionCondition.getUserIdAlias(); String userId = dataPermissionCondition.getUserId(); boolean ownQuery = dataPermissionCondition.isOwnQuery(); // ?userId?? if (ownQuery && StringUtils.isEmpty(dataPermissionCondition.getUserIdAlias())) { dataPermissionCondition.setUserIdAlias("user_id"); } // ???SELECTDELETEUPDATE MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType(); String originalSql = boundSql.getSql(); if (SqlCommandType.SELECT.equals(sqlCommandType) || SqlCommandType.DELETE.equals(sqlCommandType) || SqlCommandType.UPDATE.equals(sqlCommandType)) { String newSql = DataPermissionUtil.convertDataPermission(originalSql, orgIdAlias, orgIdList, ownQuery, userIdAlias, userId); metaObject.setValue("delegate.boundSql.sql", newSql); } else { return invocation.proceed(); } return invocation.proceed(); }
From source file:com.mybatisX.plugins.SqlExplainInterceptor.java
License:Apache License
public Object intercept(Invocation invocation) throws Throwable { /**/* w ww . j a v a 2 s. c o m*/ * ? DELETE UPDATE ? */ MappedStatement ms = (MappedStatement) invocation.getArgs()[0]; if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) { Configuration configuration = ms.getConfiguration(); Object parameter = invocation.getArgs()[1]; BoundSql boundSql = ms.getBoundSql(parameter); Executor exe = (Executor) invocation.getTarget(); Connection connection = exe.getTransaction().getConnection(); /** * SQL ? */ sqlExplain(configuration, ms, boundSql, connection, parameter); } return invocation.proceed(); }
From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java
License:Open Source License
private void buildBatchDelete(String statementId, String collection) { Integer timeout = null;/*from ww w.j a va 2 s. co 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 buildDelete(String statementId) { Integer timeout = null;/*from ww w . j av a 2s . c om*/ Class<?> parameterType = entityClass; //~~~~~~~~~~~~~~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); List<SqlNode> contents = new ArrayList<SqlNode>(); SqlNode sqlNode = new TextSqlNode( "DELETE FROM " + tableName + " WHERE " + getIdColumnName() + " = #{" + getIdFieldName() + "} "); contents.add(sqlNode); // if (versionField != null) // contents.add(new IfSqlNode(new TextSqlNode(getVersionSQL()), // getTestByField(null, versionField))); SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents)); 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.tj.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * <p>// ww w . j av a 2s .c o m * ? SQL ? * </p> * * @param mapperClass * @param modelClass * @param table */ private void injectDeleteSelectiveSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) { SqlMethod sqlMethod = SqlMethod.DELETE_SELECTIVE; String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlWhere(table, false)); SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); this.addMappedStatement(mapperClass, sqlMethod, sqlSource, SqlCommandType.DELETE, Integer.class); }
From source file:com.tj.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * <p>// ww w . j av a 2s . co m * SQL ? * </p> * * @param batch * ??? * @param mapperClass * @param modelClass * @param table */ private void injectDeleteSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) { SqlMethod sqlMethod = SqlMethod.DELETE_BY_ID; SqlSource sqlSource = null; if (batch) { sqlMethod = SqlMethod.DELETE_BATCH; StringBuilder ids = new StringBuilder(); ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"list\" separator=\",\">"); ids.append("#{item}"); ids.append("\n</foreach>"); String sql = String.format(sqlMethod.getSql(), table.getTableName(), table.getKeyColumn(), ids.toString()); sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); } else { String sql = String.format(sqlMethod.getSql(), table.getTableName(), table.getKeyColumn(), table.getKeyColumn()); sqlSource = new RawSqlSource(configuration, sql, Object.class); } this.addMappedStatement(mapperClass, sqlMethod, sqlSource, SqlCommandType.DELETE, Integer.class); }
From source file:org.makersoft.activesql.builder.GenericStatementBuilder.java
License:Open Source License
private void buildDelete(String statementId) { Integer timeout = null;/*from w ww . ja v a 2 s .c om*/ Class<?> parameterType = entityClass; //~~~~~~~~~~~~~~~~~~~~~~~ boolean flushCache = true; boolean useCache = false; boolean resultOrdered = false; KeyGenerator keyGenerator = new NoKeyGenerator(); SqlNode sqlNode = new TextSqlNode("DELETE FROM " + tableName + " WHERE " + getIdColumnName() + " = #{" + getIdFieldName() + "} " + getVersionSQL()); SqlSource sqlSource = new DynamicSqlSource(configuration, sqlNode); assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.DELETE, null, timeout, null, parameterType, null, null, null, flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang); }