本文整理汇总了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);
}
示例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");
}
}
示例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();
}
示例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);
});
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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, ""));
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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());
}