List of usage examples for com.google.gwt.gears.client.database ResultSet isValidRow
public native boolean isValidRow() ;
true
if this ResultSet
cursor is currently pointing at a valid row. From source file:com.google.gwt.gears.sample.database.client.DatabaseDemo.java
License:Apache License
/** * Fill the labels with the phrases from the database. *///from w ww . j a va 2 s. c om private void displayRecentPhrases() { try { ResultSet rs = db.execute("SELECT * FROM Phrases ORDER BY Id DESC"); int i; for (i = 1; rs.isValidRow(); ++i, rs.next()) { if (i <= NUM_SAVED_ROWS) { dataTable.setText(i, 0, rs.getFieldAsString(0)); dataTable.setText(i, 1, rs.getFieldAsString(1)); dataTable.setText(i, 2, new Date(rs.getFieldAsLong(2)).toString()); } else { db.execute("DELETE FROM Phrases WHERE Id = ?", new String[] { rs.getFieldAsString(0) }); } } // If a phrase has been removed, clear the label. for (; i <= NUM_SAVED_ROWS; i++) { for (int j = 0; j < NUM_DATA_TABLE_COLUMNS; j++) { dataTable.clearCell(i, j); } } rs.close(); } catch (DatabaseException e) { Window.alert(e.toString()); } }
From source file:com.google.gwt.gears.sample.gwtnote.client.local.GearsHelper.java
License:Apache License
/** * Unmarshals all rows in the database into an array of {@link Note} * instances./* ww w . ja v a 2 s . c o m*/ * * @return a list of all notes in the DB */ public Note[] getNotes() { if (db == null) { return null; } ResultSet rs = null; ArrayList<Note> al = new ArrayList<Note>(); try { rs = db.execute(DB_FETCH_TEXT); while (rs.isValidRow()) { Note nd = new Note(rs.getFieldAsString(0), rs.getFieldAsString(1), rs.getFieldAsString(2)); al.add(nd); rs.next(); } } catch (DatabaseException e) { return null; } Note[] notes = new Note[al.size()]; for (int i = 0; i < al.size(); ++i) { notes[i] = al.get(i); } return notes; }
From source file:com.google.gwt.gears.sample.gwtnote.client.local.GearsHelper.java
License:Apache License
/** * Marshals the indicated note to the database. This amounts to updating the * row with the data as provided.//from w w w .java2s .com * * If <code>dirty</code> is true, the row will be marked as dirty. Note that * even if the argument is NOT true, the row may still be dirty -- that is, * <code>dirty</code> specifies whether the current operation makes the row * dirty, not the absolute state of the row. * * @param n the note to update */ public void updateNote(Note n) { if (db == null) { return; } String name = n.getName(); String data = n.getText(); String vers = n.getVersion(); String[] args = null; ResultSet rs = null; try { // test whether the row exists or not -- controls behavior below args = new String[] { name }; rs = db.execute(DB_EXISTS, args); } catch (DatabaseException e1) { return; } // if row exists update it; if not, create a new one if (rs.isValidRow()) { args = new String[] { vers, data, name }; try { db.execute(DB_UPDATE, args); } catch (DatabaseException e) { return; } } else { args = new String[] { name, vers, data }; try { db.execute(DB_INSERT, args); } catch (DatabaseException e) { return; } } }
From source file:de.lilawelt.zmachine.client.offline.OfflineMenuImplReal.java
License:Open Source License
public void showGames() { if (showing) { return;/*from www. j a v a 2 s. c o m*/ } showing = true; p.remove(statusLabel); Label title = new Label("Available games:"); p.add(title, DockPanel.NORTH); HTMLTable h = new FlexTable(); h.setText(0, 0, "Game Name:"); p.add(h, DockPanel.NORTH); try { Database db = f.createDatabase(); db.open("textadventure-saves"); ResultSet rs = db.execute("Select gamename, gameuid from offlinegames;"); for (int i = 0; rs.isValidRow(); ++i, rs.next()) { final String name = rs.getFieldAsString(0); final String uid = rs.getFieldAsString(1); Hyperlink link = new Hyperlink(); link.setText(rs.getFieldAsString(0)); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Machine.get().loadStory("/games/" + name + ".sto", uid); } }); h.setWidget(i + 1, 0, link); } } catch (Exception e) { Window.alert("Error: " + e.getMessage()); } }
From source file:de.lilawelt.zmachine.client.storage.GearsAdapterReal.java
License:Open Source License
public void restore(String SaveName, String GameUid, AsyncCallback<String> callback) { Log.debug("Got restore with saveName: " + SaveName + " and GameUid: " + GameUid); try {/*from w ww.j a v a2s . com*/ ResultSet rs = db.execute("Select savedata from saves where savename = ? AND gameuid = ?", SaveName, GameUid); if (!rs.isValidRow()) { Window.alert("no such save found"); callback.onFailure(new Throwable("no such save found")); } else { callback.onSuccess(rs.getFieldAsString(0)); } } catch (DatabaseException e) { callback.onFailure(new Throwable(e.toString())); } }
From source file:de.lilawelt.zmachine.client.storage.GearsAdapterReal.java
License:Open Source License
public void getSavedGames(String GameUid, AsyncCallback<List<String>> callback) { List<String> SavedGames = new LinkedList<String>(); if (!initialized) { try {//from ww w . j a v a2s. com Initialize(); } catch (StorageException e) { callback.onFailure(e); return; } } try { ResultSet rs = db.execute("Select savename from saves where gameuid = ?", GameUid); for (int i = 0; rs.isValidRow(); ++i, rs.next()) { SavedGames.add(rs.getFieldAsString(0)); Log.debug("Added saved game: " + rs.getFieldAsString(0)); } Log.debug("Firing saved-games callback"); callback.onSuccess(SavedGames); } catch (DatabaseException e) { callback.onFailure(new Throwable(e.toString())); } }
From source file:org.sigmah.client.offline.DatabaseStateProvider.java
License:Open Source License
@Override protected String getValue(String name) { if (db == null) { return null; }/* w ww .j a va 2 s. co m*/ try { ResultSet rs = db.execute("select value from state where key = ?", name); if (rs.isValidRow()) { return rs.getFieldAsString(0); } else { return null; } } catch (DatabaseException e) { GWT.log("DatabaseStateProvider: getValue failed", e); return null; } }
From source file:org.sigmah.client.offline.sigmah.dao.OrganizationDAO.java
License:Open Source License
private static Set<OrgUnitDTO> findSubOrgUnits(int parentOrgUnitId, Database database) throws DatabaseException { final ResultSet resultSet = database.execute("SELECT * FROM orgUnit " + "WHERE parent = ?", Integer.toString(parentOrgUnitId)); final LinkedHashSet<OrgUnitDTO> children = new LinkedHashSet<OrgUnitDTO>(); while (resultSet.isValidRow()) { final OrgUnitDTO orgUnitDTO = asOrgUnitDTO(resultSet); Log.debug("OrgUnit, parent : " + parentOrgUnitId + ", child : " + orgUnitDTO.getId()); if (orgUnitDTO != null) orgUnitDTO.setChildren(findSubOrgUnits(orgUnitDTO.getId(), database)); children.add(orgUnitDTO);//from w ww .j a v a 2 s . co m resultSet.next(); } return children; }
From source file:org.sigmah.client.offline.sigmah.dao.OrganizationDAO.java
License:Open Source License
private static OrganizationDTO asOrganizationDTO(ResultSet resultSet) throws DatabaseException { if (resultSet == null || !resultSet.isValidRow()) return null; final OrganizationDTO organizationDTO = new OrganizationDTO(); organizationDTO.setId(resultSet.getFieldAsInt(0)); organizationDTO.setName(resultSet.getFieldAsString(1)); organizationDTO.setLogo(resultSet.getFieldAsString(2)); // Temporary value final OrgUnitDTO orgUnitDTO = new OrgUnitDTO(); orgUnitDTO.setId(resultSet.getFieldAsInt(3)); organizationDTO.setRoot(orgUnitDTO); return organizationDTO; }
From source file:org.sigmah.client.offline.sigmah.dao.OrganizationDAO.java
License:Open Source License
private static OrgUnitDTO asOrgUnitDTO(ResultSet resultSet) throws DatabaseException { if (resultSet == null || !resultSet.isValidRow()) return null; final OrgUnitDTO orgUnitDTO = new OrgUnitDTO(); orgUnitDTO.setId(resultSet.getFieldAsInt(0)); orgUnitDTO.setName(resultSet.getFieldAsString(1)); orgUnitDTO.setFullName(resultSet.getFieldAsString(2)); orgUnitDTO.setOrgUnitModel(getDummyOrgUnitModel(resultSet.getFieldAsInt(3))); orgUnitDTO.setOrganization(null);// w w w . j a va2 s . com orgUnitDTO.setParent(null); orgUnitDTO.setCalendarId(resultSet.getFieldAsInt(9)); orgUnitDTO.setOfficeLocationCountry(null); return orgUnitDTO; }