Package org.conserve.connection

Examples of org.conserve.connection.ConnectionWrapper


  public void testBasicFunctionality() throws Exception
  {

    PersistenceManager persist = new PersistenceManager(driver, database,
        login, password);
    ConnectionWrapper cw = persist.getConnectionWrapper();
   
    PreparedStatement stmt = cw.prepareStatement("SELECT COUNT(*) FROM C__ARRAY");
    ResultSet rs = stmt.executeQuery();
    if(rs.next())
    {
      System.out.println("Found " + rs.getInt(1) + " objects.");
    }
    else
    {
      System.out.println("No result.");
    }
    stmt.close();
    cw.commitAndDiscard();
    persist.close();
  }
View Full Code Here


   * @param where
   * @return the number of deleted objects.
   */
  <T> int deleteObjects(Class<T> clazz, Clause where) throws SQLException
  {
    ConnectionWrapper cw = connectionPool.getConnectionWrapper();
    int res = 0;
    try
    {
      res = deleteObjects(cw, clazz, where);
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      cw.rollbackAndDiscard();
      throw new SQLException(e);
    }
    return res;
  }
View Full Code Here

   *
   * @throws SQLException
   */
  void saveObject(Object object) throws SQLException
  {
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      saveObject(cw, object, true, null);
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      // cancel the operation
      cw.rollbackAndDiscard();
      // re-throw the original exception
      throw new SQLException(e);
    }
  }
View Full Code Here

   */
  public <T> List<T> getObjects(Class<T> clazz, Clause... clause)
      throws SQLException
  {
    List<T> res = null;
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      res = getObjects(cw, clazz, clause);
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      cw.rollbackAndDiscard();
      throw new SQLException(e);
    }
    return res;
  }
View Full Code Here

   * @throws SQLException
   */
  <T> long getCount(Class<T> clazz, Clause clause) throws SQLException
  {
    long res = 0;
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      res = getCount(cw, clazz, clause);
    }
    catch (Exception e)
    {
      cw.rollback();
      throw new SQLException(e);
    }
    cw.discard();
    return res;
  }
View Full Code Here

  public List<Class<?>> getClasses() throws SQLException
  {
    ArrayList<Class<?>> res = new ArrayList<Class<?>>();
    // get all c__IS_A entries
    String selectStmt = "SELECT * from " + Defaults.IS_A_TABLENAME;
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      PreparedStatement ps = cw.prepareStatement(selectStmt);
      ResultSet rs = ps.executeQuery();
      while (rs.next())
      {
        String superClassName = rs.getString("SUPERCLASS");
        String subClassName = rs.getString("SUBCLASS");
        try
        {
          Class<?> superClass = ObjectTools
              .lookUpClass(superClassName);
          if (superClass != null && !res.contains(superClass))
          {
            res.add(superClass);
          }
        }
        catch (ClassNotFoundException e)
        {
          LOGGER.log(Level.WARNING, "ClassNotFoundException: ", e);
        }
        try
        {
          Class<?> subClass = ObjectTools.lookUpClass(subClassName);
          if (subClass != null && !res.contains(subClass))
          {
            res.add(subClass);
          }
        }
        catch (ClassNotFoundException e)
        {
          LOGGER.log(Level.WARNING, "ClassNotFoundException: ", e);
        }

      }
      ps.close();
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      cw.rollbackAndDiscard();
      throw new SQLException(e);
    }

    return res;
  }
View Full Code Here

  void close()
  {
    if (adapter.getShutdownCommand() != null)
    {
      ConnectionWrapper cw = null;
      try
      {
        cw = getConnectionWrapper();
        PreparedStatement ps = cw.prepareStatement(adapter
            .getShutdownCommand());
        ps.execute();
        ps.close();
        cw.commitAndDiscard();
      }
      catch (Exception e)
      {
        LOGGER.log(Level.WARNING, "Exception: ", e);
        try
        {
          if (cw != null)
          {
            cw.rollbackAndDiscard();
          }
        }
        catch (SQLException e1)
        {
          LOGGER.log(Level.WARNING, "SQLException: ", e1);
View Full Code Here

   *
   */
  public <T> T refresh(T obj) throws IllegalArgumentException, SQLException
  {
    T res = null;
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      res = refresh(cw, obj);
      cw.commitAndDiscard();
    }
    catch (IllegalArgumentException iae)
    {
      // rethrow
      throw iae;
    }
    catch (Exception e)
    {
      // cancel the operation
      cw.rollbackAndDiscard();
      // re-throw the original exception
      throw new SQLException(e);
    }
    return res;
  }
View Full Code Here

   *            the class of object to drop the table for.
   * @throws SQLException
   */
  public void dropTable(Class<?> c) throws SQLException
  {
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      dropTable(cw, c);
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      // cancel the operation
      cw.rollbackAndDiscard();
      // re-throw the original exception
      throw new SQLException(e);
    }
  }
View Full Code Here

   * @param klass
   * @throws SQLException
   */
  public void updateSchema(Class<?> klass) throws SQLException
  {
    ConnectionWrapper cw = getConnectionWrapper();
    try
    {
      persist.getTableManager().updateTableForClass(klass, cw);
      cw.commitAndDiscard();
    }
    catch (Exception e)
    {
      // cancel the operation
      cw.rollbackAndDiscard();
      // re-throw the original exception
      throw new SQLException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.conserve.connection.ConnectionWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.