Esempio n. 1
0
  /**
   * Reads active registry entries assigned to this server.
   *
   * @return the list of the active registry entries associated to this server
   * @throws com.funambol.pushlistener.service.registry.dao.DataAccessException if an error occurs
   */
  public List<RegistryEntry> getActiveEntries() throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    List<RegistryEntry> entries = new ArrayList<RegistryEntry>();

    try {
      if (log.isTraceEnabled()) {
        log.trace("Executing '" + queryDesc.getReadActiveEntriesQuery() + "'");
      }

      con = getConnection();
      con.setReadOnly(true);

      ps = con.prepareStatement(queryDesc.getReadActiveEntriesQuery());

      ps.setString(1, "Y");
      rs = ps.executeQuery();

      while (rs.next()) {
        entries.add(resultSetToRegistryEntry(rs));
      }

    } catch (Exception e) {

      throw new DataAccessException(e);

    } finally {
      DBTools.close(con, ps, rs);
    }

    return entries;
  }
Esempio n. 2
0
 public final void setWriteEnabled(final boolean enabled) {
   try {
     m_conn.setReadOnly(!enabled);
   } catch (SQLException e) {
     throw new IllegalStateException(e);
   }
 }
Esempio n. 3
0
  /**
   * Returns the registry entry with the given id
   *
   * @return the read entry
   * @param id the id of the pim registry entry
   * @throws DataAccessException if an error occurs
   */
  public RegistryEntry getEntryById(long id) throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    RegistryEntry entry = null;

    try {

      con = getConnection();
      con.setReadOnly(true);

      ps = con.prepareStatement(queryDesc.getReadEntryQuery());
      ps.setLong(1, id);
      rs = ps.executeQuery();

      while (rs.next()) {
        entry = resultSetToRegistryEntry(rs);
      }

    } catch (Exception e) {
      throw new DataAccessException("Error reading entry with id: " + id, e);
    } finally {
      DBTools.close(con, ps, rs);
    }

    return entry;
  }
Esempio n. 4
0
  /**
   * Reads registry entries assigned to this server. If <code>lastUpdate</code> is different than 0,
   * just the changed entries with last_update bigger than the given one and the given status are
   * returned.
   *
   * @param lastUpdate the lastUpdate. 0 if all entries must be returned
   * @param status the wanted status
   * @throws com.funambol.pushlistener.service.registry.dao.DataAccessException if an error occurs
   * @return the read entries
   */
  public List<RegistryEntry> getEntries(long lastUpdate, String status) throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    List<RegistryEntry> entries = new ArrayList<RegistryEntry>();

    try {

      con = getConnection();
      con.setReadOnly(true);

      if (lastUpdate != 0) {
        //
        // Read only changed registry entries
        //
        if (log.isTraceEnabled()) {
          log.trace("Executing '" + queryDesc.getReadChangedEntriesQuery() + "'");
        }

        ps = con.prepareStatement(queryDesc.getReadChangedEntriesQuery());
        ps.setLong(1, lastUpdate);
        ps.setString(2, status);

      } else {
        //
        // Read all registry entries
        //
        if (log.isTraceEnabled()) {
          log.trace("Executing '" + queryDesc.getReadActiveEntriesQuery() + "'");
        }

        ps = con.prepareStatement(queryDesc.getReadActiveEntriesQuery());
        ps.setString(1, "Y");
      }

      rs = ps.executeQuery();

      while (rs.next()) {
        entries.add(resultSetToRegistryEntry(rs));
      }

    } catch (Exception e) {

      throw new DataAccessException(e);

    } finally {
      DBTools.close(con, ps, rs);
    }

    return entries;
  }
Esempio n. 5
0
  public void open() {
    try {
      m_conn = DriverManager.getConnection(getJdbcUrl());
    } catch (SQLException e) {
      throw new LentilConnectionException(e);
    }

    try {
      m_conn.setReadOnly(true);
      m_conn.setAutoCommit(false);
    } catch (SQLException e) {
      throw new IllegalStateException(e);
    }
  }
Esempio n. 6
0
  private void reset(boolean known_resolved_txn) throws SQLException {
    ensureOkay();
    C3P0ImplUtils.resetTxnState(
        physicalConnection,
        forceIgnoreUnresolvedTransactions,
        autoCommitOnClose,
        known_resolved_txn);
    if (isolation_lvl_nondefault) {
      physicalConnection.setTransactionIsolation(dflt_txn_isolation);
      isolation_lvl_nondefault = false;
    }
    if (catalog_nondefault) {
      physicalConnection.setCatalog(dflt_catalog);
      catalog_nondefault = false;
    }
    if (holdability_nondefault) // we don't test if holdability is supported, 'cuz it can never go
                                // nondefault if it's not.
    {
      physicalConnection.setHoldability(dflt_holdability);
      holdability_nondefault = false;
    }

    try {
      physicalConnection.setReadOnly(false);
    } catch (Throwable t) {
      if (logger.isLoggable(MLevel.FINE))
        logger.log(
            MLevel.FINE,
            "A Throwable occurred while trying to reset the readOnly property of our Connection to false!",
            t);
    }

    try {
      if (supports_setTypeMap) physicalConnection.setTypeMap(Collections.EMPTY_MAP);
    } catch (Throwable t) {
      if (logger.isLoggable(MLevel.FINE))
        logger.log(
            MLevel.FINE,
            "A Throwable occurred while trying to reset the typeMap property of our Connection to Collections.EMPTY_MAP!",
            t);
    }
  }
Esempio n. 7
0
 public void setReadOnly(boolean readOnly) throws SQLException {
   con.setReadOnly(readOnly);
 }
Esempio n. 8
0
 @Setter
 public void setReadOnly(boolean value) throws SQLException {
   connection.setReadOnly(value);
 }
Esempio n. 9
0
 public void setReadOnly(boolean b) throws SQLException {
   conn.setReadOnly(b);
 }