public void insertBlobForStreamingLoad(Row row, Column col, JDBCStore store, Object ob, Select sel) throws SQLException { if (row.getAction() == Row.ACTION_INSERT) { insertPostgresBlob(row, col, store, ob); } else if (row.getAction() == Row.ACTION_UPDATE) { updatePostgresBlob(row, col, store, ob, sel); } }
return isOwnedSequence(strName); String[][] namePairs = buildNames(strName); if (queryOwnership(conn, namePairs[i], schema)) { return true; if (log.isWarnEnabled()) log.warn(_loc.get("psql-owned-seq-warning"), t); return isOwnedSequence(strName); return isOwnedSequence(strName);
/** * Get the native PostgreSQL connection from the given connection. * Various attempts of unwrapping are being performed. */ protected PGConnection getPGConnection(DelegatingConnection conn) { Connection innerConn = conn.getInnermostDelegate(); if (innerConn instanceof PGConnection) { return (PGConnection) innerConn; } if (innerConn.getClass().getName().startsWith("org.apache.commons.dbcp")) { return (PGConnection) getDbcpDelegate(innerConn); } return (PGConnection) unwrapConnection(conn, PGConnection.class); }
ResultSet rs = null; try { ps = prepareStatement(conn, isOwnedSequenceSQL); String tblName = ""; if (!DBIdentifier.isEmpty(schema)) { tblName = schema.getName() + getIdentifierDelimiter(); String colName = toDBName(DBIdentifier.newColumn(namePair[1])); ps.setString(2, colName); ps.execute(); return false; String val = getString(rs, 1); if (val == null || val.length() == 0) { return false;
stmnt = sql.prepareStatement(conn, fetch, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); setTimeouts(stmnt, fetch, true); res = stmnt.executeQuery(); if (!res.next()) { if (oid != -1) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); if (ob != null) { LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); long size = copy((InputStream) ob, os); lo.truncate((int) size); lo.close(); if (ob != null) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid);
private void insertPostgresBlob(Row row, Column col, JDBCStore store, Object ob) throws SQLException { if (ob != null) { col.setType(Types.INTEGER); DelegatingConnection conn = (DelegatingConnection)store .getConnection(); try { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); // The create method is valid in versions previous to 8.3 // in 8.3 this method is deprecated, use createLO int oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid); } catch (IOException ioe) { throw new StoreException(ioe); } finally { conn.close(); } } else { row.setInt(col, -1); } }
/** * Append XML column value so that it can be used in comparisons. * * @param buf * the SQL buffer to write the value * @param val * the value to be written */ private void appendXmlValue(SQLBuffer buf, FilterValue val) { Class rc = Filters.wrap(val.getType()); int type = getJDBCType(JavaTypes.getTypeCode(rc), false); boolean isXmlAttribute = (val.getXmlMapping() == null) ? false : val.getXmlMapping().isXmlAttribute(); SQLBuffer newBufer = new SQLBuffer(this); newBufer.append("(xpath('/*/"); val.appendTo(newBufer); if (!isXmlAttribute) newBufer.append("/text()"); newBufer.append("',"). append(val.getColumnAlias(val.getFieldMapping().getColumns()[0])). append("))[1]"); appendCast(buf, newBufer, type); }
public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start) { buf.append("(POSITION("); find.appendTo(buf); buf.append(" IN "); if (start != null) substring(buf, str, start, null); else str.appendTo(buf); buf.append(") - 1"); if (start != null) { buf.append(" + "); start.appendTo(buf); } buf.append(")"); }
/** * Append XML comparison. * * @param buf * the SQL buffer to write the comparison * @param op * the comparison operation to perform * @param lhs * the left hand side of the comparison * @param rhs * the right hand side of the comparison * @param lhsxml * indicates whether the left operand maps to XML * @param rhsxml * indicates whether the right operand maps to XML */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml) appendXmlValue(buf, lhs); else lhs.appendTo(buf); buf.append(" ").append(op).append(" "); if (rhsxml) appendXmlValue(buf, rhs); else rhs.appendTo(buf); }
LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); } else { LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid);
ResultSet rs = null; try { ps = prepareStatement(conn, isOwnedSequenceSQL); String tblName = ""; if (!DBIdentifier.isEmpty(schema)) { tblName = schema.getName() + getIdentifierDelimiter(); String colName = toDBName(DBIdentifier.newColumn(namePair[1])); ps.setString(2, colName); ps.execute(); return false; String val = getString(rs, 1); if (val == null || val.length() == 0) { return false;
stmnt = sql.prepareStatement(conn, fetch, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); setTimeouts(stmnt, fetch, true); res = stmnt.executeQuery(); if (!res.next()) { if (oid != -1) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); if (ob != null) { LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); long size = copy((InputStream) ob, os); lo.truncate((int) size); lo.close(); if (ob != null) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid);
private void insertPostgresBlob(Row row, Column col, JDBCStore store, Object ob) throws SQLException { if (ob != null) { col.setType(Types.INTEGER); DelegatingConnection conn = (DelegatingConnection)store .getConnection(); try { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); // The create method is valid in versions previous to 8.3 // in 8.3 this method is deprecated, use createLO int oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid); } catch (IOException ioe) { throw new StoreException(ioe); } finally { conn.close(); } } else { row.setInt(col, -1); } }
/** * Append XML column value so that it can be used in comparisons. * * @param buf * the SQL buffer to write the value * @param val * the value to be written */ private void appendXmlValue(SQLBuffer buf, FilterValue val) { Class rc = Filters.wrap(val.getType()); int type = getJDBCType(JavaTypes.getTypeCode(rc), false); boolean isXmlAttribute = (val.getXmlMapping() == null) ? false : val.getXmlMapping().isXmlAttribute(); SQLBuffer newBufer = new SQLBuffer(this); newBufer.append("(xpath('/*/"); val.appendTo(newBufer); if (!isXmlAttribute) newBufer.append("/text()"); newBufer.append("',"). append(val.getColumnAlias(val.getFieldMapping().getColumns()[0])). append("))[1]"); appendCast(buf, newBufer, type); }
@Override public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start) { buf.append("(POSITION("); find.appendTo(buf); buf.append(" IN "); if (start != null) substring(buf, str, start, null); else str.appendTo(buf); buf.append(")"); if (start != null) { buf.append(" - 1 + "); start.appendTo(buf); } buf.append(")"); }
/** * Append XML comparison. * * @param buf * the SQL buffer to write the comparison * @param op * the comparison operation to perform * @param lhs * the left hand side of the comparison * @param rhs * the right hand side of the comparison * @param lhsxml * indicates whether the left operand maps to XML * @param rhsxml * indicates whether the right operand maps to XML */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml) appendXmlValue(buf, lhs); else lhs.appendTo(buf); buf.append(" ").append(op).append(" "); if (rhsxml) appendXmlValue(buf, rhs); else rhs.appendTo(buf); }
private void insertPostgresBlob(Row row, Column col, JDBCStore store, Object ob) throws SQLException { if (ob != null) { col.setType(Types.INTEGER); DelegatingConnection conn = (DelegatingConnection)store .getConnection(); try { conn.setAutoCommit(false); PGConnection pgconn = (PGConnection) conn.getInnermostDelegate(); LargeObjectManager lom = pgconn.getLargeObjectAPI(); // The create method is valid in versions previous 8.3 // in 8.3 this methos is deprecated, use createLO int oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid); } catch (IOException ioe) { throw new StoreException(ioe); } finally { conn.close(); } } else { row.setInt(col, -1); } }
ResultSet rs = null; try { ps = prepareStatement(conn, isOwnedSequenceSQL); String tblName = ""; if (!DBIdentifier.isEmpty(schema)) { tblName = schema.getName() + getIdentifierDelimiter(); String colName = toDBName(DBIdentifier.newColumn(namePair[1])); ps.setString(2, colName); ps.execute(); return false; String val = getString(rs, 1); if (val == null || val.length() == 0) { return false;
stmnt = sql.prepareStatement(conn, fetch, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); setTimeouts(stmnt, fetch, true); res = stmnt.executeQuery(); if (!res.next()) { if (oid != -1) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); if (ob != null) { LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); long size = copy((InputStream) ob, os); lo.truncate((int) size); lo.close(); if (ob != null) { conn.setAutoCommit(false); LargeObjectManager lom = getLargeObjectManager(conn); oid = lom.create(); LargeObject lo = lom.open(oid, LargeObjectManager.WRITE); OutputStream os = lo.getOutputStream(); copy((InputStream)ob, os); lo.close(); row.setInt(col, oid);
return isOwnedSequence(strName); String[][] namePairs = buildNames(strName); if (queryOwnership(conn, namePairs[i], schema)) { return true; if (log.isWarnEnabled()) log.warn(_loc.get("psql-owned-seq-warning"), t); return isOwnedSequence(strName); return isOwnedSequence(strName);