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


Java CCJSqlParserManager.parse方法代码示例

本文整理汇总了Java中net.sf.jsqlparser.parser.CCJSqlParserManager.parse方法的典型用法代码示例。如果您正苦于以下问题:Java CCJSqlParserManager.parse方法的具体用法?Java CCJSqlParserManager.parse怎么用?Java CCJSqlParserManager.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.jsqlparser.parser.CCJSqlParserManager的用法示例。


在下文中一共展示了CCJSqlParserManager.parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testParse

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
public void testParse() throws Exception {
	CCJSqlParserManager parserManager = new CCJSqlParserManager();
	BufferedReader in = new BufferedReader(new FileReader("testfiles" + File.separator + "simple_parsing.txt"));
	String statement = "";
	while (true) {
		try {
			statement = CCJSqlParserManagerTest.getStatement(in);
			if (statement == null)
				break;
				
			Statement parsedStm = parserManager.parse(new StringReader(statement));
			//System.out.println(statement);
		} catch (JSQLParserException e) {
			throw new TestException("impossible to parse statement: " + statement, e);
		}
	}
}
 
开发者ID:UBOdin,项目名称:jsqlparser,代码行数:18,代码来源:CCJSqlParserManagerTest.java

示例2: testParse

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
@Test
public void testParse() throws Exception {
    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    URL simpleParsing = Thread.currentThread().getContextClassLoader().getResource("simple_parsing.txt");
    try (BufferedReader in = new BufferedReader(new InputStreamReader(simpleParsing.openStream()))) {
        String statement = "";
        while (true) {
            try {
                statement = CCJSqlParserManagerTest.getStatement(in);
                if (statement == null) {
                    break;
                }

                Statement parsedStm = parserManager.parse(new StringReader(statement));
                //System.out.println(statement);
            } catch (JSQLParserException e) {
                throw new TestException("impossible to parse statement: " + statement, e);
            }
        }
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:22,代码来源:CCJSqlParserManagerTest.java

示例3: QueryId

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
@Inject
public QueryId(@Assisted String sql, CCJSqlParserManager pm) throws QueryException {
    try {
        Statement stmt = pm.parse(new StringReader(sql));
        if (stmt instanceof Select) {
            this.select = (Select) stmt;
            this.sql = SQL_FORMATTER.format(this.select.toString());
            this.md5 = getMD5(this.sql);
            this.md5Raw = getMD5(sql);
            this.id = QueryFactory.nextUID();
        } else {
            throw new QueryException("Only SELECT statements allowed!");
        }
    } catch (JSQLParserException ex) {
        throw new QueryException(ex.getCause().getMessage());
    }
}
 
开发者ID:valdasraps,项目名称:resthub,代码行数:18,代码来源:QueryId.java

示例4: checkJSqlParserFeature

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
/**
 * To make ddal-jsqlparser work well, JSqlParser should include the feature of 'support getting jdbc parameter index'.
 * And this feature is provided on the version of {@link <a href="https://github.com/JSQLParser/JSqlParser/releases/tag/jsqlparser-0.9.7">0.9.7</a>}.
 * This method is designed to check the necessary feature.
 */
private static void checkJSqlParserFeature() throws JSQLParserException {
    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    String sql = "SELECT * FROM tab_1 WHERE tab_1.col_1 = ? AND col_2 IN (SELECT DISTINCT col_2 FROM tab_2 WHERE col_3 LIKE ? AND col_4 > ?) LIMIT ?, ?";
    Select select = (Select) parserManager.parse(new StringReader(sql));
    PlainSelect selectBody = (PlainSelect) select.getSelectBody();
    //
    AndExpression andExpression = (AndExpression) selectBody.getWhere();
    EqualsTo equalsTo = (EqualsTo) andExpression.getLeftExpression();
    JdbcParameter jdbcParameter = (JdbcParameter) equalsTo.getRightExpression();
    Integer index1 = jdbcParameter.getIndex();
    if (index1 != 1) {
        throw new IllegalStateException("Current version of JSQLParser doesn't support the feature of 'support "
                                        + "get jdbc parameter index'");
    }
    //
    InExpression inExpression = (InExpression) andExpression.getRightExpression();
    SubSelect subSelect = (SubSelect) inExpression.getRightItemsList();
    PlainSelect subSelectBody = (PlainSelect) subSelect.getSelectBody();
    AndExpression subAndExpression = (AndExpression) subSelectBody.getWhere();
    LikeExpression likeExpression = (LikeExpression) subAndExpression.getLeftExpression();
    if (((JdbcParameter) likeExpression.getRightExpression()).getIndex() != 2) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
    //
    GreaterThan greaterThan = (GreaterThan) subAndExpression.getRightExpression();
    if (((JdbcParameter) greaterThan.getRightExpression()).getIndex() != 3) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
    //
    Expression offset = selectBody.getLimit().getOffset();
    Expression rowCount = selectBody.getLimit().getRowCount();
    if (((JdbcParameter) offset).getIndex() != 4 || ((JdbcParameter) rowCount).getIndex() != 5) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
}
 
开发者ID:hellojavaer,项目名称:ddal,代码行数:44,代码来源:JSQLParserAdapter.java

示例5: testInsertOrReplace

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
/**
 * "INSERT OR REPLACE"语法会报错,SqlParser不支持
 *
 * @throws JSQLParserException
 */
@Test(expected = Exception.class)
public void testInsertOrReplace() throws JSQLParserException {
    String sql = "INSERT OR REPLACE INTO \"USER\" (\"_id\",\"UID\",\"NAME\") VALUES (?,?,?)";

    CCJSqlParserManager pm = new CCJSqlParserManager();

    Statement statement = pm.parse(new StringReader(sql));
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:14,代码来源:KbSqlParserTest.java

示例6: ThirdEyeQueryParser

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
public ThirdEyeQueryParser(String sql) throws Exception {
  this.sql = sql;

  CCJSqlParserManager parserManager = new CCJSqlParserManager();
  Statement statement = parserManager.parse(new StringReader(sql));
  ((Select) statement).getSelectBody().accept(this);

  if (query.getStart() == null || query.getEnd() == null) {
    throw new Exception("Must provide BETWEEN clause");
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:12,代码来源:ThirdEyeQueryParser.java

示例7: getStatementFinder

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
/**
* 
* @param sql
* @return
* @throws JSQLParserException
*/
  public static StatementFinder getStatementFinder(String sql) {

      CCJSqlParserManager pm = new CCJSqlParserManager();
      net.sf.jsqlparser.statement.Statement statement = null;
      StatementFinder statementFinder = null;
      try {
          statement = pm.parse(new StringReader(sql));
          if (statement instanceof Select) {
              Select selectStatement = (Select) statement;
              statementFinder = new SelectItemFinder(selectStatement);
          } else if (statement instanceof Insert) {
              Insert insertStatement = (Insert) statement;
              statementFinder = new InsertItemFinder(insertStatement);
          }
          else if (statement instanceof Delete) {
              Delete deleteStatement = (Delete) statement;
              statementFinder = new DeleteItemFinder(deleteStatement);
          } else if (statement instanceof Update) {
              Update updateStatement = (Update) statement;
              statementFinder = new UpdateItemFinder(updateStatement);
          }
      } catch (JSQLParserException e) {
          e.printStackTrace();
          throw new RuntimeException(e);
      }
      return statementFinder;
  }
 
开发者ID:qafedev,项目名称:qafe-platform,代码行数:34,代码来源:StatementFinderFactory.java

示例8: intercept

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
@Test
public void intercept() throws Exception {
    String sql = "INSERT INTO person (id, name) VALUES (1, 'KK')";

    CCJSqlParserManager pm     = new CCJSqlParserManager();
    Insert              insert = (Insert) pm.parse(new StringReader(sql));

    Insert insertProxy = new InsertOrReplaceProxy().getInstance(Insert.class, insert);

    Table table = insertProxy.getTable();

    Assert.assertEquals("person", table.getName());

    String string = insertProxy.toString();

    Assert.assertEquals("INSERT OR REPLACE INTO person (id, name) VALUES (1, 'KK')", string);
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:18,代码来源:InsertOrReplaceProxyTest.java

示例9: main

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
		System.gc();
		System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
		CCJSqlParserManager parserManager = new CCJSqlParserManager();

/*		String longQuery = new String(
			"select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          "
				+ "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           "
				+ "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             "
				+ "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           "
				+ "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
				+ "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
				+ "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
				+ "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
				+ "wct_workflows.active_version_id ))) UNION  SELECT  wct_workflows.workflow_id  as       "
				+ "id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                        "
				+ "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              "
				+ "'W'  or  wct_audit_entry.privilege  =  'C'  )  and  wct_audit_entry.outcome            "
				+ "=  't'  and  wct_audit_entry.transaction_id  =                                         "
				+ "wct_transaction.transaction_id  and  wct_transaction.user_id  = 164 and                "
				+ "afdf=  (  select  wct_audit_entry.object_id  from  wct_audit_entry  ,                  "
				+ "wct_workflow_archive  where  wct_audit_entry.object_id  =                              "
				+ "wct_workflow_archive.archive_id  and  wct_workflows.workflow_id  =                     "
				+ "wct_workflow_archive.workflow_id  )                                                    "
				+ "UNION  SELECT  wct_workflows.workflow_id                                               "
				+ "as  id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                    "
				+ "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              "
				+ "'W'  OR  wct_audit_entry.privilege  =  'E'  OR  wct_audit_entry.privilege  =           "
				+ "'A'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
				+ "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
				+ "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
				+ "wct_workflows.workflow_id    UNION SELECT * FROM interm2  ,  wct_workflow_docs  WHERE  "
				+ "interm2.id  =  wct_workflow_docs.document_id  ORDER BY  id  ,  date  DESC              ");
*/
		String longQuery = new String("select * from k where ID > 4");
		
		
		/*		String longQuery = "select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          "
						+ "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           "
						+ "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             "
						+ "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           "
						+ "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
						+ "'C'  ))))";
*/
/*		String longQuery = "select  *  from  d WHERE                           "
				+ "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
				+ "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
				+ "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
				+ "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
				+ "wct_workflows.active_version_id ";
*/
		StringReader stringReader = new StringReader(longQuery);
	    Statement statement = parserManager.parse(stringReader);
//		stringReader = new StringReader(longQuery);
//		Statement statement2 = parserManager.parse(stringReader);
//		stringReader = null;
		//statement2 = null;
		statement = null;
		parserManager = null;
		longQuery = null;
		System.gc();
		System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());


	}
 
开发者ID:UBOdin,项目名称:jsqlparser,代码行数:66,代码来源:MemoryTest.java

示例10: main

import net.sf.jsqlparser.parser.CCJSqlParserManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
        System.gc();
        System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
        CCJSqlParserManager parserManager = new CCJSqlParserManager();

        /*		String longQuery = new String(
        "select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          "
        + "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           "
        + "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             "
        + "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           "
        + "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
        + "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
        + "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
        + "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
        + "wct_workflows.active_version_id ))) UNION  SELECT  wct_workflows.workflow_id  as       "
        + "id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                        "
        + "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              "
        + "'W'  or  wct_audit_entry.privilege  =  'C'  )  and  wct_audit_entry.outcome            "
        + "=  't'  and  wct_audit_entry.transaction_id  =                                         "
        + "wct_transaction.transaction_id  and  wct_transaction.user_id  = 164 and                "
        + "afdf=  (  select  wct_audit_entry.object_id  from  wct_audit_entry  ,                  "
        + "wct_workflow_archive  where  wct_audit_entry.object_id  =                              "
        + "wct_workflow_archive.archive_id  and  wct_workflows.workflow_id  =                     "
        + "wct_workflow_archive.workflow_id  )                                                    "
        + "UNION  SELECT  wct_workflows.workflow_id                                               "
        + "as  id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                    "
        + "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              "
        + "'W'  OR  wct_audit_entry.privilege  =  'E'  OR  wct_audit_entry.privilege  =           "
        + "'A'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
        + "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
        + "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
        + "wct_workflows.workflow_id    UNION SELECT * FROM interm2  ,  wct_workflow_docs  WHERE  "
        + "interm2.id  =  wct_workflow_docs.document_id  ORDER BY  id  ,  date  DESC              ");
         */
        String longQuery = "select * from k where ID > 4";


        /*		String longQuery = "select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          "
        + "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           "
        + "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             "
        + "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           "
        + "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
        + "'C'  ))))";
         */
        /*		String longQuery = "select  *  from  d WHERE                           "
        + "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 "
        + "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      "
        + "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 "
        + "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       "
        + "wct_workflows.active_version_id ";
         */
        StringReader stringReader = new StringReader(longQuery);
        Statement statement = parserManager.parse(stringReader);
//		stringReader = new StringReader(longQuery);
//		Statement statement2 = parserManager.parse(stringReader);
//		stringReader = null;
        //statement2 = null;
        statement = null;
        parserManager = null;
        longQuery = null;
        System.gc();
        System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
    }
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:64,代码来源:MemoryTest.java


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