Codota Logo
PgArray
Code IndexAdd Codota to your IDE (free)

How to use
PgArray
in
org.postgresql.jdbc

Best Java code snippets using org.postgresql.jdbc.PgArray (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: org.postgresql/postgresql

protected Array makeArray(int oid, String fieldString) throws SQLException {
 return new PgArray(this, oid, fieldString);
}
origin: org.postgresql/postgresql

private int calcRemainingDataLength(int[] dims, int pos, int elementOid, int thisDimension) {
 if (thisDimension == dims.length - 1) {
  for (int i = 0; i < dims[thisDimension]; ++i) {
   int len = ByteConverter.int4(fieldBytes, pos);
   pos += 4;
   if (len == -1) {
    continue;
   }
   pos += len;
  }
 } else {
  pos = calcRemainingDataLength(dims, elementOid, pos, thisDimension + 1);
 }
 return pos;
}
origin: org.postgresql/postgresql

/**
 * {@inheritDoc}
 */
@Override
public void appendArray(StringBuilder sb, char delim, String[] array) {
 sb.append('{');
 for (int i = 0; i < array.length; ++i) {
  if (i > 0) {
   sb.append(delim);
  }
  if (array[i] == null) {
   sb.append('N');
   sb.append('U');
   sb.append('L');
   sb.append('L');
  } else {
   PgArray.escapeArrayElement(sb, array[i]);
  }
 }
 sb.append('}');
}
origin: debezium/debezium

  private Object getArray(PgProto.DatumMessage datumMessage, PgConnectionSupplier connection, int columnType) {
    // Currently the logical decoding plugin sends unhandled types as a byte array containing the string
    // representation (in Postgres) of the array value.
    // The approach to decode this is sub-optimal but the only way to improve this is to update the plugin.
    // Reasons for it being sub-optimal include:
    // 1. It requires a Postgres JDBC connection to deserialize
    // 2. The byte-array is a serialised string but we make the assumption its UTF-8 encoded (which it will
    //    be in most cases)
    // 3. For larger arrays and especially 64-bit integers and the like it is less efficient sending string
    //    representations over the wire.
    try {
      byte[] data = datumMessage.hasDatumBytes()? datumMessage.getDatumBytes().toByteArray() : null;
      if (data == null) return null;
      String dataString = new String(data, Charset.forName("UTF-8"));
      PgArray arrayData = new PgArray(connection.get(), columnType, dataString);
      Object deserializedArray = arrayData.getArray();
      return Arrays.asList((Object[])deserializedArray);
    }
    catch (SQLException e) {
      LOGGER.warn("Unexpected exception trying to process PgArray column '{}'", datumMessage.getColumnName(), e);
    }
    return null;
  }
}
origin: org.postgresql/postgresql

 return readBinaryResultSet((int) index, count);
buildArrayList();
  t[1] = v == null ? null : connection.encodeString(toString((PgArrayList) v));
  rows.add(t);
origin: org.postgresql/postgresql

/**
 * Convert array list to PG String representation (e.g. {0,1,2}).
 */
private String toString(PgArrayList list) throws SQLException {
 if (list == null) {
  return "NULL";
 }
 StringBuilder b = new StringBuilder().append('{');
 char delim = connection.getTypeInfo().getArrayDelimiter(oid);
 for (int i = 0; i < list.size(); i++) {
  Object v = list.get(i);
  if (i > 0) {
   b.append(delim);
  }
  if (v == null) {
   b.append("NULL");
  } else if (v instanceof PgArrayList) {
   b.append(toString((PgArrayList) v));
  } else {
   escapeArrayElement(b, (String) v);
  }
 }
 b.append('}');
 return b.toString();
}
origin: org.postgresql/postgresql

public String toString() {
 if (fieldString == null && fieldBytes != null) {
  try {
   Object array = readBinaryArray(1, 0);
   final PrimitiveArraySupport arraySupport = PrimitiveArraySupport.getArraySupport(array);
   if (arraySupport != null) {
    fieldString = arraySupport.toArrayString(connection.getTypeInfo().getArrayDelimiter(oid), array);
   } else {
    java.sql.Array tmpArray = connection.createArrayOf(getBaseTypeName(), (Object[]) array);
    fieldString = tmpArray.toString();
   }
  } catch (SQLException e) {
   fieldString = "NULL"; // punt
  }
 }
 return fieldString;
}
origin: zalando-stups/java-sproc-wrapper

  final String typeName = arrayObj.getBaseTypeName();
  final String value = arrayObj.toString();
  node = new ArrayResultNode(name, value, typeName, typeId, pgSet.getStatement().getConnection());
} else {
origin: org.postgresql/postgresql

public Object getArrayImpl(long index, int count, Map<String, Class<?>> map) throws SQLException {
 // for now maps aren't supported.
 if (map != null && !map.isEmpty()) {
  throw org.postgresql.Driver.notImplemented(this.getClass(), "getArrayImpl(long,int,Map)");
 }
 // array index is out of range
 if (index < 1) {
  throw new PSQLException(GT.tr("The array index is out of range: {0}", index),
    PSQLState.DATA_ERROR);
 }
 if (fieldBytes != null) {
  return readBinaryArray((int) index, count);
 }
 if (fieldString == null) {
  return null;
 }
 buildArrayList();
 if (count == 0) {
  count = arrayList.size();
 }
 // array index out of range
 if ((--index) + count > arrayList.size()) {
  throw new PSQLException(
    GT.tr("The array index is out of range: {0}, number of elements: {1}.",
      index + count, (long) arrayList.size()),
    PSQLState.DATA_ERROR);
 }
 return buildArray(arrayList, (int) index, count);
}
origin: org.postgresql/postgresql

  : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : BooleanTypeUtil.castToBoolean((String) o));
} else {
 pa[length++] = o == null ? false : BooleanTypeUtil.castToBoolean((String) o);
   : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : PgResultSet.toShort((String) o));
} else {
 pa[length++] = o == null ? 0 : PgResultSet.toShort((String) o);
   : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : PgResultSet.toInt((String) o));
} else {
 pa[length++] = o == null ? 0 : PgResultSet.toInt((String) o);
   : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : PgResultSet.toLong((String) o));
} else {
 pa[length++] = o == null ? 0L : PgResultSet.toLong((String) o);
oa[length++] = dims > 1 && v != null ? buildArray((PgArrayList) v, 0, -1)
  : (v == null ? null : PgResultSet.toBigDecimal((String) v));
   : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : PgResultSet.toFloat((String) o));
} else {
 pa[length++] = o == null ? 0f : PgResultSet.toFloat((String) o);
   : (dims > 1 ? buildArray((PgArrayList) o, 0, -1) : PgResultSet.toDouble((String) o));
} else {
 pa[length++] = o == null ? 0d : PgResultSet.toDouble((String) o);
oa[length++] = dims > 1 && v != null ? buildArray((PgArrayList) v, 0, -1) : v;
origin: org.postgresql/postgresql

public int getBaseType() throws SQLException {
 return connection.getTypeInfo().getSQLType(getBaseTypeName());
}
origin: org.postgresql/postgresql

private Object readBinaryArray(int index, int count) throws SQLException {
 int dimensions = ByteConverter.int4(fieldBytes, 0);
 // int flags = ByteConverter.int4(fieldBytes, 4); // bit 0: 0=no-nulls, 1=has-nulls
 int elementOid = ByteConverter.int4(fieldBytes, 8);
 int pos = 12;
 int[] dims = new int[dimensions];
 for (int d = 0; d < dimensions; ++d) {
  dims[d] = ByteConverter.int4(fieldBytes, pos);
  pos += 4;
  /* int lbound = ByteConverter.int4(fieldBytes, pos); */
  pos += 4;
 }
 if (dimensions == 0) {
  return java.lang.reflect.Array.newInstance(elementOidToClass(elementOid), 0);
 }
 if (count > 0) {
  dims[0] = Math.min(count, dims[0]);
 }
 Object arr = java.lang.reflect.Array.newInstance(elementOidToClass(elementOid), dims);
 try {
  storeValues((Object[]) arr, elementOid, dims, pos, 0, index);
 } catch (IOException ioe) {
  throw new PSQLException(
    GT.tr(
      "Invalid character data was found.  This is most likely caused by stored data containing characters that are invalid for the character set the database was created in.  The most common example of this is storing 8bit data in a SQL_ASCII database."),
    PSQLState.DATA_ERROR, ioe);
 }
 return arr;
}
origin: org.postgresql/postgresql

public Object getArray() throws SQLException {
 return getArrayImpl(1, 0, null);
}
origin: org.postgresql/postgresql

public String getBaseTypeName() throws SQLException {
 buildArrayList();
 int elementOID = connection.getTypeInfo().getPGArrayElement(oid);
 return connection.getTypeInfo().getPGType(elementOID);
}
origin: debezium/debezium

try {
  final String dataString = rawValue.asString();
  PgArray arrayData = new PgArray(connection.get(), type.getOid(), dataString);
  Object deserializedArray = arrayData.getArray();
  return Arrays.asList((Object[])deserializedArray);
origin: org.postgresql/postgresql

public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
 return getArrayImpl(index, count, map);
}
origin: io.debezium/debezium-connector-postgres

  private Object getArray(PgProto.DatumMessage datumMessage, PgConnectionSupplier connection, int columnType) {
    // Currently the logical decoding plugin sends unhandled types as a byte array containing the string
    // representation (in Postgres) of the array value.
    // The approach to decode this is sub-optimal but the only way to improve this is to update the plugin.
    // Reasons for it being sub-optimal include:
    // 1. It requires a Postgres JDBC connection to deserialize
    // 2. The byte-array is a serialised string but we make the assumption its UTF-8 encoded (which it will
    //    be in most cases)
    // 3. For larger arrays and especially 64-bit integers and the like it is less efficient sending string
    //    representations over the wire.
    try {
      byte[] data = datumMessage.hasDatumBytes()? datumMessage.getDatumBytes().toByteArray() : null;
      if (data == null) return null;
      String dataString = new String(data, Charset.forName("UTF-8"));
      PgArray arrayData = new PgArray(connection.get(), columnType, dataString);
      Object deserializedArray = arrayData.getArray();
      return Arrays.asList((Object[])deserializedArray);
    }
    catch (SQLException e) {
      LOGGER.warn("Unexpected exception trying to process PgArray column '{}'", datumMessage.getColumnName(), e);
    }
    return null;
  }
}
origin: org.postgresql/postgresql

protected Array makeArray(int oid, byte[] value) throws SQLException {
 return new PgArray(connection, oid, value);
}
origin: org.postgresql/postgresql

public Object getArray(long index, int count) throws SQLException {
 return getArrayImpl(index, count, null);
}
origin: org.postgresql/postgresql

int dimensionsLeft = dims.length - nextDimension;
for (int i = 1; i < index; ++i) {
 pos = calcRemainingDataLength(dims, pos, elementOid, nextDimension);
 ByteConverter.int4(rowData[0], 0, i + index);
 rows.add(rowData);
 int dataEndPos = calcRemainingDataLength(dims, pos, elementOid, nextDimension);
 int dataLength = dataEndPos - pos;
 rowData[1] = new byte[12 + 8 * dimensionsLeft + dataLength];
org.postgresql.jdbcPgArray

Javadoc

Array is used collect one column of query result data.

Read a field of type Array into either a natively-typed Java array object or a ResultSet. Accessor methods provide the ability to capture array slices.

Other than the constructor all methods are direct implementations of those specified for java.sql.Array. Please refer to the javadoc for java.sql.Array for detailed descriptions of the functionality and parameters of the methods of this class.

Most used methods

  • <init>
    Create a new Array.
  • getBaseTypeName
  • toString
    Convert array list to PG String representation (e.g. {0,1,2}).
  • buildArray
    Convert ArrayList to array.
  • buildArrayList
    Build ArrayList from field's string input. As a result of this method #arrayList is build. Method ca
  • calcRemainingDataLength
  • elementOidToClass
  • escapeArrayElement
  • getArray
  • getArrayImpl
  • getResultSetImpl
  • isBinary
  • getResultSetImpl,
  • isBinary,
  • readBinaryArray,
  • readBinaryResultSet,
  • storeValues,
  • toBytes

Popular in Java

  • Parsing JSON documents to java classes using gson
  • findViewById (Activity)
  • runOnUiThread (Activity)
  • addToBackStack (FragmentTransaction)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • ResourceBundle (java.util)
    Resource bundles contain locale-specific objects. When your program needs a locale-specific resource
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Runner (org.openjdk.jmh.runner)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now