Package com.impossibl.postgres.types

Examples of com.impossibl.postgres.types.Type


  }

  @Override
  public String getParameterClassName(int param) throws SQLException {

    Type paramType = getType(param);

    return paramType.getJavaType(paramType.getPreferredFormat(), typeMap).getName();
  }
View Full Code Here


        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

    @Override
    public void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

      RangeType rangeType = (RangeType) type;
      Type baseType = rangeType.getBase();

      Range<?> range = (Range<?>) val;

      if (range.isLowerBoundInclusive()) {
        buffer.append('[');
      }
      else {
        buffer.append('(');
      }

      if (range.hasLowerBound()) {
        StringBuilder lowerBuffer = new StringBuilder();
        baseType.getTextCodec().encoder.encode(baseType, lowerBuffer, range.getLowerBound(), context);
        String lower = lowerBuffer.toString();

        if (needsQuotes(lower)) {
          buffer.append('"').append(lower).append('"');
        }
        else {
          buffer.append(lower);
        }
      }

      buffer.append(',');

      if (range.hasUpperBound()) {
        StringBuilder upperBuffer = new StringBuilder();
        baseType.getTextCodec().encoder.encode(baseType, upperBuffer, range.getUpperBound(), context);
        String upper = upperBuffer.toString();

        if (needsQuotes(upper)) {
          buffer.append('"').append(upper).append('"');
        }
View Full Code Here

        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()) {

            context.refreshType(attributeType.getId());
          }

          Object attributeVal = attributeType.getBinaryCodec().decoder.decode(attributeType, null, null, buffer, context);

          attributeVals[c] = attributeVal;
        }

        if (length != buffer.readerIndex() - readStart) {
View Full Code Here

        buffer.writeInt(attributes.size());

        for (Attribute attribute : attributes) {

          Type attributeType = attribute.type;

          buffer.writeInt(attributeType.getId());

          Object attributeVal = attributeVals[attribute.number - 1];

          attributeType.getBinaryCodec().encoder.encode(attributeType, buffer, attributeVal, context);
        }

        //Set length
        buffer.setInt(writeStart - 4, buffer.writerIndex() - writeStart);
      }
View Full Code Here

        length += 4;

        for (Attribute attribute : attributes) {

          Type attributeType = attribute.type;

          length += 4;

          int idx = attribute.number > 0 ? attribute.number - 1 : attributes.size() + attribute.number;

          Object attributeVal = attributeVals[idx];

          length += attributeType.getBinaryCodec().encoder.length(attributeType, attributeVal, context);
        }

      }

      return length;
View Full Code Here

      while (rs.next()) {

        String schema = rs.getString("nspname");
        String procedureName = rs.getString("proname");
        String specificName = rs.getString("proname") + "_" + rs.getString("oid");
        Type returnType = reg.loadType(rs.getInt("prorettype"));
        String returnTypeType = rs.getString("typtype");
        int returnTypeRelId = rs.getInt("typrelid");

        Integer[] argTypeIds = rs.getObject("proargtypes", Integer[].class);
        String[] argNames = rs.getObject("proargnames", String[].class);
        String[] argModes = rs.getObject("proargmodes", String[].class);
        Integer[] allArgTypeIds = rs.getObject("proallargtypes", Integer[].class);

        int numArgs = allArgTypeIds != null ? allArgTypeIds.length : argTypeIds.length;

        // decide if we are returning a single column result.
        if (returnTypeType.equals("b") ||
            returnTypeType.equals("d") ||
            (returnTypeType.equals("p") && argModes == null)) {

          Object[] row = new Object[resultFields.length];
          row[0] = null;
          row[1] = schema;
          row[2] = procedureName;
          row[3] = "returnValue";
          row[4] = DatabaseMetaData.procedureColumnReturn;
          row[5] = SQLTypeMetaData.getSQLType(returnType);
          row[6] = SQLTypeMetaData.getTypeName(returnType, null, 0);
          row[7] = null;
          row[8] = null;
          row[9] = null;
          row[10] = null;
          row[11] = DatabaseMetaData.procedureNullableUnknown;
          row[12] = null;
          row[17] = 0;
          row[18] = "";
          row[19] = specificName;

          results.add(row);
        }

        // Add a row for each argument.
        for (int i = 0; i < numArgs; i++) {

          Object[] row = new Object[resultFields.length];
          row[0] = null;
          row[1] = schema;
          row[2] = procedureName;

          if (argNames != null) {
            row[3] = argNames[i];
          }
          else {
            row[3] = "$" + (i + 1);
          }

          int columnMode = DatabaseMetaData.procedureColumnIn;
          if (argModes != null) {

            if (argModes[i].equals("o")) {
              columnMode = DatabaseMetaData.procedureColumnOut;
            }
            else if (argModes[i].equals("b")) {
              columnMode = DatabaseMetaData.procedureColumnInOut;
            }
          }

          row[4] = columnMode;

          Type argType;
          if (allArgTypeIds != null) {
            argType = reg.loadType(allArgTypeIds[i].intValue());
          }
          else {
            argType = reg.loadType(argTypeIds[i].intValue());
          }

          row[5] = SQLTypeMetaData.getSQLType(argType);
          row[6] = argType.getJavaType(argType.getPreferredFormat(), connection.getTypeMap()).getName();
          row[7] = null;
          row[8] = null;
          row[9] = null;
          row[10] = null;
          row[11] = DatabaseMetaData.procedureNullableUnknown;
          row[12] = null;
          row[17] = i + 1;
          row[18] = "";
          row[19] = specificName;

          results.add(row);
        }

        // if we are returning a multi-column result.
        if (returnTypeType.equals("c") ||
            (returnTypeType.equals("p") && argModes != null && returnTypeRelId != 0)) {

          String columnsql = "SELECT a.attname,a.atttypid FROM pg_catalog.pg_attribute a WHERE a.attrelid = " + returnTypeRelId + " AND a.attnum > 0 ORDER BY a.attnum ";
          try (ResultSet columnrs = connection.createStatement().executeQuery(columnsql)) {
            while (columnrs.next()) {
              Type columnType = reg.loadType(columnrs.getInt("atttypid"));

              Object[] row = new Object[resultFields.length];
              row[0] = null;
              row[1] = schema;
              row[2] = procedureName;
              row[3] = columnrs.getString("attname");
              row[4] = DatabaseMetaData.procedureColumnResult;
              row[5] = SQLTypeMetaData.getSQLType(columnType);
              row[6] = columnType.getJavaType(columnType.getPreferredFormat(), connection.getTypeMap()).getName();
              row[7] = null;
              row[8] = null;
              row[9] = null;
              row[10] = null;
              row[11] = DatabaseMetaData.procedureNullableUnknown;
View Full Code Here

    try (ResultSet rs = execForResultSet(sql.toString(), params)) {
      while (rs.next()) {

        Object[] row = new Object[8];
        Type type = reg.loadType(rs.getInt("atttypid"));
        int typeLen = rs.getInt("attlen");
        int typeMod = rs.getInt("atttypmod");
        int decimalDigits = SQLTypeMetaData.getScale(type, typeLen, typeMod);
        int columnSize = SQLTypeMetaData.getPrecision(type, typeLen, typeMod);
        if (columnSize == 0) {
View Full Code Here

     * ctid, xmax, xmin, cmax, and cmin.  Depending on if we are
     * in a transaction and wether we roll it back or not the
     * only guaranteed change is to ctid. -KJ
     */

    Type type = reg.loadType("tid");

    row[0] = null;
    row[1] = "ctid";
    row[2] = SQLTypeMetaData.getSQLType(type);
    row[3] = SQLTypeMetaData.getTypeName(type, null, 0);
View Full Code Here

    try (ResultSet rs = execForResultSet(sql)) {
      while (rs.next()) {

        Object[] row = new Object[18];
        int typeOid = rs.getInt(2);
        Type type = registry.loadType(typeOid);

        row[0] = SQLTypeMetaData.getTypeName(type, null, 0);
        row[1] = SQLTypeMetaData.getSQLType(type);
        row[2] = SQLTypeMetaData.getMaxPrecision(type);
View Full Code Here

TOP

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

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.