Search in sources :

Example 1 with IgnoreKeyCaseMap

use of org.sagacity.sqltoy.model.IgnoreKeyCaseMap in project sagacity-sqltoy by chenrenfei.

the class SqlLoopTest method testSqlLoopStr.

@Test
public void testSqlLoopStr() {
    List<String> staffInfos = new ArrayList<String>();
    for (int i = 0; i < 5; i++) {
        staffInfos.add("S000" + (i + 1));
    }
    SqlLoop sqlLoop = new SqlLoop();
    String[] params = { "staffInfos", " and staffId=':staffInfos[i]'" };
    IgnoreKeyCaseMap<String, Object> keyValues = new IgnoreKeyCaseMap<String, Object>();
    keyValues.put("staffInfos", staffInfos);
    String result = sqlLoop.execute(params, keyValues);
    System.err.print(result);
}
Also used : ArrayList(java.util.ArrayList) SqlLoop(org.sagacity.sqltoy.plugins.id.macro.impl.SqlLoop) IgnoreKeyCaseMap(org.sagacity.sqltoy.model.IgnoreKeyCaseMap) Test(org.junit.jupiter.api.Test)

Example 2 with IgnoreKeyCaseMap

use of org.sagacity.sqltoy.model.IgnoreKeyCaseMap in project sagacity-sqltoy by chenrenfei.

the class SqlLoopTest method testSqlLoop.

@Test
public void testSqlLoop() {
    List<StaffInfoVO> staffInfos = new ArrayList<StaffInfoVO>();
    for (int i = 0; i < 5; i++) {
        StaffInfoVO staff = new StaffInfoVO();
        staff.setStaffId("S000" + (i + 1));
        staff.setBirthday(LocalDate.now());
        staffInfos.add(staff);
    }
    SqlLoop sqlLoop = new SqlLoop();
    String[] params = { "staffInfos", "(staffId=':staffInfos[i].staffId' and birthDay=':staffInfos[i].birthday')", "or" };
    IgnoreKeyCaseMap<String, Object> keyValues = new IgnoreKeyCaseMap<String, Object>();
    keyValues.put("staffInfos", staffInfos);
    String result = sqlLoop.execute(params, keyValues);
    System.err.print(result);
}
Also used : ArrayList(java.util.ArrayList) StaffInfoVO(org.sagacity.sqltoy.demo.vo.StaffInfoVO) SqlLoop(org.sagacity.sqltoy.plugins.id.macro.impl.SqlLoop) IgnoreKeyCaseMap(org.sagacity.sqltoy.model.IgnoreKeyCaseMap) Test(org.junit.jupiter.api.Test)

Example 3 with IgnoreKeyCaseMap

use of org.sagacity.sqltoy.model.IgnoreKeyCaseMap in project sagacity-sqltoy by chenrenfei.

the class SqlLoopTest method testSqlLoopLike.

@Test
public void testSqlLoopLike() {
    List<String> staffInfos = new ArrayList<String>();
    for (int i = 0; i < 5; i++) {
        staffInfos.add("S000" + (i + 1));
    }
    SqlLoop sqlLoop = new SqlLoop();
    String[] params = { "staffInfos", " and staffId like '%:staffInfos[i]%'" };
    IgnoreKeyCaseMap<String, Object> keyValues = new IgnoreKeyCaseMap<String, Object>();
    keyValues.put("staffInfos", staffInfos);
    String result = sqlLoop.execute(params, keyValues);
    System.err.print(result);
}
Also used : ArrayList(java.util.ArrayList) SqlLoop(org.sagacity.sqltoy.plugins.id.macro.impl.SqlLoop) IgnoreKeyCaseMap(org.sagacity.sqltoy.model.IgnoreKeyCaseMap) Test(org.junit.jupiter.api.Test)

Example 4 with IgnoreKeyCaseMap

use of org.sagacity.sqltoy.model.IgnoreKeyCaseMap in project sagacity-sqltoy by chenrenfei.

the class BeanUtilTest method testMap.

@Test
public void testMap() {
    HashMap params = new HashMap();
    params.put("companyId", "C0001");
    params.put("companyName", null);
    IgnoreKeyCaseMap map = new IgnoreKeyCaseMap(params);
    System.err.println(((Map) map).get("companyId"));
}
Also used : HashMap(java.util.HashMap) IgnoreKeyCaseMap(org.sagacity.sqltoy.model.IgnoreKeyCaseMap) Test(org.junit.jupiter.api.Test)

Example 5 with IgnoreKeyCaseMap

use of org.sagacity.sqltoy.model.IgnoreKeyCaseMap in project sagacity-sqltoy by chenrenfei.

the class MacroUtilsTest method testReplaceMacros1.

@Test
public void testReplaceMacros1() {
    Map<String, AbstractMacro> macros = new HashMap<String, AbstractMacro>();
    macros.put("@loop", new SqlLoop());
    String sql = "select * from table where 1=1 @loop(:startDates,' (bizDate between str_to_date(':startDates[i]','%Y-%m-%d') and str_to_date(':endDates[i]','%Y-%m-%d')','or')";
    String[] paramsNamed = { "startDates", "endDates" };
    String[][] paramsValue = { { "2020-10-01", "2020-11-01", "2020-12-01" }, { "2020-10-30", "2020-11-30", "2020-12-30" } };
    IgnoreKeyCaseMap<String, Object> keyValues = new IgnoreKeyCaseMap<String, Object>();
    for (int i = 0; i < paramsNamed.length; i++) {
        keyValues.put(paramsNamed[i], paramsValue[i]);
    }
    String result = MacroUtils.replaceMacros(sql, keyValues, false, macros);
    System.err.println(result);
}
Also used : AbstractMacro(org.sagacity.sqltoy.plugins.id.macro.AbstractMacro) HashMap(java.util.HashMap) SqlLoop(org.sagacity.sqltoy.plugins.id.macro.impl.SqlLoop) IgnoreKeyCaseMap(org.sagacity.sqltoy.model.IgnoreKeyCaseMap) Test(org.junit.jupiter.api.Test)

Aggregations

IgnoreKeyCaseMap (org.sagacity.sqltoy.model.IgnoreKeyCaseMap)13 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 SqlLoop (org.sagacity.sqltoy.plugins.id.macro.impl.SqlLoop)5 Map (java.util.Map)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 TableCascadeModel (org.sagacity.sqltoy.config.model.TableCascadeModel)2 StaffInfoVO (org.sagacity.sqltoy.demo.vo.StaffInfoVO)2 ReverseList (org.sagacity.sqltoy.plugins.calculator.ReverseList)2 UnpivotList (org.sagacity.sqltoy.plugins.calculator.UnpivotList)2 AbstractMacro (org.sagacity.sqltoy.plugins.id.macro.AbstractMacro)2 Method (java.lang.reflect.Method)1 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)1