Example usage for com.google.gwt.gears.client.database ResultSet next

List of usage examples for com.google.gwt.gears.client.database ResultSet next

Introduction

In this page you can find the example usage for com.google.gwt.gears.client.database ResultSet next.

Prototype

public native void next() ;

Source Link

Document

Advances to the next row of the results.

Usage

From source file:com.google.gwt.gears.sample.database.client.DatabaseDemo.java

License:Apache License

/**
 * Fill the labels with the phrases from the database.
 *///w w  w. j a  v  a 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./*from   w w  w .  j a  v a2s.  co 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:de.lilawelt.zmachine.client.offline.OfflineMenuImplReal.java

License:Open Source License

public void showGames() {
    if (showing) {
        return;//from  ww  w.  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 getSavedGames(String GameUid, AsyncCallback<List<String>> callback) {
    List<String> SavedGames = new LinkedList<String>();

    if (!initialized) {
        try {/*from   w ww  .  j  av a  2s . c om*/
            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.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);/*  w w w .j a  v a  2  s .c o m*/
        resultSet.next();
    }

    return children;
}