test_class.file: dal-jdbc/src/test/java/org/unidal/dal/jdbc/query/token/resolver/ValuesTokenResolverTest.java
test_class.identifier: ValuesTokenResolverTest
test_class.superclass: extends AbstractTokenResolverTest
test_case.body: @Test
     public void testInsert2() throws Exception {
        QueryDef query = new QueryDef("test", UserEntity.class, QueryType.INSERT, "<values/>");
        User user = new User();
        QueryContext ctx = getSelectContext(query, user, null);
        
        user.setUserId(1234);
        user.setUserName("test");
        m_queryResolver.resolve(ctx);
        Assert.assertEquals("?,?,NOW(),NOW(),password(?)", ctx.getSqlStatement());
        Assert.assertEquals("[${user-id}, ${user-name}, ${password}]", ctx.getParameters().toString());
     }
test_case.class_method_signature: ValuesTokenResolverTest.testInsert2()
test_case.full_signature: @Test public void testInsert2()
test_case.identifier: testInsert2
test_case.invocations: getSelectContext setUserId setUserName resolve assertEquals getSqlStatement assertEquals toString getParameters
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInsert2()
focal_class.declarator: m_expressionResolver
focal_class.modifier: @Inject
     private
focal_class.original_string: @Inject
     private ExpressionResolver m_expressionResolver;
focal_class.type: ExpressionResolver
focal_class.var_name: m_expressionResolver
focal_class.file: dal-jdbc/src/main/java/org/unidal/dal/jdbc/query/token/resolver/ValuesTokenResolver.java
focal_class.identifier: ValuesTokenResolver
focal_class.interfaces: implements TokenResolver
focal_class.class_method_signature: ValuesTokenResolver.resolve(Token token, QueryContext ctx)
focal_class.full_signature: public String resolve(Token token, QueryContext ctx)
focal_class.identifier: resolve
focal_class.modifiers: public
focal_class.parameters: (Token token, QueryContext ctx)
focal_class.return: String
focal_class.signature: String resolve(Token token, QueryContext ctx)
focal_method.body: public String resolve(Token token, QueryContext ctx) {
        if (token.getType() != TokenType.VALUES) {
           throw new DalRuntimeException("Internal error: only VALUES token is supported by " + getClass());
        }
  
        EntityInfo entityInfo = ctx.getEntityInfo();
        StringBuilder sb = new StringBuilder(1024);
  
        switch (ctx.getQuery().getType()) {
        case SELECT:
           throw new DalRuntimeException("VALUES token does not support query type: " + ctx.getQuery().getType());
        case INSERT:
           DataObject proto = ctx.getProto();
           
           for (DataField field : entityInfo.getAttributeFields()) {
              Attribute attribute = entityInfo.getAttribute(field);
  
              if (attribute != null) {
                 if (attribute.field().length() > 0 && !(attribute.autoIncrement() && !proto.isFieldUsed(field))) {
                    if (sb.length() > 0) {
                       sb.append(',');
                    }
  
                    if (!proto.isFieldUsed(field) && attribute.insertExpr().length() > 0) {
                       sb.append(m_expressionResolver.resolve(ctx, attribute.insertExpr()));
                    } else {
                       sb.append('?');
                       ctx.addParameter(new Parameter(field));
                    }
                 }
              } else {
                 throw new DalRuntimeException("Internal error: No Attribute annotation defined for field: " + field);
              }
           }
  
           break;
        case UPDATE:
           throw new DalRuntimeException("VALUES token does not support query type: " + ctx.getQuery().getType());
        case DELETE:
           throw new DalRuntimeException("VALUES token does not support query type: " + ctx.getQuery().getType());
        default:
           throw new DalRuntimeException("VALUES token does not support query type: " + ctx.getQuery().getType());
        }
  
        return sb.toString();
     }
focal_method.class_method_signature: ValuesTokenResolver.resolve(Token token, QueryContext ctx)
focal_method.full_signature: public String resolve(Token token, QueryContext ctx)
focal_method.identifier: resolve
focal_method.invocations: getType getClass getEntityInfo getType getQuery getType getQuery getProto getAttributeFields getAttribute length field autoIncrement isFieldUsed length append isFieldUsed length insertExpr append resolve insertExpr append addParameter getType getQuery getType getQuery getType getQuery toString
focal_method.modifiers: public
focal_method.parameters: (Token token, QueryContext ctx)
focal_method.return: String
focal_method.signature: String resolve(Token token, QueryContext ctx)