Example usage for com.google.gwt.gears.client.database Database open

List of usage examples for com.google.gwt.gears.client.database Database open

Introduction

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

Prototype

public native void open(String name) ;

Source Link

Document

Opens a database with the specified name.

Usage

From source file:de.lilawelt.zmachine.client.offline.OfflineMenuImplReal.java

License:Open Source License

public void showGames() {
    if (showing) {
        return;/*from w w  w.ja  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:org.sigmah.client.offline.sigmah.handler.GetOrganizationHandler.java

License:Open Source License

@Override
public CommandResult execute(GetOrganization cmd, User user) throws CommandException {
    OrganizationDTO organizationDTO = null;

    final Factory factory = Factory.getInstance();
    if (factory != null) {

        final Database database = factory.createDatabase();
        database.open(OnlineMode.LOCAL_DATABASE_NAME);
        try {//from w  w  w .jav a 2s . c  o  m
            organizationDTO = OrganizationDAO.selectOrganization(cmd.getId(), database);

        } catch (DatabaseException ex) {
            Log.debug("Error while reading the organization dto " + cmd.getId() + " from the local database.",
                    ex);

        } finally {
            try {
                database.close();
            } catch (DatabaseException ex) {
                Log.debug("Database closing error.", ex);
            }
        }
    }

    return organizationDTO;
}

From source file:org.sigmah.client.offline.sigmah.Query.java

License:Open Source License

public ResultSet execute() throws DatabaseException {
    final Factory factory = Factory.getInstance();
    final Database database = factory.createDatabase();

    database.open(OnlineMode.LOCAL_DATABASE_NAME);

    final ResultSet resultSet = database.execute(statement, arguments);

    database.close();/*from w  w  w.  ja  va  2s  .c  o  m*/

    return resultSet;
}

From source file:org.sigmah.client.offline.sigmah.sync.OrganizationSynchronizer.java

License:Open Source License

@Override
public void synchronizeLocalDatabase() {
    fireOnStart();/*w  w w.  ja v a2s .  c  o  m*/
    fireOnTaskChange(I18N.CONSTANTS.synchronizerOrganizationDownload_0());

    final Factory factory = Factory.getInstance();

    if (factory != null) {

        dispatcher.execute(new GetOrganization(authentication.getOrganizationId()), null,
                new AsyncCallback<OrganizationDTO>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        fireOnFailure(false, I18N.CONSTANTS.synchronizerOrganizationDownload_0_failed()
                                + caught.getMessage());
                    }

                    @Override
                    public void onSuccess(OrganizationDTO result) {
                        final Database database = factory.createDatabase();
                        database.open(OnlineMode.LOCAL_DATABASE_NAME);

                        try {
                            fireOnUpdate(0.1);
                            fireOnTaskChange(I18N.CONSTANTS.synchronizerOrganizationDownload_1());
                            OrganizationDAO.createTablesIfNotExists(database);

                            fireOnUpdate(0.2);
                            fireOnTaskChange(I18N.CONSTANTS.synchronizerOrganizationDownload_2());
                            OrganizationDAO.insertOrReplaceOrganization(result, database);

                            final LocalServer localServer = factory.createLocalServer();
                            final ResourceStore store = localServer.createStore(OnlineMode.LOCAL_DATABASE_NAME);

                            fireOnUpdate(0.8);
                            fireOnTaskChange(I18N.CONSTANTS.synchronizerOrganizationDownload_3());
                            store.capture(new ResourceStoreUrlCaptureHandler() {

                                @Override
                                public void onCapture(ResourceStoreUrlCaptureEvent event) {
                                    fireOnComplete();
                                }
                            }, GWT.getModuleBaseURL() + "image-provider?" + FileUploadUtils.IMAGE_URL + "="
                                    + result.getLogo());

                        } catch (DatabaseException ex) {
                            Log.debug("Error while writing the organization dto to the local database.", ex);
                            fireOnFailure(false, I18N.CONSTANTS.synchronizerOrganizationDownload_0_failed()
                                    + ex.getMessage());

                        } finally {
                            try {
                                database.close();
                            } catch (DatabaseException ex) {
                                Log.debug("Database closing error.", ex);
                                fireOnFailure(false, I18N.CONSTANTS.synchronizerOrganizationDownload_0_failed()
                                        + ex.getMessage());
                            }
                        }
                    }
                });

    } else
        fireOnFailure(false,
                I18N.CONSTANTS.synchronizerOrganizationDownload_0_failed() + "Google Gears isn't available.");
}

From source file:org.sigmah.client.offline.sigmah.sync.OrganizationSynchronizer.java

License:Open Source License

@Override
public void updateDistantDatabase() {
    fireOnStart();//ww w .  j a  va  2s.c  om
    fireOnTaskChange(I18N.CONSTANTS.synchronizerOrganizationUpload_0());

    final Factory factory = Factory.getInstance();

    if (factory != null) {
        final Database database = factory.createDatabase();
        database.open(OnlineMode.LOCAL_DATABASE_NAME);

        try {
            OrganizationDAO.truncateTables(database);

            fireOnComplete();

        } catch (DatabaseException ex) {
            Log.debug("Error while removing the organization dto from the local database.", ex);
            fireOnFailure(false, I18N.CONSTANTS.synchronizerOrganizationUpload_0_failed() + ex.getMessage());

        } finally {
            try {
                database.close();
            } catch (DatabaseException ex) {
                Log.debug("Database closing error.", ex);
                fireOnFailure(false,
                        I18N.CONSTANTS.synchronizerOrganizationUpload_0_failed() + ex.getMessage());
            }
        }

    } else
        fireOnFailure(false,
                I18N.CONSTANTS.synchronizerOrganizationUpload_0_failed() + "Google Gears isn't available.");
}