Package dbfit.util

Examples of dbfit.util.DbParameterAccessor


        dbfit.environment.SqlServerEnvironment env = new SqlServerEnvironment("SqlServer");

        String expectedResult = "insert into DummyTable([Column1],[Column Two],[ColumnThree]) values (?,?,?)";
        DbParameterAccessor[] parameters = new DbParameterAccessor[3];

        parameters[0] = new DbParameterAccessor("Column1", Direction.INPUT, 0, null, 0);
        parameters[1] = new DbParameterAccessor("Column Two", Direction.INPUT, 0, null, 1);
        parameters[2] = new DbParameterAccessor("ColumnThree", Direction.INPUT, 0, null, 2);

        String actualResult = env.buildInsertCommand("DummyTable", parameters);

        assertEquals(expectedResult, actualResult);
    }
View Full Code Here


        dbfit.environment.SqlServerEnvironment env = new SqlServerEnvironment("SqlServer");

        String expectedResult = "insert into DummyTable([Column1]) values (?)";
        DbParameterAccessor[] parameters = new DbParameterAccessor[2];

        parameters[0] = new DbParameterAccessor("Column1", Direction.INPUT, 0, null, 0);
        parameters[1] = new DbParameterAccessor("Column2", Direction.OUTPUT, 0, null, 0);

        String actualResult = env.buildInsertCommand("DummyTable", parameters);

        assertEquals(expectedResult, actualResult);
    }
View Full Code Here

        return call.toStatementExecution();
    }

    public DbParameterAccessor getDbParameterAccessor(String name,
                                                      Direction expectedDirection) throws SQLException{
        DbParameterAccessor parameter = findAccessorForParamWithName(name);
        if (parameter.hasDirection(INPUT_OUTPUT)) {
            // clone, separate into input and output
            parameter = parameter.clone();
            parameter.setDirection(expectedDirection);
        }
        // sql server quirk. if output parameter is used in an input column,
        // then the param should be cloned and remapped to IN/OUT
        if (expectedDirection!=Direction.OUTPUT && parameter.hasDirection(Direction.OUTPUT)) {
            parameter = parameter.clone();
            parameter.setDirection(Direction.INPUT);
        }
        return parameter;
    }
View Full Code Here

        return parameter;
    }

    private DbParameterAccessor findAccessorForParamWithName(String name) throws SQLException {
        String paramName = NameNormaliser.normaliseName(name);
        DbParameterAccessor accessor = getAllParams().get(paramName);
        if (accessor == null)
            throw new SQLException("Cannot find parameter \"" + paramName + "\"");
        return accessor;
    }
View Full Code Here

    }

    public DbParameterAccessor getDbParameterAccessor(String columnName,
            Direction expectedDirection) {
        String normalisedName = NameNormaliser.normaliseName(columnName);
        DbParameterAccessor accessor = columns.get(normalisedName);
        if (null == accessor) {
            throw new RuntimeException(
                    "No such database column or parameter: '" + normalisedName + "'");
        }

        if (accessor.hasDirection(INPUT)
                && expectedDirection == OUTPUT) {
            accessor = dbEnvironment
                    .createAutogeneratedPrimaryKeyAccessor(accessor);
        }
        return accessor;
View Full Code Here

            while (rs.next()) {
                String columnName = rs.getString(1);
                if (columnName == null)
                    columnName = "";
                String dataType = rs.getString(2);
                DbParameterAccessor dbp = new DbParameterAccessor(columnName,
                        Direction.INPUT, getSqlType(dataType),
                        getJavaClass(dataType), position++);
                columns.put(NameNormaliser.normaliseName(columnName), dbp);
            }
            rs.close();
View Full Code Here

        MySqlProcedureParametersParser parser = new MySqlProcedureParametersParser();
        Map<String, DbParameterAccessor> allParams = new HashMap<String, DbParameterAccessor>();

        int position = 0;
        for (ParamDescriptor pd: parser.parseParameters(paramList)) {
            DbParameterAccessor dbp = new DbParameterAccessor(
                    pd.name, pd.direction,
                    getSqlType(pd.type), getJavaClass(pd.type),
                    position++);
            allParams.put(NameNormaliser.normaliseName(pd.name), dbp);
        }

        if ("FUNCTION".equals(type)) {
            ParamDescriptor rd = parser.parseReturnType(returns);
            allParams.put("", new DbParameterAccessor("",
                    Direction.RETURN_VALUE, getSqlType(rd.type),
                    getJavaClass(rd.type), -1));
        }

        return allParams;
View Full Code Here

                String paramName = rs.getString(1);
                if (paramName == null) {
                    paramName = "";
                }
                String dataType = rs.getString(2);
                DbParameterAccessor dbp = new DbParameterAccessor(paramName,
                        Direction.INPUT, getSqlType(dataType),
                        getJavaClass(dataType), position++);
                allParams.put(NameNormaliser.normaliseName(paramName), dbp);
            }
            rs.close();
View Full Code Here

                token = s.nextToken();
                paramName = "$" + (position + 1);

                dataType = normaliseTypeName(param);

                DbParameterAccessor dbp = new DbParameterAccessor(paramName,
                        direction, getSqlType(dataType), getJavaClass(dataType),
                        position++);
                allParams.put(NameNormaliser.normaliseName(paramName), dbp);
            }
        }
View Full Code Here

        for (int i = 0; headerCells != null; i++, headerCells = headerCells.more) {
            String name = headerCells.text();
            String paramName = NameNormaliser.normaliseName(name);
            //need to clone db param accessors here because same column may be in the update and select part
            DbParameterAccessor orig = allParams.get(paramName);
            if (orig == null) {
                wrong(headerCells);
                throw new SQLException("Cannot find column " + paramName);
            }
            //clone parameter because there may be multiple usages of the same column
            DbParameterAccessor acc = orig.clone();
            acc.setDirection(Direction.INPUT);
            if (headerCells.text().endsWith("=")) {
                updateAcc.add(acc);
            } else {
                selectAcc.add(acc);
            }
View Full Code Here

TOP

Related Classes of dbfit.util.DbParameterAccessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.