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


Java Insert类代码示例

本文整理汇总了Java中net.sf.jsqlparser.statement.insert.Insert的典型用法代码示例。如果您正苦于以下问题:Java Insert类的具体用法?Java Insert怎么用?Java Insert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createInsertWithSelectStatement

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
private InsertWorker createInsertWithSelectStatement(Insert insert, boolean forceUpdate) throws SQLException
{
	Select select = insert.getSelect();
	if (select == null)
	{
		throw new CloudSpannerSQLException("Insert statement must contain a select statement",
				Code.INVALID_ARGUMENT);
	}
	boolean isDuplicate = insert.isUseDuplicate();
	InsertWorker.DMLOperation mode;
	if (forceUpdate)
		mode = DMLOperation.Update;
	else if (isDuplicate)
		mode = DMLOperation.OnDuplicateKeyUpdate;
	else
		mode = DMLOperation.Insert;
	return new InsertWorker(getConnection(), select, insert, getConnection().isAllowExtendedMode(), mode);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:19,代码来源:CloudSpannerPreparedStatement.java

示例2: JSQLParserAdapter

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
public JSQLParserAdapter(String sql, ShardRouter shardRouter, boolean enableLimitCheck) {
    this.sql = sql;
    this.shardRouter = shardRouter;
    this.enableLimitCheck = enableLimitCheck;
    try {
        this.statement = CCJSqlParserUtil.parse(sql);
    } catch (Throwable e) {
        throw new SQLSyntaxErrorException("sql is [" + sql + "]", e);
    }
    if (statement instanceof Select //
        || statement instanceof Update//
        || statement instanceof Insert//
        || statement instanceof Delete) {
        // ok
    } else {
        throw new UnsupportedSQLExpressionException(
                                                    "Sql ["
                                                            + sql
                                                            + "] is not supported in shard sql. Only support 'select' 'insert' 'update' and 'delete' sql statement");
    }
}
 
开发者ID:hellojavaer,项目名称:ddal,代码行数:22,代码来源:JSQLParserAdapter.java

示例3: visit

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
public void visit(Insert insert) {
    this.getStack().push(new FrameContext());
    ShardRouteConfig routeConfig = shardRouter.getRouteConfig(insert.getTable().getSchemaName(),
                                                              insert.getTable().getName());
    if (routeConfig != null) {
        TableWrapper table = new TableWrapper(insert.getTable(), routeConfig);
        addRoutedTableIntoContext(table, routeConfig, false);
        List<Column> columns = insert.getColumns();
        if (columns != null) {
            ExpressionList expressionList = (ExpressionList) insert.getItemsList();
            List<Expression> valueList = expressionList.getExpressions();
            for (int i = 0; i < columns.size(); i++) {
                Column column = columns.get(i);
                TableWrapper tab = getTableFromContext(column);
                if (tab != null) {
                    Expression expression = valueList.get(i);
                    routeTable(tab, column, expression);
                }
            }
        }
    }
    super.visit(insert);
    afterVisitBaseStatement();
}
 
开发者ID:hellojavaer,项目名称:ddal,代码行数:26,代码来源:JSQLParserAdapter.java

示例4: visit

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
public void visit(Insert s) {
    visit(s.getTable());
    if (s.getColumns() != null) {
        s.getColumns().forEach(c -> {
            c.accept(this);
        });
    }
    if (s.getItemsList() != null) {
        s.getItemsList().accept(this);
    }
    if (s.getSelect() != null) {
        s.getSelect().accept(this);
    }
    if (s.getReturningExpressionList() != null) {
        s.getReturningExpressionList().forEach(o -> {
            o.accept(this);
        });
    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:21,代码来源:JdbcQueryRewriter.java

示例5: processInsert

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
/**
 * <p>
 * insert 语句处理
 * </p>
 */
@Override
public void processInsert(Insert insert) {
    if (this.tenantHandler.doTableFilter(insert.getTable().getName())) {
        // 过滤退出执行
        return;
    }
    insert.getColumns().add(new Column(this.tenantHandler.getTenantIdColumn()));
    if (insert.getSelect() != null) {
        processPlainSelect((PlainSelect) insert.getSelect().getSelectBody(), true);
    } else if (insert.getItemsList() != null) {
        ((ExpressionList) insert.getItemsList()).getExpressions().add(tenantHandler.getTenantId());
    } else {
        throw new MybatisPlusException("Failed to process multiple-table update, please exclude the tableName or statementId");
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:21,代码来源:TenantSqlParser.java

示例6: rawQuery

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
/**
 * Use the {@link android.database.sqlite.SQLiteDatabase#rawQuery(String, String[]) rawQuery} method.
 * This method uses {@link net.sf.jsqlparser.parser.CCJSqlParserUtil#parse(String) parser} method to parse the SQL query.
 * Unlike the rawQuery of the SQLiteDatabase, there is no need to call the moveToFirst method of the returned Cursor to apply SQL query.
 * @param tag The tag to be mapped to the restoring query.
 * @throws IllegalArgumentException if the tag is null.
 */
public Cursor rawQuery(String sql, String[] selectionArgs, String tag)
        throws JSQLParserException, ClassCastException {
    if (tag == null)
        throw new IllegalArgumentException("The tag must not be null.");

    Statement statement = CCJSqlParserUtil.parse(sql);

    generateRawUpdateDeleteQuery(statement, sql, selectionArgs, tag);

    Cursor cursor =  mSQLiteDatabase.rawQuery(sql, selectionArgs);
    cursor.moveToFirst();

    if (sql.toLowerCase(Locale.getDefault()).contains("insert into")) {
        Insert insertStatement = (Insert) statement;
        String table = insertStatement.getTable().getName();
        generateInsertRawQuery(table, tag);
    }

    return cursor;
}
 
开发者ID:yaa110,项目名称:RestorableSQLiteDatabase,代码行数:28,代码来源:RestorableSQLiteDatabase.java

示例7: parseConvertedQuery

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
protected Statement parseConvertedQuery(Insert insert) {
    // Get expression list from query
    ItemsList itemsList = insert.getItemsList();

    if (itemsList instanceof MultiExpressionList) {
        ((MultiExpressionList) itemsList).getExprList().stream()
                .map(ExpressionList::getExpressions)
                .forEach(this::convertExpressionList);
    } else {
        List<Expression> expressions = ((ExpressionList) itemsList).getExpressions();
        convertExpressionList(expressions);
    }

    return insert;
}
 
开发者ID:Hyperparticle,项目名称:integrity-coded-database,代码行数:17,代码来源:OCFQuery.java

示例8: checkParseAndDeparse

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
public void checkParseAndDeparse(String statementText) throws JSQLParserException {
    Statement statement = parserManager.parse(new StringReader(statementText));
    assertNotNull(statement);
    StringBuilder buffer = new StringBuilder();
    StatementDeParser deparser = new StatementDeParser(buffer);
    if (statement instanceof Select) {
        deparser.visit((Select) statement);
    } else if (statement instanceof Delete) {
        deparser.visit((Delete) statement);
    } else if (statement instanceof Insert) {
        deparser.visit((Insert) statement);
    } else {
        throw new JSQLParserException("Unknown type of parsed statement");
    }
    assertEquals(buffer.toString().toLowerCase().replaceAll(ExpressionDeParser.LINE_SEPARATOR, ""), statementText.toLowerCase().replaceAll(ExpressionDeParser.LINE_SEPARATOR, ""));
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:17,代码来源:GeneralTest.java

示例9: testInsertFromSelect

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Test
public void testInsertFromSelect() throws JSQLParserException {
    String statement = "INSERT INTO mytable t (col1, col2, col3) SELECT * FROM mytable2";
    Insert insert = (Insert) parserManager.parse(new StringReader(statement));
    assertEquals("mytable", insert.getTable().getName());
    assertEquals(3, insert.getColumns().size());
    assertEquals("col1", ((Column) insert.getColumns().get(0)).getColumnName());
    assertEquals("col2", ((Column) insert.getColumns().get(1)).getColumnName());
    assertEquals("col3", ((Column) insert.getColumns().get(2)).getColumnName());
    assertTrue(insert.getItemsList() instanceof SubSelect);
    assertEquals("mytable2", ((Table) ((PlainSelect) ((SubSelect) insert.getItemsList()).getSelectBody()).getFromItem()).getName());

    //toString uses brakets
    String statementToString = "INSERT INTO mytable t (col1, col2, col3) (SELECT * FROM mytable2)";
    assertEquals(statementToString, "" + insert);
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:17,代码来源:InsertTest.java

示例10: processSQL

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
public Result processSQL(String SQL) throws Exception {
    Statement s = CCJSqlParserUtil.parse(SQL);
    if(s instanceof Select){
        return processSelect(SQL);
    }
    else if(s instanceof Insert){
        return processInsert(SQL)? new AggregateResults() : null;
    }
    else if(s instanceof CreateTable) {
        return processCreateTable(SQL) ? new AggregateResults() : null;
    }

    return new AggregateResults();
}
 
开发者ID:zbd1023,项目名称:512DB,代码行数:15,代码来源:SQLLayer.java

示例11: getParameterMetaData

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
public CloudSpannerParameterMetaData getParameterMetaData() throws SQLException
{
	// parse the SQL statement without executing it
	try
	{
		if (isDDLStatement())
		{
			throw new CloudSpannerSQLException("Cannot get parameter meta data for DDL statement",
					Code.INVALID_ARGUMENT);
		}
		Statement statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
		if (statement instanceof Insert || statement instanceof Update || statement instanceof Delete)
		{
			// Create mutation, but don't do anything with it. This
			// initializes column names of the parameter store.
			createMutations(sql, false, true);
		}
		else if (statement instanceof Select)
		{
			// Create select builder, but don't do anything with it. This
			// initializes column names of the parameter store.
			createSelectBuilder(statement, sql);
		}
	}
	catch (JSQLParserException | TokenMgrError e)
	{
		throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(),
				Code.INVALID_ARGUMENT, e);
	}
	return new CloudSpannerParameterMetaData(this);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:33,代码来源:CloudSpannerPreparedStatement.java

示例12: visit

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
public void visit(Insert insert) {
    SelectDeParser selectDeParser = new SelectDeParser();
    selectDeParser.setBuffer(buffer);
    ExpressionDeParser expressionDeParser = new ExpressionDeParser(selectDeParser, buffer);
    selectDeParser.setExpressionVisitor(expressionDeParser);
    InsertDeParser insertDeParser = new InsertDeParser(expressionDeParser, selectDeParser, buffer);
    insertDeParser.deParse(insert);
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:10,代码来源:StatementDeParser.java

示例13: visit

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Override
public void visit(Insert insert) {
    tables.add(insert.getTable().getName());
    if (insert.getItemsList() != null) {
        insert.getItemsList().accept(this);
    }
    if (insert.getSelect() != null) {
        visit(insert.getSelect());
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:11,代码来源:TablesNamesFinder.java

示例14: parse

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
public Statement parse(String sql) throws JSQLParserException {
    sql = sql.trim();

    boolean isInsertOrReplace = false;

    // 校验是否"INSERT OR REPLACE"语法
    if (sql.toUpperCase().startsWith("INSERT OR REPLACE")) {
        isInsertOrReplace = true;

        String[] sqlParts = new String[2];
        sqlParts[0] = sql.substring(0, "INSERT OR REPLACE".length());
        sqlParts[1] = sql.substring("INSERT OR REPLACE".length(), sql.length());

        sqlParts[0] = sqlParts[0].toUpperCase().replace("INSERT OR REPLACE", "INSERT");

        sql = sqlParts[0] + sqlParts[1];
    }

    CCJSqlParser parser = new CCJSqlParser(new StringReader(sql));
    try {
        Statement statement = parser.Statement();

        // 当"INSERT OR REPLACE"语法,生成Insert代理
        if (isInsertOrReplace && statement instanceof Insert) {
            statement = new InsertOrReplaceProxy().getInstance(Insert.class, (Insert) statement);
        }
        return statement;
    } catch (Exception ex) {
        throw new JSQLParserException(ex);
    }
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:32,代码来源:KbSqlParserManager.java

示例15: parse

import net.sf.jsqlparser.statement.insert.Insert; //导入依赖的package包/类
@Test
public void parse() throws Exception {
    String sql = "INSERT or replace INTO person (id, name) VALUES (?, ?)";

    Insert insert = (Insert) new KbSqlParserManager().parse(sql);

    Assert.assertEquals("INSERT OR REPLACE INTO person (id, name) VALUES (?, ?)", insert.toString());
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:9,代码来源:KbSqlParserManagerTest.java


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