void truncateTable() throws IOException { if ( table == null ) { return; } Cursor tableRows = Cursor.createCursor( table ); while ( tableRows.moveToNextRow() ) { tableRows.deleteCurrentRow(); } } }
/** * Convenience method for finding a specific row in a table which matches a * given row "pattern". See {@link Cursor#findFirstRow(Column,Object)} for * details on the pattern. * <p> * Note, a {@code null} result value is ambiguous in that it could imply no * match or a matching row with {@code null} for the desired value. If * distinguishing this situation is important, you will need to use a Cursor * directly instead of this convenience method. * * @param table the table to search * @param column column whose value should be returned * @param columnPattern column being matched by the valuePattern * @param valuePattern value from the columnPattern which will match the * desired row * @return the matching row or {@code null} if a match could not be found. */ public static Object findValue(Table table, Column column, Column columnPattern, Object valuePattern) throws IOException { Cursor cursor = createCursor(table); if(cursor.findFirstRow(columnPattern, valuePattern)) { return cursor.getCurrentRowValue(column); } return null; }
/** * Convenience method for finding a specific row in an indexed table which * matches a given row "pattern". See {@link Cursor#findFirstRow(Map)} for * details on the rowPattern. * <p> * Warning, this method <i>always</i> starts searching from the beginning of * the Table (you cannot use it to find successive matches). * * @param index index to assist the search * @param rowPattern pattern to be used to find the row * @return the matching row or {@code null} if a match could not be found. */ public static Row findRow(Index index, Map<String,?> rowPattern) throws IOException { Cursor cursor = createCursor(index); if(cursor.findFirstRow(rowPattern)) { return cursor.getCurrentRow(); } return null; }
@Override protected int findMaxSyntheticId() throws IOException { // find max id < 0 ColumnImpl idCol = _systemCatalog.getColumn(CAT_COL_ID); _systemCatalogCursor.reset(); int curMaxSynthId = Integer.MIN_VALUE; while(_systemCatalogCursor.moveToNextRow()) { int id = (Integer)_systemCatalogCursor.getCurrentRowValue(idCol); if((id > curMaxSynthId) && (id < 0)) { curMaxSynthId = id; } } return curMaxSynthId; } }
public synchronized Object getObject(int row, int column) { if (columns == null || cursor == null) { return null; } try { Column c = columns.get(column); if (curPos == null) { cursor.reset(); cursor.moveNextRows(row + 1); } else { int diff = row + 1 - curPos; if (diff > 0) { cursor.moveNextRows(diff); } else if (diff < 0) { cursor.movePreviousRows(-diff); } } curPos = row + 1; return cursor.getCurrentRowValue(c); } catch (IOException e) { throw new RuntimeException(e); } }
if (!HibernateSupport.isActive()) { Cursor c = t.getDefaultCursor(); while (c.getNextRow() != null) { c.deleteCurrentRow(); Map<String, Object> row; Cursor catc = cat.getDefaultCursor(); while ((row = catc.getNextRow()) != null) { String name = (String) row.get("Name"); if (name != null && name.equalsIgnoreCase(tableName)) { rowtsa.put("ObjectId", id); Cursor cur = tsa.getDefaultCursor(); if (cur.findNextRow(rowtsa)) { cur.deleteCurrentRow(); catc.deleteCurrentRow(); Table srs = db.getSystemTable("MSysRelationships"); Cursor srsc = srs.getDefaultCursor(); while ((row = srsc.getNextRow()) != null) { String szObject = (String) row.get("szObject"); String szReferencedObject = (String) row.get("szReferencedObject"); if ((szObject != null && szObject.equalsIgnoreCase(tableName)) || (szReferencedObject != null && szReferencedObject.equalsIgnoreCase(tableName))) { srsc.deleteCurrentRow();
Table invoices = db_opened.getTable("Invoices"); Table invoices_lignes = db_opened.getTable("InvoicesLignes"); Cursor cursor = CursorBuilder.createCursor(invoices_lignes.getIndex("Code")); for (Row row : invoices) { long start = System.currentTimeMillis( ); System.out.println(String.format("Invoice : '%s'", start)); for (Row crow : cursor.newIterable().addMatchPattern("Code", row.get("Code"))) { System.out.println(String.format("Loop : '%s'", System.currentTimeMillis( ))); } long end = System.currentTimeMillis( ); System.out.println(String.format("End loop : '%s'", System.currentTimeMillis( ))); long diff = end - start; System.out.println(String.format("Loop elapsed time : '%s' ms", diff )); }
public boolean moveToNextRow(Cursor cur, Set<String> columnNames) throws IOException { boolean hasNext = cur.moveToNextRow(); if (hasNext) { this.currentRow = cur.getCurrentRow(columnNames); } return hasNext; }
Cursor cursor = new CursorBuilder(ptab1).toCursor(); Column idCol = ptab1.getColumn("id"); if(cursor.findFirstRow(idCol, 1)) { cursor.deleteCurrentRow(); }
@Override public IFeedbackAction persist() throws SQLException { try { Cursor cur = indexSelector.getCursor(); if (cur.findNextRow(rowPattern)) { if (this.blobColumns != null) { for (Column col : this.blobColumns) { Object val = cur.getCurrentRowValue(col); modifiedRow[tableColumns.indexOf(col)] = val; } } updateComplex(cur); persist(cur); } } catch (IOException e) { throw new UcanaccessSQLException(e); } return new BlobAction(table, modifiedRow); }
Map<String, Object> row; Cursor catc = cat.getDefaultCursor(); while ((row = catc.getNextRow()) != null) { String name = (String) row.get("Name"); if (name != null && name.equalsIgnoreCase(oldTableName)) { Map<String, Object> rowtsa = new HashMap<String, Object>(); rowtsa.put("ObjectId", id); Row r = catc.getCurrentRow(); r.put("Name", tn); catc.updateCurrentRowFromMap(r); Table srs = db.getSystemTable("MSysRelationships"); Cursor srsc = srs.getDefaultCursor(); while ((row = srsc.getNextRow()) != null) { String szObject = (String) row.get("szObject"); String szReferencedObject = (String) row.get("szReferencedObject"); srsc.updateCurrentRowFromMap(row);
public Integer findObjectId(Integer parentId, String name) throws IOException { Cursor cur = findRow(parentId, name); if(cur == null) { return null; } ColumnImpl idCol = _systemCatalog.getColumn(CAT_COL_ID); return (Integer)cur.getCurrentRowValue(idCol); }
public Row getObjectRow(Integer parentId, String name, Collection<String> columns) throws IOException { Cursor cur = findRow(parentId, name); return ((cur != null) ? cur.getCurrentRow(columns) : null); }
@Override public IFeedbackAction persist() throws SQLException { try { Cursor cur = indexSelector.getCursor(); if (cur.findNextRow(rowPattern)) { cur.deleteCurrentRow(); } } catch (IOException e) { throw new UcanaccessSQLException(e); } return null; }
Table table = DatabaseBuilder.open(new File("my.mdb")).getTable("MyTable"); Cursor cursor = CursorBuilder.createCursor(table); while (cursor.findNextRow(Collections.singletonMap("a", "foo"))) { Row row = cursor.getCurrentRow(); System.out.println(String.format( "a='%s', SomeFieldName='%s'.", row.get("a"), row.get("SomeFieldName"))); }
@Override protected Cursor findRow(Integer parentId, String name) throws IOException { Map<String,Object> rowPat = new HashMap<String,Object>(); rowPat.put(CAT_COL_PARENT_ID, parentId); rowPat.put(CAT_COL_NAME, name); return (_systemCatalogCursor.findFirstRow(rowPat) ? _systemCatalogCursor : null); }
Pattern.quote("" + quote) + ")|(?:[\n\r])"); List<? extends Column> origCols = cursor.getTable().getColumns(); List<Column> columns = new ArrayList<Column>(origCols); columns = filter.filterColumns(columns); while ((row = cursor.getNextRow(columnNames)) != null) {
@Override public CompositeFeedbackAction persistCurrentRow(Cursor cur) throws IOException { cur.deleteCurrentRow(); return null; }
@Override public boolean currentRowMatches(Cursor cur, Map<String, Object> currentRow) throws IOException { Map<String, Object> rowPattern = getRowPattern(); if (rowPattern.size() != currentRow.size()) { return false; } for (Map.Entry<String, Object> e : currentRow.entrySet()) { String columnName = e.getKey(); if (!cur.getColumnMatcher().matches(cur.getTable(), columnName, rowPattern.get(columnName), e.getValue())) { return false; } } return true; }
public IterableBuilder setMatchPattern(String columnNamePattern, Object valuePattern) { return setMatchPattern(_cursor.getTable().getColumn(columnNamePattern), valuePattern); }