test_class.file: dal-jdbc/src/test/java/org/unidal/dal/jdbc/query/token/resolver/ParameterTokenResolverTest.java
test_class.identifier: ParameterTokenResolverTest
test_class.superclass: extends AbstractTokenResolverTest
test_case.body: @Test
     public void testVariable() throws Exception {
        QueryDef query = new QueryDef("test", UserEntity.class, QueryType.SELECT, "${key-user-id}");
        Readset<?> readset = UserEntity.READSET_FULL;
        User user = new User();
        QueryContext ctx = getSelectContext(query, user, readset);
  
        user.setKeyUserId(1234L);
        m_queryResolver.resolve(ctx);
        Assert.assertEquals("?", ctx.getSqlStatement());
        Assert.assertEquals(1234L, getParameterValue(ctx, 0));
     }
test_case.class_method_signature: ParameterTokenResolverTest.testVariable()
test_case.full_signature: @Test public void testVariable()
test_case.identifier: testVariable
test_case.invocations: getSelectContext setKeyUserId resolve assertEquals getSqlStatement assertEquals getParameterValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testVariable()
focal_class.declarator: m_accessor
focal_class.modifier: @Inject
     private
focal_class.original_string: @Inject
     private DataObjectAccessor m_accessor;
focal_class.type: DataObjectAccessor
focal_class.var_name: m_accessor
focal_class.file: dal-jdbc/src/main/java/org/unidal/dal/jdbc/query/token/resolver/ParameterTokenResolver.java
focal_class.identifier: ParameterTokenResolver
focal_class.interfaces: implements TokenResolver
focal_class.class_method_signature: ParameterTokenResolver.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.PARAM) {
           throw new DalRuntimeException("Internal error: only PARAM token is supported by " + getClass());
        }
  
        ParameterToken parameter = (ParameterToken) token;
        String fieldName = parameter.getParameterName();
        DataField dataField = ctx.getEntityInfo().getFieldByName(fieldName);
  
        if (parameter.isIn()) { // IN
           Object value = m_accessor.getFieldValue(ctx.getProto(), dataField);
  
           if (ctx.isWithinInToken() && value != null && value.getClass().isArray()) {
              int length = Array.getLength(value);
              StringBuilder sb = new StringBuilder();
  
              if (length > 0) {
                 ctx.addParameter(new Parameter(dataField).setType(Parameter.TYPE_ARRAY));
  
                 for (int i = 0; i < length; i++) {
                    if (i > 0) {
                       sb.append(',');
                    }
  
                    sb.append('?');
                 }
              } else {
                 sb.append("null"); // to avoid SQL exception
              }
  
              return sb.toString();
           } else if (ctx.isWithinInToken() && value instanceof Iterable) {
              Iterable<?> iterable = (Iterable<?>) value;
              Iterator<?> i = iterable.iterator();
              StringBuilder sb = new StringBuilder();
  
              if (i.hasNext()) {
                 ctx.addParameter(new Parameter(dataField).setType(Parameter.TYPE_ITERABLE));
  
                 for (; i.hasNext(); i.next()) {
                    if (sb.length() > 0) {
                       sb.append(',');
                    }
  
                    sb.append('?');
                 }
              } else {
                 sb.append("null"); // to avoid SQL exception
              }
  
              return sb.toString();
           } else {
              ctx.addParameter(new Parameter(dataField).setType(Parameter.TYPE_SINGLE_VALUE));
              return "?";
           }
        } else if (parameter.isInOut()) { // IN_OUT
           Variable variable = ctx.getEntityInfo().getVariable(dataField);
  
           ctx.addParameter(new Parameter(dataField, variable.sqlType(), variable.scale(), true).setType(Parameter.TYPE_SINGLE_VALUE));
           return "?";
        } else { // OUT
           Variable variable = ctx.getEntityInfo().getVariable(dataField);
  
           ctx.addParameter(new Parameter(dataField, variable.sqlType(), variable.scale()).setType(Parameter.TYPE_SINGLE_VALUE));
           return "?";
        }
     }
focal_method.class_method_signature: ParameterTokenResolver.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 getParameterName getFieldByName getEntityInfo isIn getFieldValue getProto isWithinInToken isArray getClass getLength addParameter setType append append append toString isWithinInToken iterator hasNext addParameter setType hasNext next length append append append toString addParameter setType isInOut getVariable getEntityInfo addParameter setType sqlType scale getVariable getEntityInfo addParameter setType sqlType scale
focal_method.modifiers: public
focal_method.parameters: (Token token, QueryContext ctx)
focal_method.return: String
focal_method.signature: String resolve(Token token, QueryContext ctx)