Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.zalando.typemapper.core.result;
  
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
 
 
 
 public class ObjectResultNode implements DbResultNode {
 
     private static final Logger LOG = LoggerFactory.getLogger(ObjectResultNode.class);
 
     private String name;
     private String type;
     private int typeId;
     private List<DbResultNodechildren;
     private Map<StringDbResultNodenodeMap = new HashMap<>();
 
     public ObjectResultNode(final String valuefinal String namefinal String typeNamefinal int typeId,
             final Connection connectionthrows SQLException {
         super();
         this. = typeName;
         this. = typeId;
         this. = new ArrayList<DbResultNode>();
         this. = name;
 
         List<Stringvalues;
         if (value == null) {
              = null;
             return;
         }
 
         try {
             values = ParseUtils.postgresROW2StringList(value);
         } catch (final RowParserException e) {
             throw new SQLException(e);
         }
 
         final DbType dbType = DbTypeRegister.getDbType(typeIdconnection);
         int i = 1;
         for (final String fieldValue : values) {
             if (dbType == null) {
                 final String error = "dbType is null for typename: " + typeName;
                 .error(error);
                 throw new NullPointerException(error);
             }
 
             final DbTypeField fieldDef = dbType.getFieldByPos(i);
             DbResultNode node = null;
             if (fieldDef == null) {
                 .error("Could not find field in {} for pos "dbTypei);
                 continue;
             }
 
             if (fieldDef.getType().equals("USER-DEFINED")) {
                 if (fieldDef.getTypeName().equals("hstore")) {
                     node = new SimpleResultNode(fieldValuefieldDef.getName());
                 } else if (fieldDef.getTypeName().equals("enumeration")) {
                     node = new SimpleResultNode(fieldValuefieldDef.getName());
                 } else {
                     node = new ObjectResultNode(fieldValuefieldDef.getName(), fieldDef.getTypeName(),
                             fieldDef.getTypeId(), connection);
                 }
             } else if (fieldDef.getType().equals("ARRAY")) {
                 node = new ArrayResultNode(fieldDef.getName(), fieldValuefieldDef.getTypeName().substring(1),
                         fieldDef.getTypeId(), connection);
             } else {
                 node = new SimpleResultNode(fieldValuefieldDef.getName());
             }
 
             this..add(node);
             i++;
         }
     }
 
     public String getType() {
         return ;
     }
 
     @Override
     public DbResultNodeType getNodeType() {
         return .;
     }
 
     @Override
     public String getValue() {
         return null;
     }
    @Override
    public List<DbResultNodegetChildren() {
        return ;
    }
    @Override
    public String getName() {
        return this.;
    }
    @Override
    public DbResultNode getChildByName(final String name) {
        DbResultNode resultNode = .get(name);
        if (resultNode == null) {
            for (final DbResultNode node : getChildren()) {
                if (node.getName().equals(name)) {
                    resultNode = node;
                    .put(nameresultNode);
                    break;
                }
            }
        }
        return resultNode;
    }
    @Override
    public String toString() {
        return "ObjectResultNode [name=" +  + ", type=" +  + ", typeId=" +  + ", children=" + 
                + "]";
    }
New to GrepCode? Check out our FAQ X