Search in sources :

Example 1 with Function

use of org.h2.expression.Function in project Gargoyle by callakrsos.

the class FileSearcher method listClases.

public static List<ProjectInfo> listClases(String classDirName) throws Exception {
    File file = new File(classDirName);
    // 기본적인 파일의 존재유무 및 디렉토리인지 체크.
    if (!file.exists())
        throw new FileNotFoundException(file + " Not found!");
    //
    if (!file.isDirectory())
        throw new IllegalArgumentException("only directory.");
    /*
		 * 디렉토리안에 클래스패스 정보가 존재하는지 확인하고 존재한다면 classpath에 기술된 정보 기준으로 클래스 파일을
		 * 로드한다. 프로그램내에서 workspace를 선택한 경우일수있고, 프로젝트를 선택한 두가지의 경우가 있기때문에 두가지의
		 * 케이스를 고려한 로직이 들어간다.
		 */
    /*
		 * 일단 워크스페이스를 선택한경우라고 가정하고 워크스페이스내에 폴더들을 순차적으로 돌아보면서 classpath의 존재유무를 찾고
		 * 존재하는케이스는 따로 모아놓는다. 파일레벨은 워크스페이스(0레벨)-프로젝트(1레벨)로 가정하여 1레벨까지만 이동한다.
		 */
    List<File> listFiles = findClassPaths(file);
    /*
		 * classpath파일을 찾은경우 그 파일path를 기준으로 클래스들을 로딩한다.
		 */
    List<ProjectInfo> allClasses = new ArrayList<>();
    if (listFiles != null && !listFiles.isEmpty())
        LOGGER.debug(" im will working...");
    long startTime = System.currentTimeMillis();
    int searchedDirCount = 0;
    StringBuffer srchedDirNames = new StringBuffer();
    for (File f : listFiles) {
        try {
            ClassPath parsingClassPath = parsingClassPath(f.getAbsolutePath());
            // 프로젝트파일.
            File projectFile = f.getParentFile();
            // output 속성값의 존재유무만 확인하여 컴파일되는 경로를 찾는다.
            List<ProjectInfo> collect = parsingClassPath.toStream().filter(entry -> {
                boolean notEmpty = ValueUtil.isNotEmpty(entry.getOutput());
                LOGGER.debug(String.format("srch entry path : %s is Traget %b ", entry.getPath(), notEmpty));
                return notEmpty;
            }).map(pram -> pram.getOutput()).distinct().parallel().flatMap(new Function<String, Stream<ProjectInfo>>() {

                @Override
                public Stream<ProjectInfo> apply(String entry) {
                    LOGGER.debug(String.format("entry : %s", entry));
                    File compiledFilePath = new File(projectFile, entry);
                    int length = compiledFilePath.getAbsolutePath().length() + 1;
                    List<String> findClases = findClases(projectFile.getAbsolutePath(), compiledFilePath, length);
                    LOGGER.debug(compiledFilePath.toString());
                    LOGGER.debug(findClases.toString());
                    LOGGER.debug(String.valueOf(findClases.size()));
                    ProjectInfo classInfo = new ProjectInfo();
                    classInfo.setProjectName(projectFile.getName());
                    classInfo.setProjectDir(compiledFilePath.getAbsolutePath());
                    classInfo.setClasses(findClases);
                    return Stream.of(classInfo);
                }
            }).collect(Collectors.toList());
            allClasses.addAll(collect);
            searchedDirCount++;
            srchedDirNames.append(f.getAbsolutePath()).append(SystemUtils.LINE_SEPARATOR);
        } catch (SAXParseException e) {
            LOGGER.error(String.format("정상적인 XML 형태가 아님. 파일명 :  %s", f.getAbsolutePath()));
            LOGGER.error(String.format("%d 행 :: %d 열", e.getLineNumber(), e.getColumnNumber()));
        }
    }
    long endTime = System.currentTimeMillis();
    long costMillisend = endTime - startTime;
    LOGGER.debug(String.format("Total Cost time : %s (ms) searched Directory Count : %d ", costMillisend, searchedDirCount));
    LOGGER.debug(String.format("Searched Dirs info \n%s", srchedDirNames.toString()));
    return allClasses;
}
Also used : URL(java.net.URL) ZipUtil(com.kyj.fx.voeditor.visual.util.ZipUtil) LoggerFactory(org.slf4j.LoggerFactory) Function(java.util.function.Function) Supplier(java.util.function.Supplier) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) NamedNodeMap(org.w3c.dom.NamedNodeMap) Method(java.lang.reflect.Method) SystemUtils(org.apache.commons.lang.SystemUtils) ClassPathEntry(com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry) InputSource(org.xml.sax.InputSource) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) MalformedURLException(java.net.MalformedURLException) Predicate(java.util.function.Predicate) ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) FileInputStream(java.io.FileInputStream) Reader(java.io.Reader) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StringUtils(org.h2.util.StringUtils) List(java.util.List) SAXParseException(org.xml.sax.SAXParseException) Stream(java.util.stream.Stream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileTypeMap(javax.activation.FileTypeMap) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Function(java.util.function.Function) SAXParseException(org.xml.sax.SAXParseException) File(java.io.File)

Example 2 with Function

use of org.h2.expression.Function in project h2database by h2database.

the class Parser method readConcat.

private Expression readConcat() {
    Expression r = readSum();
    while (true) {
        if (readIf("||")) {
            r = new Operation(OpType.CONCAT, r, readSum());
        } else if (readIf("~")) {
            if (readIf("*")) {
                Function function = Function.getFunction(database, "CAST");
                function.setDataType(new Column("X", Value.STRING_IGNORECASE));
                function.setParameter(0, r);
                r = function;
            }
            r = new CompareLike(database, r, readSum(), null, true);
        } else if (readIf("!~")) {
            if (readIf("*")) {
                Function function = Function.getFunction(database, "CAST");
                function.setDataType(new Column("X", Value.STRING_IGNORECASE));
                function.setParameter(0, r);
                r = function;
            }
            r = new ConditionNot(new CompareLike(database, r, readSum(), null, true));
        } else {
            return r;
        }
    }
}
Also used : Function(org.h2.expression.Function) TableFunction(org.h2.expression.TableFunction) JavaFunction(org.h2.expression.JavaFunction) ConditionNot(org.h2.expression.ConditionNot) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Operation(org.h2.expression.Operation) NoOperation(org.h2.command.dml.NoOperation) CompareLike(org.h2.expression.CompareLike)

Example 3 with Function

use of org.h2.expression.Function in project h2database by h2database.

the class Parser method readTerm.

private Expression readTerm() {
    Expression r;
    switch(currentTokenType) {
        case AT:
            read();
            r = new Variable(session, readAliasIdentifier());
            if (readIf(":=")) {
                Expression value = readExpression();
                Function function = Function.getFunction(database, "SET");
                function.setParameter(0, r);
                function.setParameter(1, value);
                r = function;
            }
            break;
        case PARAMETER:
            r = readParameter();
            break;
        case KEYWORD:
            if (isToken("SELECT") || isToken("FROM") || isToken("WITH")) {
                Query query = parseSelect();
                r = new Subquery(query);
            } else {
                throw getSyntaxError();
            }
            break;
        case IDENTIFIER:
            String name = currentToken;
            if (currentTokenQuoted) {
                read();
                if (readIf("(")) {
                    r = readFunction(null, name);
                } else if (readIf(".")) {
                    r = readTermObjectDot(name);
                } else {
                    r = new ExpressionColumn(database, null, null, name);
                }
            } else {
                read();
                if (readIf(".")) {
                    r = readTermObjectDot(name);
                } else if (equalsToken("CASE", name)) {
                    // CASE must be processed before (,
                    // otherwise CASE(3) would be a function call, which it is
                    // not
                    r = readCase();
                } else if (readIf("(")) {
                    r = readFunction(null, name);
                } else if (equalsToken("CURRENT_USER", name)) {
                    r = readFunctionWithoutParameters("USER");
                } else if (equalsToken("CURRENT_TIMESTAMP", name)) {
                    r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
                } else if (equalsToken("SYSDATE", name)) {
                    r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
                } else if (equalsToken("SYSTIMESTAMP", name)) {
                    r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
                } else if (equalsToken("CURRENT_DATE", name)) {
                    r = readFunctionWithoutParameters("CURRENT_DATE");
                } else if (equalsToken("TODAY", name)) {
                    r = readFunctionWithoutParameters("CURRENT_DATE");
                } else if (equalsToken("CURRENT_TIME", name)) {
                    r = readFunctionWithoutParameters("CURRENT_TIME");
                } else if (equalsToken("SYSTIME", name)) {
                    r = readFunctionWithoutParameters("CURRENT_TIME");
                } else if (equalsToken("CURRENT", name)) {
                    if (readIf("TIMESTAMP")) {
                        r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
                    } else if (readIf("TIME")) {
                        r = readFunctionWithoutParameters("CURRENT_TIME");
                    } else if (readIf("DATE")) {
                        r = readFunctionWithoutParameters("CURRENT_DATE");
                    } else {
                        r = new ExpressionColumn(database, null, null, name);
                    }
                } else if (equalsToken("NEXT", name) && readIf("VALUE")) {
                    read("FOR");
                    Sequence sequence = readSequence();
                    r = new SequenceValue(sequence);
                } else if (equalsToken("TIME", name)) {
                    boolean without = readIf("WITHOUT");
                    if (without) {
                        read("TIME");
                        read("ZONE");
                    }
                    if (currentTokenType != VALUE || currentValue.getType() != Value.STRING) {
                        if (without) {
                            throw getSyntaxError();
                        }
                        r = new ExpressionColumn(database, null, null, name);
                    } else {
                        String time = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueTime.parse(time));
                    }
                } else if (equalsToken("TIMESTAMP", name)) {
                    if (readIf("WITH")) {
                        read("TIME");
                        read("ZONE");
                        if (currentTokenType != VALUE || currentValue.getType() != Value.STRING) {
                            throw getSyntaxError();
                        }
                        String timestamp = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueTimestampTimeZone.parse(timestamp));
                    } else {
                        boolean without = readIf("WITHOUT");
                        if (without) {
                            read("TIME");
                            read("ZONE");
                        }
                        if (currentTokenType != VALUE || currentValue.getType() != Value.STRING) {
                            if (without) {
                                throw getSyntaxError();
                            }
                            r = new ExpressionColumn(database, null, null, name);
                        } else {
                            String timestamp = currentValue.getString();
                            read();
                            r = ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
                        }
                    }
                } else if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
                    if (equalsToken("DATE", name) || equalsToken("D", name)) {
                        String date = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueDate.parse(date));
                    } else if (equalsToken("T", name)) {
                        String time = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueTime.parse(time));
                    } else if (equalsToken("TS", name)) {
                        String timestamp = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
                    } else if (equalsToken("X", name)) {
                        read();
                        byte[] buffer = StringUtils.convertHexToBytes(currentValue.getString());
                        r = ValueExpression.get(ValueBytes.getNoCopy(buffer));
                    } else if (equalsToken("E", name)) {
                        String text = currentValue.getString();
                        // the PostgreSQL ODBC driver uses
                        // LIKE E'PROJECT\\_DATA' instead of LIKE
                        // 'PROJECT\_DATA'
                        // N: SQL-92 "National Language" strings
                        text = StringUtils.replaceAll(text, "\\\\", "\\");
                        read();
                        r = ValueExpression.get(ValueString.get(text));
                    } else if (equalsToken("N", name)) {
                        // SQL-92 "National Language" strings
                        String text = currentValue.getString();
                        read();
                        r = ValueExpression.get(ValueString.get(text));
                    } else {
                        r = new ExpressionColumn(database, null, null, name);
                    }
                } else {
                    r = new ExpressionColumn(database, null, null, name);
                }
            }
            break;
        case MINUS:
            read();
            if (currentTokenType == VALUE) {
                r = ValueExpression.get(currentValue.negate());
                if (r.getType() == Value.LONG && r.getValue(session).getLong() == Integer.MIN_VALUE) {
                    // convert Integer.MIN_VALUE to type 'int'
                    // (Integer.MAX_VALUE+1 is of type 'long')
                    r = ValueExpression.get(ValueInt.get(Integer.MIN_VALUE));
                } else if (r.getType() == Value.DECIMAL && r.getValue(session).getBigDecimal().compareTo(ValueLong.MIN_BD) == 0) {
                    // convert Long.MIN_VALUE to type 'long'
                    // (Long.MAX_VALUE+1 is of type 'decimal')
                    r = ValueExpression.get(ValueLong.MIN);
                }
                read();
            } else {
                r = new Operation(OpType.NEGATE, readTerm(), null);
            }
            break;
        case PLUS:
            read();
            r = readTerm();
            break;
        case OPEN:
            read();
            if (readIf(")")) {
                r = new ExpressionList(new Expression[0]);
            } else {
                r = readExpression();
                if (readIf(",")) {
                    ArrayList<Expression> list = New.arrayList();
                    list.add(r);
                    while (!readIf(")")) {
                        r = readExpression();
                        list.add(r);
                        if (!readIf(",")) {
                            read(")");
                            break;
                        }
                    }
                    r = new ExpressionList(list.toArray(new Expression[0]));
                } else {
                    read(")");
                }
            }
            break;
        case TRUE:
            read();
            r = ValueExpression.get(ValueBoolean.TRUE);
            break;
        case FALSE:
            read();
            r = ValueExpression.get(ValueBoolean.FALSE);
            break;
        case ROWNUM:
            read();
            if (readIf("(")) {
                read(")");
            }
            if (currentSelect == null && currentPrepared == null) {
                throw getSyntaxError();
            }
            r = new Rownum(currentSelect == null ? currentPrepared : currentSelect);
            break;
        case NULL:
            read();
            r = ValueExpression.getNull();
            break;
        case VALUE:
            r = ValueExpression.get(currentValue);
            read();
            break;
        default:
            throw getSyntaxError();
    }
    if (readIf("[")) {
        Function function = Function.getFunction(database, "ARRAY_GET");
        function.setParameter(0, r);
        r = readExpression();
        r = new Operation(OpType.PLUS, r, ValueExpression.get(ValueInt.get(1)));
        function.setParameter(1, r);
        r = function;
        read("]");
    }
    if (readIf("::")) {
        // PostgreSQL compatibility
        if (isToken("PG_CATALOG")) {
            read("PG_CATALOG");
            read(".");
        }
        if (readIf("REGCLASS")) {
            FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN, "PG_GET_OID");
            if (f == null) {
                throw getSyntaxError();
            }
            Expression[] args = { r };
            r = new JavaFunction(f, args);
        } else {
            Column col = parseColumnWithType(null);
            Function function = Function.getFunction(database, "CAST");
            function.setDataType(col);
            function.setParameter(0, r);
            r = function;
        }
    }
    return r;
}
Also used : Variable(org.h2.expression.Variable) Query(org.h2.command.dml.Query) CreateFunctionAlias(org.h2.command.ddl.CreateFunctionAlias) FunctionAlias(org.h2.engine.FunctionAlias) DropFunctionAlias(org.h2.command.ddl.DropFunctionAlias) JavaFunction(org.h2.expression.JavaFunction) ValueString(org.h2.value.ValueString) DropSequence(org.h2.command.ddl.DropSequence) CreateSequence(org.h2.command.ddl.CreateSequence) Sequence(org.h2.schema.Sequence) AlterSequence(org.h2.command.dml.AlterSequence) Operation(org.h2.expression.Operation) NoOperation(org.h2.command.dml.NoOperation) Subquery(org.h2.expression.Subquery) Rownum(org.h2.expression.Rownum) ExpressionColumn(org.h2.expression.ExpressionColumn) Function(org.h2.expression.Function) TableFunction(org.h2.expression.TableFunction) JavaFunction(org.h2.expression.JavaFunction) SequenceValue(org.h2.expression.SequenceValue) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) ExpressionList(org.h2.expression.ExpressionList)

Example 4 with Function

use of org.h2.expression.Function in project h2database by h2database.

the class Parser method readFunctionWithoutParameters.

private Expression readFunctionWithoutParameters(String name) {
    if (readIf("(")) {
        read(")");
    }
    if (database.isAllowBuiltinAliasOverride()) {
        FunctionAlias functionAlias = database.getSchema(session.getCurrentSchemaName()).findFunction(name);
        if (functionAlias != null) {
            return new JavaFunction(functionAlias, new Expression[0]);
        }
    }
    Function function = Function.getFunction(database, name);
    function.doneWithParameters();
    return function;
}
Also used : Function(org.h2.expression.Function) TableFunction(org.h2.expression.TableFunction) JavaFunction(org.h2.expression.JavaFunction) CreateFunctionAlias(org.h2.command.ddl.CreateFunctionAlias) FunctionAlias(org.h2.engine.FunctionAlias) DropFunctionAlias(org.h2.command.ddl.DropFunctionAlias) JavaFunction(org.h2.expression.JavaFunction)

Example 5 with Function

use of org.h2.expression.Function in project h2database by h2database.

the class Parser method readCase.

private Expression readCase() {
    if (readIf("END")) {
        readIf("CASE");
        return ValueExpression.getNull();
    }
    if (readIf("ELSE")) {
        Expression elsePart = readExpression().optimize(session);
        read("END");
        readIf("CASE");
        return elsePart;
    }
    int i;
    Function function;
    if (readIf("WHEN")) {
        function = Function.getFunction(database, "CASE");
        function.setParameter(0, null);
        i = 1;
        do {
            function.setParameter(i++, readExpression());
            read("THEN");
            function.setParameter(i++, readExpression());
        } while (readIf("WHEN"));
    } else {
        Expression expr = readExpression();
        if (readIf("END")) {
            readIf("CASE");
            return ValueExpression.getNull();
        }
        if (readIf("ELSE")) {
            Expression elsePart = readExpression().optimize(session);
            read("END");
            readIf("CASE");
            return elsePart;
        }
        function = Function.getFunction(database, "CASE");
        function.setParameter(0, expr);
        i = 1;
        read("WHEN");
        do {
            function.setParameter(i++, readExpression());
            read("THEN");
            function.setParameter(i++, readExpression());
        } while (readIf("WHEN"));
    }
    if (readIf("ELSE")) {
        function.setParameter(i, readExpression());
    }
    read("END");
    readIf("CASE");
    function.doneWithParameters();
    return function;
}
Also used : Function(org.h2.expression.Function) TableFunction(org.h2.expression.TableFunction) JavaFunction(org.h2.expression.JavaFunction) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Aggregations

SimpleResultSet (org.h2.tools.SimpleResultSet)10 ResultSet (java.sql.ResultSet)9 Function (org.h2.expression.Function)8 JavaFunction (org.h2.expression.JavaFunction)8 TableFunction (org.h2.expression.TableFunction)8 Expression (org.h2.expression.Expression)7 ValueExpression (org.h2.expression.ValueExpression)7 Column (org.h2.table.Column)7 Statement (java.sql.Statement)6 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)6 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 IndexColumn (org.h2.table.IndexColumn)6 SQLException (java.sql.SQLException)5 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)5 PreparedStatement (java.sql.PreparedStatement)4 ValueString (org.h2.value.ValueString)4 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)3