Java Code Examples for org.apache.oro.text.regex.Perl5Matcher#matches()

The following examples show how to use org.apache.oro.text.regex.Perl5Matcher#matches() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 6 votes vote down vote up
private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);

        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String names[] = StringUtils.split(tableString, ".");
        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }

    return null;
}
 
Example 2
Source File: FileUtils.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
private static List<File> listFiles(File dir, Pattern _pattern, boolean _recurse, int listType) {
	File[] files = (_pattern == null ? dir.listFiles() : listFiles(dir, _pattern, listType));
	List<File> filesList = new ArrayList<File>();
	Perl5Matcher matcher = ( _pattern == null ? null : new Perl5Matcher() );

	if (files != null) {
		for (int i = 0; i < files.length; i++) {
			boolean isDir = files[i].isDirectory();

			if (isDir && _recurse) {
				filesList.addAll(listFiles(files[i], _pattern, _recurse, listType));
			}

			if ((listType == LIST_TYPE_DIR && !isDir) || (listType == LIST_TYPE_FILE && isDir))
				continue;

			if ( _pattern == null || matcher.matches( files[i].getName(), _pattern ) ){
				filesList.add(files[i]);
			}
		}
	}
	return filesList;
}
 
Example 3
Source File: SimpleDdlParser.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);
        if (StringUtils.isEmpty(tableString)) {
            return null;
        }

        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String names[] = StringUtils.split(tableString, ".");
        if (names.length == 0) {
            return null;
        }

        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }

    return null;
}
 
Example 4
Source File: RegexFunction.java    From canal with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}
 
Example 5
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);
        if (StringUtils.isEmpty(tableString)) {
            return null;
        }

        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String names[] = StringUtils.split(tableString, ".");
        if (names.length == 0) {
            return null;
        }

        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }

    return null;
}
 
Example 6
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
        DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
        if (orign != null && target != null) {
            return new DdlResult(target.getSchemaName(),
                target.getTableName(),
                orign.getSchemaName(),
                orign.getTableName());
        }
    }

    return null;
}
 
Example 7
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static boolean isDml(String queryString, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        return true;
    } else {
        return false;
    }
}
 
Example 8
Source File: SimpleDdlParser.java    From canal with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName);
        return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理
    }

    return null;
}
 
Example 9
Source File: RegexFunction.java    From canal with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}
 
Example 10
Source File: RegexFunction.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}
 
Example 11
Source File: RegexFunction.java    From binlake with Apache License 2.0 5 votes vote down vote up
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String pattern = FunctionUtils.getStringValue(arg1, env);
    String text = FunctionUtils.getStringValue(arg2, env);
    Perl5Matcher matcher = new Perl5Matcher();
    boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
    return AviatorBoolean.valueOf(isMatch);
}
 
Example 12
Source File: SimpleDdlParser.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
        DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
        if (orign != null && target != null) {
            return new DdlResult(target.getSchemaName(),
                target.getTableName(),
                orign.getSchemaName(),
                orign.getTableName());
        }
    }

    return null;
}
 
Example 13
Source File: SimpleDdlParser.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private static boolean isDml(String queryString, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        return true;
    } else {
        return false;
    }
}
 
Example 14
Source File: SimpleDdlParser.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName);
        return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理
    }

    return null;
}
 
Example 15
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
        DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
        if (orign != null && target != null) {
            return new DdlResult(target.getSchemaName(),
                    target.getTableName(),
                    orign.getSchemaName(),
                    orign.getTableName());
        }
    }

    return null;
}
 
Example 16
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 5 votes vote down vote up
private static boolean isDml(String queryString, String pattern) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        return true;
    } else {
        return false;
    }
}
 
Example 17
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 5 votes vote down vote up
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) {
    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
        DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName);
        return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理
    }

    return null;
}
 
Example 18
Source File: SimpleDdlParser.java    From binlake with Apache License 2.0 4 votes vote down vote up
public static DdlResult parse(String queryString, String schmeaName) {
    queryString = removeComment(queryString); // 去除/* */的sql注释内容
    DdlResult result = parseDdl(queryString, schmeaName, ALERT_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.ALTER);
        return result;
    }

    result = parseDdl(queryString, schmeaName, CREATE_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.CREATE);
        return result;
    }

    result = parseDdl(queryString, schmeaName, DROP_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.ERASE);
        return result;
    }

    result = parseDdl(queryString, schmeaName, TRUNCATE_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.TRUNCATE);
        return result;
    }

    Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.matches(queryString, PatternUtils.getPattern(RENAME_PATTERN))) {
        String[] renameSqls = queryString.split(",");
        List<DdlResult> rsts = new LinkedList<DdlResult>();
        switch (renameSqls.length) {
            case 0:
                break;
            case 1:
                addRenameDDlResult(queryString, schmeaName, rsts);
                if (rsts.size() != 0) {
                    rsts.get(0).rsts = rsts;
                    return rsts.get(0);
                }

                break;
            default:
                addRenameDDlResult(renameSqls[0], schmeaName, rsts);

                for (int index = 1; index < renameSqls.length; index++) {
                    addRenameDDlResult("RENAME TABLE " + renameSqls[index], schmeaName, rsts);
                }
                if (rsts.size() != 0) {
                    rsts.get(0).rsts = rsts;
                    return rsts.get(0);
                }
                break;
        }
    }

    result = parseDdl(queryString, schmeaName, CREATE_INDEX_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.CINDEX);
        return result;
    }

    result = parseDdl(queryString, schmeaName, DROP_INDEX_PATTERN, 2);
    if (result != null) {
        result.setType(WaveEntry.EventType.DINDEX);
        return result;
    }

    result = new DdlResult(schmeaName);
    if (isDml(queryString, INSERT_PATTERN)) {
        result.setType(WaveEntry.EventType.INSERT);
        return result;
    }

    if (isDml(queryString, UPDATE_PATTERN)) {
        result.setType(WaveEntry.EventType.UPDATE);
        return result;
    }

    if (isDml(queryString, DELETE_PATTERN)) {
        result.setType(WaveEntry.EventType.DELETE);
        return result;
    }

    result.setType(WaveEntry.EventType.QUERY);
    return result;
}