Search in sources :

Example 16 with Right

use of org.h2.engine.Right in project nzbhydra2 by theotherp.

the class NzbHydra method startup.

protected static void startup(String[] args, OptionSet options) throws Exception {
    if (options.has("datafolder")) {
        dataFolder = (String) options.valueOf("datafolder");
    } else {
        dataFolder = "./data";
    }
    File dataFolderFile = new File(dataFolder);
    dataFolder = dataFolderFile.getCanonicalPath();
    // Check if we can write in the data folder. If not we can just quit now
    if (!dataFolderFile.exists() && !dataFolderFile.mkdirs()) {
        logger.error("Unable to read or write data folder {}", dataFolder);
        System.exit(1);
    }
    if (isOsWindows()) {
        // It may happen that the yaml file is written empty due to some weird write right constraints in c:\program files or c:\program files (x86)
        if (dataFolderFile.getAbsolutePath().toLowerCase().contains(":\\program files")) {
            String[] split = dataFolderFile.getAbsolutePath().split("\\\\");
            logger.error("NZBHydra 2 may not work properly when run in {}\\\\{}. Please put it somewhere else", split[0], split[1]);
            System.exit(1);
        }
    }
    System.setProperty("nzbhydra.dataFolder", dataFolder);
    File yamlFile = new File(dataFolder, "nzbhydra.yml");
    System.setProperty("spring.config.location", yamlFile.getAbsolutePath());
    useIfSet(options, "host", "server.address");
    useIfSet(options, "port", "server.port");
    useIfSet(options, "baseurl", "server.contextPath");
    useIfSet(options, "nobrowser", BROWSER_DISABLED, "true");
    SpringApplication hydraApplication = new SpringApplication(NzbHydra.class);
    NzbHydra.originalArgs = args;
    wasRestarted = Arrays.stream(args).anyMatch(x -> x.equals("restarted"));
    if (!options.has("quiet") && !options.has("nobrowser")) {
        hydraApplication.setHeadless(false);
    }
    try {
        applicationContext = hydraApplication.run(args);
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : Arrays(java.util.Arrays) AopAutoConfiguration(org.springframework.boot.autoconfigure.aop.AopAutoConfiguration) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) UrlCalculator(org.nzbhydra.web.UrlCalculator) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) SpringApplication(org.springframework.boot.SpringApplication) PreDestroy(javax.annotation.PreDestroy) OptionException(joptsimple.OptionException) ConfigProvider(org.nzbhydra.config.ConfigProvider) CacheManager(org.springframework.cache.CacheManager) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OptionParser(joptsimple.OptionParser) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) URI(java.net.URI) OptionSet(joptsimple.OptionSet) EnableCaching(org.springframework.cache.annotation.EnableCaching) DebugInfosProvider(org.nzbhydra.debuginfos.DebugInfosProvider) Logger(org.slf4j.Logger) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) GenericStorage(org.nzbhydra.genericstorage.GenericStorage) ApplicationContext(org.springframework.context.ApplicationContext) RestController(org.springframework.web.bind.annotation.RestController) ComponentScan(org.springframework.context.annotation.ComponentScan) File(java.io.File) GuavaCacheManager(org.springframework.cache.guava.GuavaCacheManager) Configuration(org.springframework.context.annotation.Configuration) java.awt(java.awt) BrowserOpener(org.nzbhydra.misc.BrowserOpener) WebSocketAutoConfiguration(org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration) ConnectorStartFailedException(org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException) PostConstruct(javax.annotation.PostConstruct) Flyway(org.flywaydb.core.Flyway) Bean(org.springframework.context.annotation.Bean) YAMLException(org.yaml.snakeyaml.error.YAMLException) javax.swing(javax.swing) SpringApplication(org.springframework.boot.SpringApplication) File(java.io.File) OptionException(joptsimple.OptionException) IOException(java.io.IOException) ConnectorStartFailedException(org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException) YAMLException(org.yaml.snakeyaml.error.YAMLException)

Example 17 with Right

use of org.h2.engine.Right in project siena by mandubian.

the class FullText method addColumnData.

private static void addColumnData(ArrayList<String> columns, ArrayList<String> data, Expression expr) {
    if (expr instanceof ConditionAndOr) {
        ConditionAndOr and = (ConditionAndOr) expr;
        Expression left = and.getExpression(true);
        Expression right = and.getExpression(false);
        addColumnData(columns, data, left);
        addColumnData(columns, data, right);
    } else {
        Comparison comp = (Comparison) expr;
        ExpressionColumn ec = (ExpressionColumn) comp.getExpression(true);
        ValueExpression ev = (ValueExpression) comp.getExpression(false);
        String columnName = ec.getColumnName();
        columns.add(columnName);
        if (ev == null) {
            data.add(null);
        } else {
            data.add(ev.getValue(null).getString());
        }
    }
}
Also used : ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression) Comparison(org.h2.expression.Comparison) ValueExpression(org.h2.expression.ValueExpression) ConditionAndOr(org.h2.expression.ConditionAndOr) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 18 with Right

use of org.h2.engine.Right in project ignite by apache.

the class GridH2CollocationModel method buildCollocationModel.

/**
 * @param upper Upper.
 * @param filter Filter.
 * @param qry Query.
 * @param unions Unions.
 * @param validate Query validation flag.
 * @return Built model.
 */
private static GridH2CollocationModel buildCollocationModel(GridH2CollocationModel upper, int filter, Query qry, List<GridH2CollocationModel> unions, boolean validate) {
    if (qry.isUnion()) {
        if (unions == null)
            unions = new ArrayList<>();
        SelectUnion union = (SelectUnion) qry;
        GridH2CollocationModel left = buildCollocationModel(upper, filter, union.getLeft(), unions, validate);
        GridH2CollocationModel right = buildCollocationModel(upper, filter, union.getRight(), unions, validate);
        assert left != null;
        assert right != null;
        return upper != null ? upper : left;
    }
    Select select = (Select) qry;
    List<TableFilter> list = new ArrayList<>();
    for (TableFilter f = select.getTopTableFilter(); f != null; f = f.getJoin()) list.add(f);
    TableFilter[] filters = list.toArray(new TableFilter[list.size()]);
    GridH2CollocationModel cm = createChildModel(upper, filter, unions, true, validate);
    cm.childFilters(filters);
    for (int i = 0; i < filters.length; i++) {
        TableFilter f = filters[i];
        if (f.getTable().isView())
            buildCollocationModel(cm, i, getSubQuery(f), null, validate);
        else if (f.getTable() instanceof GridH2Table)
            createChildModel(cm, i, null, false, validate);
    }
    return upper != null ? upper : cm;
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion) TableFilter(org.h2.table.TableFilter) ArrayList(java.util.ArrayList) Select(org.h2.command.dml.Select)

Example 19 with Right

use of org.h2.engine.Right in project ignite by apache.

the class GridSqlQueryParser method parseExpression0.

/**
 * @param expression Expression.
 * @param calcTypes Calculate types for all the expressions.
 * @return Parsed expression.
 */
private GridSqlElement parseExpression0(Expression expression, boolean calcTypes) {
    if (expression instanceof ExpressionColumn) {
        ExpressionColumn expCol = (ExpressionColumn) expression;
        return new GridSqlColumn(expCol.getColumn(), parseTableFilter(expCol.getTableFilter()), SCHEMA_NAME.get(expCol), expCol.getOriginalTableAliasName(), expCol.getColumnName());
    }
    if (expression instanceof Alias)
        return new GridSqlAlias(expression.getAlias(), parseExpression(expression.getNonAliasExpression(), calcTypes), true);
    if (expression instanceof ValueExpression)
        // == comparison is legit, see ValueExpression#getSQL()
        return expression == ValueExpression.getDefault() ? GridSqlKeyword.DEFAULT : new GridSqlConst(expression.getValue(null));
    if (expression instanceof Operation) {
        Operation operation = (Operation) expression;
        Integer type = OPERATION_TYPE.get(operation);
        if (type == Operation.NEGATE) {
            assert OPERATION_RIGHT.get(operation) == null;
            return new GridSqlOperation(GridSqlOperationType.NEGATE, parseExpression(OPERATION_LEFT.get(operation), calcTypes));
        }
        return new GridSqlOperation(OPERATION_OP_TYPES[type], parseExpression(OPERATION_LEFT.get(operation), calcTypes), parseExpression(OPERATION_RIGHT.get(operation), calcTypes));
    }
    if (expression instanceof Comparison) {
        Comparison cmp = (Comparison) expression;
        GridSqlOperationType opType = COMPARISON_TYPES[COMPARISON_TYPE.get(cmp)];
        assert opType != null : COMPARISON_TYPE.get(cmp);
        Expression leftExp = COMPARISON_LEFT.get(cmp);
        GridSqlElement left = parseExpression(leftExp, calcTypes);
        if (opType.childrenCount() == 1)
            return new GridSqlOperation(opType, left);
        Expression rightExp = COMPARISON_RIGHT.get(cmp);
        GridSqlElement right = parseExpression(rightExp, calcTypes);
        return new GridSqlOperation(opType, left, right);
    }
    if (expression instanceof ConditionNot)
        return new GridSqlOperation(NOT, parseExpression(expression.getNotIfPossible(null), calcTypes));
    if (expression instanceof ConditionAndOr) {
        ConditionAndOr andOr = (ConditionAndOr) expression;
        int type = ANDOR_TYPE.get(andOr);
        assert type == ConditionAndOr.AND || type == ConditionAndOr.OR;
        return new GridSqlOperation(type == ConditionAndOr.AND ? AND : OR, parseExpression(ANDOR_LEFT.get(andOr), calcTypes), parseExpression(ANDOR_RIGHT.get(andOr), calcTypes));
    }
    if (expression instanceof Subquery) {
        Query qry = ((Subquery) expression).getQuery();
        return parseQueryExpression(qry);
    }
    if (expression instanceof ConditionIn) {
        GridSqlOperation res = new GridSqlOperation(IN);
        res.addChild(parseExpression(LEFT_CI.get((ConditionIn) expression), calcTypes));
        List<Expression> vals = VALUE_LIST_CI.get((ConditionIn) expression);
        for (Expression val : vals) res.addChild(parseExpression(val, calcTypes));
        return res;
    }
    if (expression instanceof ConditionInConstantSet) {
        GridSqlOperation res = new GridSqlOperation(IN);
        res.addChild(parseExpression(LEFT_CICS.get((ConditionInConstantSet) expression), calcTypes));
        List<Expression> vals = VALUE_LIST_CICS.get((ConditionInConstantSet) expression);
        for (Expression val : vals) res.addChild(parseExpression(val, calcTypes));
        return res;
    }
    if (expression instanceof ConditionInSelect) {
        GridSqlOperation res = new GridSqlOperation(IN);
        boolean all = ALL.get((ConditionInSelect) expression);
        int compareType = COMPARE_TYPE.get((ConditionInSelect) expression);
        assert0(!all, expression);
        assert0(compareType == Comparison.EQUAL, expression);
        res.addChild(parseExpression(LEFT_CIS.get((ConditionInSelect) expression), calcTypes));
        Query qry = QUERY_IN.get((ConditionInSelect) expression);
        res.addChild(parseQueryExpression(qry));
        return res;
    }
    if (expression instanceof CompareLike) {
        assert0(ESCAPE.get((CompareLike) expression) == null, expression);
        boolean regexp = REGEXP_CL.get((CompareLike) expression);
        return new GridSqlOperation(regexp ? REGEXP : LIKE, parseExpression(LEFT.get((CompareLike) expression), calcTypes), parseExpression(RIGHT.get((CompareLike) expression), calcTypes));
    }
    if (expression instanceof Function) {
        Function f = (Function) expression;
        GridSqlFunction res = new GridSqlFunction(null, f.getName());
        if (f.getArgs() != null) {
            if (f.getFunctionType() == Function.TABLE || f.getFunctionType() == Function.TABLE_DISTINCT) {
                Column[] cols = FUNC_TBL_COLS.get((TableFunction) f);
                Expression[] args = f.getArgs();
                assert cols.length == args.length;
                for (int i = 0; i < cols.length; i++) {
                    GridSqlElement arg = parseExpression(args[i], calcTypes);
                    GridSqlAlias alias = new GridSqlAlias(cols[i].getName(), arg, false);
                    alias.resultType(fromColumn(cols[i]));
                    res.addChild(alias);
                }
            } else {
                for (Expression arg : f.getArgs()) {
                    if (arg == null) {
                        if (f.getFunctionType() != Function.CASE)
                            throw new IllegalStateException("Function type with null arg: " + f.getFunctionType());
                        res.addChild(GridSqlPlaceholder.EMPTY);
                    } else
                        res.addChild(parseExpression(arg, calcTypes));
                }
            }
        }
        if (f.getFunctionType() == Function.CAST || f.getFunctionType() == Function.CONVERT)
            res.resultType(fromExpression(f));
        return res;
    }
    if (expression instanceof JavaFunction) {
        JavaFunction f = (JavaFunction) expression;
        FunctionAlias alias = FUNC_ALIAS.get(f);
        GridSqlFunction res = new GridSqlFunction(alias.getSchema().getName(), f.getName());
        if (f.getArgs() != null) {
            for (Expression arg : f.getArgs()) res.addChild(parseExpression(arg, calcTypes));
        }
        return res;
    }
    if (expression instanceof Parameter)
        return new GridSqlParameter(((Parameter) expression).getIndex());
    if (expression instanceof Aggregate) {
        int typeId = TYPE.get((Aggregate) expression);
        if (GridSqlAggregateFunction.isValidType(typeId)) {
            GridSqlAggregateFunction res = new GridSqlAggregateFunction(DISTINCT.get((Aggregate) expression), typeId);
            Expression on = ON.get((Aggregate) expression);
            if (on != null)
                res.addChild(parseExpression(on, calcTypes));
            return res;
        }
    }
    if (expression instanceof ExpressionList) {
        Expression[] exprs = EXPR_LIST.get((ExpressionList) expression);
        GridSqlArray res = new GridSqlArray(exprs.length);
        for (Expression expr : exprs) res.addChild(parseExpression(expr, calcTypes));
        return res;
    }
    if (expression instanceof ConditionExists) {
        Query qry = QUERY_EXISTS.get((ConditionExists) expression);
        GridSqlOperation res = new GridSqlOperation(EXISTS);
        res.addChild(parseQueryExpression(qry));
        return res;
    }
    throw new IgniteException("Unsupported expression: " + expression + " [type=" + expression.getClass().getSimpleName() + ']');
}
Also used : ConditionNot(org.h2.expression.ConditionNot) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Query(org.h2.command.dml.Query) JavaFunction(org.h2.expression.JavaFunction) Operation(org.h2.expression.Operation) ConditionAndOr(org.h2.expression.ConditionAndOr) Subquery(org.h2.expression.Subquery) ExpressionColumn(org.h2.expression.ExpressionColumn) Function(org.h2.expression.Function) TableFunction(org.h2.expression.TableFunction) JavaFunction(org.h2.expression.JavaFunction) Comparison(org.h2.expression.Comparison) GridSqlType.fromColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) IgniteException(org.apache.ignite.IgniteException) ExpressionList(org.h2.expression.ExpressionList) FunctionAlias(org.h2.engine.FunctionAlias) ConditionIn(org.h2.expression.ConditionIn) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) CompareLike(org.h2.expression.CompareLike) ConditionInConstantSet(org.h2.expression.ConditionInConstantSet) ConditionInSelect(org.h2.expression.ConditionInSelect) Expression(org.h2.expression.Expression) GridSqlType.fromExpression(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromExpression) ValueExpression(org.h2.expression.ValueExpression) FunctionAlias(org.h2.engine.FunctionAlias) Alias(org.h2.expression.Alias) ValueExpression(org.h2.expression.ValueExpression) Parameter(org.h2.expression.Parameter) Aggregate(org.h2.expression.Aggregate) ConditionExists(org.h2.expression.ConditionExists)

Example 20 with Right

use of org.h2.engine.Right in project h2database by h2database.

the class Query method query.

/**
 * Execute the query, writing the result to the target result.
 *
 * @param limit the maximum number of rows to return
 * @param target the target result (null will return the result)
 * @return the result set (if the target is not set).
 */
public final ResultInterface query(int limit, ResultTarget target) {
    if (isUnion()) {
        // right queries
        return queryWithoutCacheLazyCheck(limit, target);
    }
    fireBeforeSelectTriggers();
    if (noCache || !session.getDatabase().getOptimizeReuseResults() || session.isLazyQueryExecution()) {
        return queryWithoutCacheLazyCheck(limit, target);
    }
    Value[] params = getParameterValues();
    long now = session.getDatabase().getModificationDataId();
    if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
        if (lastResult != null && !lastResult.isClosed() && limit == lastLimit) {
            if (sameResultAsLast(session, params, lastParameters, lastEvaluated)) {
                lastResult = lastResult.createShallowCopy(session);
                if (lastResult != null) {
                    lastResult.reset();
                    return lastResult;
                }
            }
        }
    }
    lastParameters = params;
    closeLastResult();
    ResultInterface r = queryWithoutCacheLazyCheck(limit, target);
    lastResult = r;
    this.lastEvaluated = now;
    lastLimit = limit;
    return r;
}
Also used : ResultInterface(org.h2.result.ResultInterface) Value(org.h2.value.Value)

Aggregations

Right (org.h2.engine.Right)9 Database (org.h2.engine.Database)7 Expression (org.h2.expression.Expression)7 ValueExpression (org.h2.expression.ValueExpression)7 Value (org.h2.value.Value)7 Comparison (org.h2.expression.Comparison)6 ConditionAndOr (org.h2.expression.ConditionAndOr)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 ValueString (org.h2.value.ValueString)6 Column (org.h2.table.Column)5 IOException (java.io.IOException)4 Constraint (org.h2.constraint.Constraint)4 IndexColumn (org.h2.table.IndexColumn)4 ArrayList (java.util.ArrayList)3 DbObject (org.h2.engine.DbObject)3 Index (org.h2.index.Index)3 Sequence (org.h2.schema.Sequence)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 ResultSet (java.sql.ResultSet)2