Package de.zalando.typemapper.core.result

Examples of de.zalando.typemapper.core.result.DbResultNode


        Object result = null;

        // instantiate enums by string value
        if (clazz.isEnum()) {
            final DbResultNode currentNode = node.getChildByName(node.getType());
            result = Enum.valueOf(clazz, currentNode.getValue());
        } else {
            result = clazz.newInstance();

            final List<Mapping> mappings = Mapping.getMappingsForClass(clazz);

            for (final Mapping mapping : mappings) {
                final DbResultNode currentNode = node.getChildByName(mapping.getName());
                if (currentNode == null) {
                    if (mapping.isOptionalField()) {
                        mapping.map(result, null);
                    } else {
                        LOG.warn("Could not find value of mapping: {}", mapping.getName());
                    }

                    continue;
                }

                // TODO pribeiro. We should use polymorphism instead. Build like a chain.
                try {
                    if (DbResultNodeType.SIMPLE.equals(currentNode.getNodeType())) {
                        mapping.map(result,
                            mapping.getFieldMapper().mapField(currentNode.getValue(), mapping.getFieldClass()));
                    } else if (DbResultNodeType.OBJECT.equals(currentNode.getNodeType())) {
                        mapping.map(result, mapFromDbObjectNode(clazz, (ObjectResultNode) currentNode, mapping));
                    } else if (DbResultNodeType.ARRAY.equals(currentNode.getNodeType())) {
                        mapping.map(result,
                            ArrayFieldMapper.mapField(mapping.getField(), (ArrayResultNode) currentNode));
                    }
                } catch (final Exception e) {
                    LOG.error("Failed to map property {} of class {}",
View Full Code Here


        final ResultTree tree = new ResultTree();

        for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
            final int typeId = pgSet.getColumnOID(i);
            DbResultNode node = null;

            final Object obj = pgSet.getObject(i);
            final String name = rsMetaData.getColumnName(i);

            // TODO pribeiro We should use polymorphism here. Build like a chain
            if ((obj instanceof PGobject) && ((PGobject) obj).getType().equals("record")) {
                final PGobject pgObj = (PGobject) obj;
                final DbFunction function = DbFunctionRegister.getFunction(name, pgSet.getStatement().getConnection());
                List<String> fieldValues;
                try {
                    fieldValues = ParseUtils.postgresROW2StringList(pgObj.getValue());
                } catch (final RowParserException e) {
                    throw new SQLException(e);
                }

                int j = 1;
                for (final String fieldValue : fieldValues) {
                    final DbTypeField fieldDef = function.getFieldByPos(j);
                    DbResultNode currentNode = null;
                    if (fieldDef.getType().equals("USER-DEFINED")) {
                        currentNode = new ObjectResultNode(fieldValue, fieldDef.getName(), fieldDef.getTypeName(),
                                fieldDef.getTypeId(), pgSet.getStatement().getConnection());
                    } else if (fieldDef.getType().equals("ARRAY")) {
                        currentNode = new ArrayResultNode(fieldDef.getName(), fieldValue,
View Full Code Here

    }

    private void fillObject(final Object result, final ResultTree tree) throws SQLException {
        for (final Mapping mapping : getMappings()) {
            try {
                final DbResultNode node = tree.getChildByName(mapping.getName());

                // TODO pribeiro we need to distinguish between null value and a mapping not defined in the tree
                if (node == null) {

                    // this may be okay - if any return value is NULL, we will reach this path.
                    // to classify and mark this as an error, we need more information.
                    LOG.trace("Could not map property {} of class {}: field not in result tree, field may be nullable.",
                        mapping.getName(), resultClass.getSimpleName());
                    continue;
                }

                if (DbResultNodeType.MAP != node.getNodeType() && node.getValue() == null) {
                    if (mapping.isOptionalField()) {
                        mapping.map(result, null);
                    }
                }

                // TODO pribeiro we should use polymorphism instead. Build like a chain.
                if (DbResultNodeType.SIMPLE == node.getNodeType()) {
                    final String fieldStringValue = node.getValue();
                    final Object value = mapping.getFieldMapper().mapField(fieldStringValue, mapping.getFieldClass());

                    mapping.map(result, value);
                } else if (DbResultNodeType.MAP == node.getNodeType()) {

                    // TODO all fields are being converted to String and reverted later. The API forces this approach
                    // (DbResultNode.getValue). This should be improved because it's just causing overhead. The driver
                    // can convert at least the basic types so we should reuse this logic. Result tree should be
                    // improved.
                    // Refactor the if/else statements to a more object-based or polymorphic solution.

                    final Object value = ((MapResultNode) node).getMap();
                    mapping.map(result, value);
                } else if (DbResultNodeType.OBJECT == node.getNodeType()) {
                    final Object value = ObjectFieldMapper.mapFromDbObjectNode(mapping.getFieldClass(),
                            (ObjectResultNode) node, mapping);

                    mapping.map(result, value);
                } else if (DbResultNodeType.ARRAY == node.getNodeType()) {
                    final Object value = ArrayFieldMapper.mapField(mapping.getField(), (ArrayResultNode) node);

                    mapping.map(result, value);
                }
            } catch (final Exception e) {
View Full Code Here

TOP

Related Classes of de.zalando.typemapper.core.result.DbResultNode

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.