/** * Moves internal ResultSet cursor position down one row. Checks if the next row is * available. */ protected void checkNextRow() throws CayenneException { nextRow = false; try { if ((fetchLimit <= 0 || fetchedSoFar < fetchLimit) && resultSet.next()) { nextRow = true; fetchedSoFar++; } } catch (SQLException e) { throw new CayenneException("Error rewinding ResultSet", e); } }
/** * Creates new DistinctResultIterator wrapping another ResultIterator. * * @param wrappedIterator * @param defaultEntity an entity needed to build ObjectIds for distinct comparison. */ public DistinctResultIterator(ResultIterator wrappedIterator, DbEntity defaultEntity, boolean compareFullRows) throws CayenneException { if (wrappedIterator == null) { throw new CayenneException("Null wrapped iterator."); } if (defaultEntity == null) { throw new CayenneException("Null defaultEntity."); } this.wrappedIterator = wrappedIterator; this.defaultEntity = defaultEntity; this.fetchedIds = new HashSet(); this.compareFullRows = compareFullRows; checkNextRow(); }
/** * @see org.apache.cayenne.access.ResultIterator#skipDataRow() */ public void skipDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException("An attempt to read uninitialized row or past the end of the iterator."); } try { checkNextRow(); } catch (SQLException sqex) { throw new CayenneException("Exception reading ResultSet.", sqex); } }
public ResultIterator getResultIterator() throws CayenneException { if (super.hasExceptions()) { StringWriter str = new StringWriter(); PrintWriter out = new PrintWriter(str); super.printExceptions(out); try { out.close(); str.close(); } catch (IOException ioex) { // this should never happen } throw new CayenneException( "Error getting ResultIterator: " + str.getBuffer()); } return resultIterator; }
public Map nextDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } Map row = nextDataRow; checkNextRow(); return row; }
/** * Returns the next result row as a Map. */ public Map nextDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException("An attempt to read uninitialized row or past the end of the iterator."); } try { // read Map row = readDataRow(); // rewind checkNextRow(); return row; } catch (SQLException sqex) { throw new CayenneException("Exception reading ResultSet.", sqex); } }
/** * Returns a map of ObjectId values from the next result row. * Primary key columns are determined from the provided DbEntity. * * @since 1.1 */ public Map nextObjectId(DbEntity entity) throws CayenneException { if (!hasNextRow()) { throw new CayenneException("An attempt to read uninitialized row or past the end of the iterator."); } try { // read Map row = readIdRow(entity); // rewind checkNextRow(); return row; } catch (SQLException sqex) { throw new CayenneException("Exception reading ResultSet.", sqex); } } }
void checkNextRow() throws CayenneException { if (readingIds) { throw new CayenneException( "Can't go back from reading ObjectIds to reading rows."); } if (this.compareFullRows) { checkNextUniqueRow(); } else { checkNextRowWithUniqueId(); } }
public void skipDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } checkNextRow(); }
void checkNextId(DbEntity entity) throws CayenneException { if (entity == null) { throw new CayenneException("Null DbEntity, can't create id."); } this.readingIds = true; this.nextDataRow = null; while (wrappedIterator.hasNextRow()) { Map next = wrappedIterator.nextObjectId(entity); // if we are reading ids, we ignore "compareFullRows" setting if (fetchedIds.add(next)) { this.nextDataRow = next; break; } } } }
/** * Returns a Map for the next ObjectId. After calling this method, calls to * "nextDataRow()" will result in exceptions. */ public Map nextObjectId(DbEntity entity) throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } Map row = nextDataRow; // if we were previously reading full rows, we need to strip extra keys... if (!readingIds) { Iterator it = row.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); DbAttribute attribute = (DbAttribute) entity.getAttribute(name); if (attribute == null || !attribute.isPrimaryKey()) { it.remove(); } } } checkNextId(entity); return row; }
@Override public String materializeObject(CallableStatement cs, int index, int type) throws Exception { if (type == Types.CLOB || type == Types.NCLOB) { if (!isUsingClobs()) { throw new CayenneException("Character streams are not supported in stored procedure parameters."); } return readClob(cs.getClob(index)); } return handleString(cs.getString(index), type); }
public void skipDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } if (readingIds) { checkNextId(defaultEntity); } else { checkNextRow(); } }
/** Return trimmed string. */ public Object materializeObject(CallableStatement cs, int index, int type) throws Exception { String val = null; // CLOB handling if (type == Types.CLOB) { if (!isUsingClobs()) { throw new CayenneException( "Character streams are not supported in stored procedure parameters."); } val = readClob(cs.getClob(index)); } else { val = cs.getString(index); // trim CHAR type if (val != null && type == Types.CHAR && isTrimmingChars()) { val = val.trim(); } } return val; }
/** * Returns the next result row as a Map. */ public Map nextDataRow() throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } // read Map row = readDataRow(); // rewind checkNextRow(); return row; }
/** * Returns a map of ObjectId values from the next result row. Primary key columns are * determined from the provided DbEntity. */ public Map nextObjectId(DbEntity entity) throws CayenneException { if (!hasNextRow()) { throw new CayenneException( "An attempt to read uninitialized row or past the end of the iterator."); } // index id if (rootEntity != entity || pkIndices == null) { this.rootEntity = entity; indexPK(); } // read ... // TODO: note a mismatch with 1.1 API - ID positions are preset and are // not affected by the entity specified (think of deprecating/replacing this) Map row = readIdRow(); // rewind checkNextRow(); return row; }
/** * Closes the result and commits the transaction. */ public void close() throws CayenneException { try { result.close(); tx.commit(); } catch (Exception e) { try { tx.rollback(); } catch (Exception rollbackEx) { } throw new CayenneException(e); } finally { if(Transaction.getThreadTransaction() == tx) { Transaction.bindThreadTransaction(null); } } }
protected BatchQueryBuilder createBuilder() throws CayenneException { if (query instanceof InsertBatchQuery) { return new InsertBatchQueryBuilder(getAdapter()); } else if (query instanceof UpdateBatchQuery) { return new UpdateBatchQueryBuilder(getAdapter()); } else if (query instanceof DeleteBatchQuery) { return new DeleteBatchQueryBuilder(getAdapter()); } else { throw new CayenneException("Unsupported batch query: " + query); } }
@Override public byte[] materializeObject(CallableStatement cs, int index, int type) throws Exception { byte[] bytes = null; if (type == Types.BLOB) { if (!isUsingBlobs()) { throw new CayenneException("Binary streams are not supported in stored procedure parameters."); } bytes = readBlob(cs.getBlob(index)); } else { bytes = cs.getBytes(index); // trim BINARY type if (bytes != null && type == Types.BINARY && isTrimmingBytes()) { bytes = trimBytes(bytes); } } return bytes; }
public Object materializeObject(CallableStatement cs, int index, int type) throws Exception { byte[] bytes = null; if (type == Types.BLOB) { if (!isUsingBlobs()) { throw new CayenneException( "Binary streams are not supported in stored procedure parameters."); } bytes = readBlob(cs.getBlob(index)); } else { bytes = cs.getBytes(index); // trim BINARY type if (bytes != null && type == Types.BINARY && isTrimmingBytes()) { bytes = trimBytes(bytes); } } return bytes; }