Search in sources :

Example 6 with SqlLocation

use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.

the class SqlValidator method visitForNode.

@Override
public Void visitForNode(ForNode node, Void p) {
    SqlLocation location = node.getLocation();
    String identifier = node.getIdentifier();
    String expression = node.getExpression();
    TypeDeclaration typeDeclaration = validateExpressionVariable(location, expression);
    TypeMirror typeMirror = typeDeclaration.getType();
    List<? extends TypeMirror> typeArgs;
    if (ctx.getMoreTypes().isAssignableWithErasure(typeMirror, Iterable.class)) {
        DeclaredType declaredType = ctx.getMoreTypes().toDeclaredType(typeMirror);
        typeArgs = declaredType.getTypeArguments();
    } else if (ctx.getMoreTypes().isArray(typeMirror)) {
        ArrayType arrayType = ctx.getMoreTypes().toArrayType(typeMirror);
        typeArgs = Collections.singletonList(arrayType.getComponentType());
    } else {
        String sql = getSql(location);
        throw new AptException(Message.DOMA4149, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
    }
    if (typeArgs.isEmpty()) {
        String sql = getSql(location);
        throw new AptException(Message.DOMA4150, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
    }
    TypeMirror originalIdentifierType = expressionValidator.removeParameterType(identifier);
    expressionValidator.putParameterType(identifier, typeArgs.get(0));
    String hasNextVariable = identifier + ForBlockNode.HAS_NEXT_SUFFIX;
    TypeMirror originalHasNextType = expressionValidator.removeParameterType(hasNextVariable);
    expressionValidator.putParameterType(hasNextVariable, ctx.getMoreTypes().getTypeMirror(boolean.class));
    String indexVariable = identifier + ForBlockNode.INDEX_SUFFIX;
    TypeMirror originalIndexType = expressionValidator.removeParameterType(indexVariable);
    expressionValidator.putParameterType(indexVariable, ctx.getMoreTypes().getTypeMirror(int.class));
    visitNode(node, p);
    if (originalIdentifierType == null) {
        expressionValidator.removeParameterType(identifier);
    } else {
        expressionValidator.putParameterType(identifier, originalIdentifierType);
    }
    if (originalHasNextType == null) {
        expressionValidator.removeParameterType(hasNextVariable);
    } else {
        expressionValidator.putParameterType(hasNextVariable, originalHasNextType);
    }
    if (originalIndexType == null) {
        expressionValidator.removeParameterType(indexVariable);
    } else {
        expressionValidator.putParameterType(indexVariable, originalIndexType);
    }
    return null;
}
Also used : ArrayType(javax.lang.model.type.ArrayType) TypeMirror(javax.lang.model.type.TypeMirror) AptException(org.seasar.doma.internal.apt.AptException) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) DeclaredType(javax.lang.model.type.DeclaredType)

Example 7 with SqlLocation

use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.

the class SqlValidator method visitElseifNode.

@Override
public Void visitElseifNode(ElseifNode node, Void p) {
    SqlLocation location = node.getLocation();
    String expression = node.getExpression();
    TypeDeclaration typeDeclaration = validateExpressionVariable(location, expression);
    if (!typeDeclaration.isBooleanType()) {
        String sql = getSql(location);
        throw new AptException(Message.DOMA4141, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition(), expression, typeDeclaration.getBinaryName() });
    }
    visitNode(node, p);
    return null;
}
Also used : AptException(org.seasar.doma.internal.apt.AptException) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration)

Example 8 with SqlLocation

use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.

the class SqlValidator method visitEmbeddedVariableNode.

@Override
public Void visitEmbeddedVariableNode(EmbeddedVariableNode node, Void p) {
    SqlLocation location = node.getLocation();
    String variableName = node.getVariableName();
    validateExpressionVariable(location, variableName);
    visitNode(node, p);
    return null;
}
Also used : SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation)

Example 9 with SqlLocation

use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.

the class SqlValidator method visitExpandNode.

@Override
public Void visitExpandNode(ExpandNode node, Void p) {
    if (!expandable) {
        SqlLocation location = node.getLocation();
        String sql = getSql(location);
        throw new AptException(Message.DOMA4257, methodElement, new Object[] { path, sql, location.getLineNumber(), location.getPosition() });
    }
    return visitNode(node, p);
}
Also used : AptException(org.seasar.doma.internal.apt.AptException) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation)

Example 10 with SqlLocation

use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.

the class AbstractSelectQuery method expandColumns.

protected List<String> expandColumns(ExpandNode node) {
    if (entityType == null) {
        SqlLocation location = node.getLocation();
        throw new JdbcException(Message.DOMA2144, location.getSql(), location.getLineNumber(), location.getPosition());
    }
    Naming naming = config.getNaming();
    Dialect dialect = config.getDialect();
    return entityType.getEntityPropertyTypes().stream().map(p -> p.getColumnName(naming::apply, dialect::applyQuote)).collect(Collectors.toList());
}
Also used : SelectOptions(org.seasar.doma.jdbc.SelectOptions) BiFunction(java.util.function.BiFunction) EntityType(org.seasar.doma.jdbc.entity.EntityType) HashMap(java.util.HashMap) SelectOptionsAccessor(org.seasar.doma.jdbc.SelectOptionsAccessor) Function(java.util.function.Function) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Naming(org.seasar.doma.jdbc.Naming) ExpandNode(org.seasar.doma.internal.jdbc.sql.node.ExpandNode) FetchType(org.seasar.doma.FetchType) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) Map(java.util.Map) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) JdbcException(org.seasar.doma.jdbc.JdbcException) BasicSingleResultHandler(org.seasar.doma.internal.jdbc.command.BasicSingleResultHandler) SqlNode(org.seasar.doma.jdbc.SqlNode) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Value(org.seasar.doma.internal.expr.Value) SelectCommand(org.seasar.doma.jdbc.command.SelectCommand) Collectors(java.util.stream.Collectors) AssertionUtil.assertNotNull(org.seasar.doma.internal.util.AssertionUtil.assertNotNull) Message(org.seasar.doma.message.Message) List(java.util.List) SqlLogType(org.seasar.doma.jdbc.SqlLogType) PrimitiveLongWrapper(org.seasar.doma.wrapper.PrimitiveLongWrapper) Dialect(org.seasar.doma.jdbc.dialect.Dialect) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) Naming(org.seasar.doma.jdbc.Naming) JdbcException(org.seasar.doma.jdbc.JdbcException)

Aggregations

SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)16 JdbcException (org.seasar.doma.jdbc.JdbcException)7 AptException (org.seasar.doma.internal.apt.AptException)6 EvaluationResult (org.seasar.doma.internal.expr.EvaluationResult)5 TypeDeclaration (org.seasar.doma.internal.apt.decl.TypeDeclaration)4 SqlNode (org.seasar.doma.jdbc.SqlNode)3 Value (org.seasar.doma.internal.expr.Value)2 ParensNode (org.seasar.doma.internal.jdbc.sql.node.ParensNode)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ArrayType (javax.lang.model.type.ArrayType)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 FetchType (org.seasar.doma.FetchType)1 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)1 BasicSingleResultHandler (org.seasar.doma.internal.jdbc.command.BasicSingleResultHandler)1