List of usage examples for com.google.gwt.gears.client.database ResultSet getFieldAsString
public String getFieldAsString(int fieldIndex) throws DatabaseException
fieldIndex
as a String
. 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 www .j a v a 2s.co m 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./*from w w w .java 2 s . com*/ * * @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:de.lilawelt.zmachine.client.offline.OfflineMenuImplReal.java
License:Open Source License
public void showGames() { if (showing) { return;// w w w . j av 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 w w . j a v a 2 s . 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 w ww. j a va2 s . c o m 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; }// ww w. j a v a2 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 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);/* ww w. j a va 2s .c o m*/ orgUnitDTO.setParent(null); orgUnitDTO.setCalendarId(resultSet.getFieldAsInt(9)); orgUnitDTO.setOfficeLocationCountry(null); return orgUnitDTO; }