diff --git a/src/test/java/cn/com/tenlion/usercenter/JSqlParserTest.java b/src/test/java/cn/com/tenlion/usercenter/JSqlParserTest.java new file mode 100644 index 0000000..ffcad20 --- /dev/null +++ b/src/test/java/cn/com/tenlion/usercenter/JSqlParserTest.java @@ -0,0 +1,76 @@ +package cn.com.tenlion.usercenter; + +import com.alibaba.druid.pool.DruidDataSource; +import net.sf.jsqlparser.expression.Alias; +import net.sf.jsqlparser.expression.StringValue; +import net.sf.jsqlparser.expression.operators.conditional.AndExpression; +import net.sf.jsqlparser.expression.operators.relational.Between; +import net.sf.jsqlparser.expression.operators.relational.EqualsTo; +import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.Select; +import net.sf.jsqlparser.statement.select.WithItem; +import net.sf.jsqlparser.util.SelectUtils; +import org.apache.ibatis.mapping.Environment; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; +import org.apache.ibatis.transaction.TransactionFactory; +import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; +import org.apache.poi.ss.formula.functions.T; +import org.checkerframework.checker.units.qual.A; +import org.junit.Test; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; + +public class JSqlParserTest { + + @Test + public void t1() { + + Select select1 = SelectUtils.buildSelectFromTable(new Table("xxx")); + System.out.println(select1); + } + + @Test + public void t2() { + Table t1 = new Table("t1"); + Column c1 = new Column("c1"); + Column c2 = new Column("c2"); + Select select2 = SelectUtils.buildSelectFromTableAndExpressions(t1, c1, c2); + System.out.println(select2); + } + + @Test + public void t3() { + Table t1 = new Table("t1").withAlias(new Alias("t")); + Select s1 = SelectUtils.buildSelectFromTable(t1); + + EqualsTo eq1 = new EqualsTo(); + eq1.setLeftExpression(new Column("c1")); + eq1.setRightExpression(new StringValue("v1")); + + EqualsTo eq2 = new EqualsTo(); + eq2.setLeftExpression(new Column("c2")); + eq2.setRightExpression(new StringValue("v2")); + + AndExpression andExpression = new AndExpression(); + andExpression.setLeftExpression(eq1); + andExpression.setRightExpression(eq2); + +// PlainSelect plainSelect = s1.getPlainSelect(); +// plainSelect.setWhere(andExpression); +// System.out.println(plainSelect); + } + + @Test + public void t4() { + DataSource dataSource = new DruidDataSource(); + TransactionFactory transactionFactory = new JdbcTransactionFactory(); + Environment environment = new Environment("prod", transactionFactory, dataSource); + Configuration configuration = new Configuration(environment); + } + +}