sqlParamList;
-
- /**
- * init param according the sql
- */
- private TSDBPreparedParam initPreparedParam;
-
- /**
- * is table name dynamic in the prepared sql
- */
- private boolean isTableNameDynamic;
-
- /**
- * insert or import sql template pattern, the template are the following:
- *
- * insert/import into tableName [(field1, field2, ...)] [using stables tags(?, ?, ...) ] values(?, ?, ...) (?, ?, ...)
- *
- * we split it to three part:
- * 1. prefix, insert/import
- * 2. middle, tableName [(field1, field2, ...)] [using stables tags(?, ?, ...) ]
- * 3. valueList, the content after values, for example (?, ?, ...) (?, ?, ...)
- */
- private Pattern sqlPattern = Pattern.compile("(?s)(?i)^\\s*(INSERT|IMPORT)\\s+INTO\\s+((?\\S+)\\s*(\\(.*\\))?\\s+(USING\\s+(?\\S+)\\s+TAGS\\s*\\((?.+)\\))?)\\s*VALUES\\s*(?\\(.*\\)).*");
-
- /**
- * the raw sql template
- */
- private String sql;
-
- /**
- * the prefix part of sql
- */
- private String prefix;
-
- /**
- * the middle part of sql
- */
- private String middle;
-
- private int middleParamSize;
-
- /**
- * the valueList part of sql
- */
- private String valueList;
-
- private int valueListSize;
-
- /**
- * default param value
- */
- private static final String DEFAULT_VALUE = "NULL";
-
- private static final String PLACEHOLDER = "?";
-
- private String tableName;
-
- /**
- * is the parameter add to batch list
- */
- private boolean isAddBatch;
-
- public SavedPreparedStatement(String sql, TSDBPreparedStatement tsdbPreparedStatement) throws SQLException {
- this.sql = sql;
- this.tsdbPreparedStatement = tsdbPreparedStatement;
- this.sqlParamList = new ArrayList<>();
-
- parsePreparedParam(this.sql);
- }
-
- /**
- * parse the init param according the sql param
- *
- * @param sql
- */
- private void parsePreparedParam(String sql) throws SQLException {
-
- Matcher matcher = sqlPattern.matcher(sql);
-
- if (matcher.find()) {
-
- tableName = matcher.group("tablename");
-
- if (tableName != null && PLACEHOLDER.equals(tableName)) {
- // the table name is dynamic
- this.isTableNameDynamic = true;
- }
-
- prefix = matcher.group(1);
- middle = matcher.group(2);
- valueList = matcher.group("valueList");
-
- if (middle != null && !"".equals(middle)) {
- middleParamSize = parsePlaceholder(middle);
- }
-
- if (valueList != null && !"".equals(valueList)) {
- valueListSize = parsePlaceholder(valueList);
- }
-
- initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize);
-
- } else {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
- }
-
- }
-
- private TSDBPreparedParam initDefaultParam(String tableName, int middleParamSize, int valueListSize) {
-
- TSDBPreparedParam tsdbPreparedParam = new TSDBPreparedParam(tableName);
-
- tsdbPreparedParam.setMiddleParamList(getDefaultParamList(middleParamSize));
-
- tsdbPreparedParam.setValueList(getDefaultParamList(valueListSize));
-
- return tsdbPreparedParam;
- }
-
- /**
- * generate the default param value list
- *
- * @param paramSize
- * @return
- */
- private List