Package com.impossibl.postgres.types

Examples of com.impossibl.postgres.types.CompositeType


   */
  CompositeType.Attribute getRelAttr(int columnIndex) throws SQLException {

    ResultField field = get(columnIndex);

    CompositeType relType = connection.getRegistry().loadRelationType(field.relationId);
    if (relType == null)
      return null;

    return relType.getAttribute(field.relationAttributeNumber);
  }
View Full Code Here


  @Override
  public boolean isAutoIncrement(int column) throws SQLException {

    ResultField field = get(column);
    CompositeType relType = connection.getRegistry().loadRelationType(field.relationId);

    return SQLTypeMetaData.isAutoIncrement(field.typeRef.get(), relType, field.relationAttributeNumber);
  }
View Full Code Here

  @Override
  public int isNullable(int column) throws SQLException {

    ResultField field = get(column);
    CompositeType relType = connection.getRegistry().loadRelationType(field.relationId);

    return SQLTypeMetaData.isNullable(field.typeRef.get(), relType, field.relationAttributeNumber);
  }
View Full Code Here

    //Note: there seems to be some debate about whether this should return
    //query aliases or table names. We are returning table names, if
    //available, as this is at least more useful than always returning
    //null since we never have the query table aliases

    CompositeType relType = getRelType(column);
    if (relType == null)
      return "";

    return relType.getName();
  }
View Full Code Here

  @Override
  public String getColumnTypeName(int column) throws SQLException {

    ResultField field = get(column);
    CompositeType relType = connection.getRegistry().loadRelationType(field.relationId);

    return SQLTypeMetaData.getTypeName(field.typeRef.get(), relType, field.relationAttributeNumber);
  }
View Full Code Here

      return new PGStruct(connection, ((Record) val).getType(), ((Record) val).getValues());
    }
    else if (SQLData.class.isInstance(val) && sourceType instanceof CompositeType) {

      CompositeType compType = (CompositeType) sourceType;

      PGSQLOutputImpl out = new PGSQLOutputImpl(connection, compType);

      ((SQLData) val).writeSQL(out);

      return new PGStruct(connection, compType, out.getAttributeValues());
    }
    else if (val instanceof Object[] && sourceType instanceof CompositeType) {

      CompositeType compType = (CompositeType) sourceType;

      return new PGStruct(connection, compType, (Object[]) val);
    }

    throw createCoercionException(val.getClass(), Struct.class);
View Full Code Here

      return (Record) val;
    }
    else if (sourceType instanceof CompositeType) {

      CompositeType compType = (CompositeType) sourceType;

      Object[] attributeVals;

      if (val instanceof Struct) {

        Struct struct = (Struct) val;
        attributeVals = struct.getAttributes();
      }
      else if (SQLData.class.isInstance(val)) {

        PGSQLOutputImpl out = new PGSQLOutputImpl(connection, compType);

        ((SQLData) val).writeSQL(out);

        attributeVals = out.getAttributeValues();
      }
      else {

        throw createCoercionException(val.getClass(), Record.class);
      }

      if (compType.getAttributes().size() != attributeVals.length) {

        throw createCoercionException(val.getClass(), Record.class);
      }

      for (int c = 0; c < attributeVals.length; ++c) {

        Type attrType = compType.getAttribute(c + 1).type;
        Class<?> attrTargetType = mapSetType(format, attrType);

        attributeVals[c] = coerce(format, attributeVals[c], attrType, attrTargetType, typeMap, zone, connection);
      }
View Full Code Here

      return null;
    }
    else if (sourceType instanceof CompositeType) {

      CompositeType compType = (CompositeType) sourceType;

      Object[] attributeVals;

      if (val instanceof Struct) {

        Struct struct = (Struct) val;
        attributeVals = struct.getAttributes();
      }
      else if (val instanceof Record) {

        Record record = (Record) val;
        attributeVals = record.getValues();
      }
      else {

        throw createCoercionException(val.getClass(), targetType);
      }

      Object dst;
      try {
        dst = targetType.newInstance();
      }
      catch (InstantiationException | IllegalAccessException e) {
        throw createCoercionException(val.getClass(), targetType, e);
      }

      PGSQLInputImpl in = new PGSQLInputImpl(connection, compType, typeMap, attributeVals);

      ((SQLData) dst).readSQL(in, compType.getName());

      return dst;
    }

    throw createCoercionException(val.getClass(), targetType);
View Full Code Here

    }

    @Override
    public Object decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException {

      CompositeType compType = (CompositeType) type;

      Record record = null;

      int length = buffer.readInt();

      if (length != -1) {

        long readStart = buffer.readerIndex();

        int itemCount = buffer.readInt();

        Object[] attributeVals = new Object[itemCount];

        for (int c = 0; c < itemCount; ++c) {

          Attribute attribute = compType.getAttribute(c + 1);

          Type attributeType = context.getRegistry().loadType(buffer.readInt());

          if (attributeType.getId() != attribute.type.getId()) {
View Full Code Here

        Record record = (Record) val;

        Object[] attributeVals = record.getValues();

        CompositeType compType = (CompositeType) type;

        Collection<Attribute> attributes = compType.getAttributes();

        buffer.writeInt(attributes.size());

        for (Attribute attribute : attributes) {
View Full Code Here

TOP

Related Classes of com.impossibl.postgres.types.CompositeType

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.