Package com.arjuna.ats.arjuna.exceptions

Examples of com.arjuna.ats.arjuna.exceptions.ObjectStoreException


                }
                catch (Throwable e)
                {
                            if (count == MAX_RETRIES-1)
                            {
                                throw new ObjectStoreException(e.toString());
                            }
                            try
                            {
                                reconnect(pool) ;
                            }
                            catch (final Throwable th)
                            {
                                throw new ObjectStoreException(e.toString());
                            }
                }
                    }
                }
        finally
        {
          try
          {
            if (rs != null)
              rs.close();
          }
          // Ignore
          catch (Exception re) {}
          freePool(pool);
        }
      }
            return newImage;
    }
    else
      throw new ObjectStoreException("oracle.read_state - object with uid "+objUid+" has no TypeName");
  }
View Full Code Here


  public boolean write_state (Uid objUid, String tName, OutputObjectState state, int s, String tableName) throws ObjectStoreException
  {
    int imageSize = (int) state.length();

    if (imageSize > _maxStateSize)
      throw new ObjectStoreException("Object state is too large - maximum size allowed: " + _maxStateSize);

    byte[] b = state.buffer();

    if (imageSize > 0 && storeValid())
    {
      int pool = getPool();
      ResultSet rs = null;
      ResultSet rs3 = null;

            try
            {
                for(int count = 0 ; count < MAX_RETRIES ; count++)
                {
              try
              {
                PreparedStatement pstmt = _preparedStatements[pool][READ_WRITE_SHORTCUT];
       
                _theConnection[pool].setAutoCommit(false);
       
                if (pstmt == null)
                {
                  pstmt = _theConnection[pool].prepareStatement("SELECT ObjectState FROM "+tableName+" WHERE UidString = ? AND StateType = ? AND TypeName = ? FOR UPDATE", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
                  _preparedStatements[pool][READ_WRITE_SHORTCUT] = pstmt;
                }
                pstmt.setString(1, objUid.stringForm());
                pstmt.setInt(2, s);
                pstmt.setString(3, tName);
       
                rs = pstmt.executeQuery();
       
                if( rs.next() ) {
       
                  BLOB myBlob = (BLOB)rs.getBlob(1);
                  myBlob.putBytes(1, b);
       
                } else {
                  // not in database, do insert:
                  PreparedStatement pstmt2 = _preparedStatements[pool][WRITE_STATE_NEW];
       
                  if (pstmt2 == null)
                  {
                    pstmt2 = _theConnection[pool].prepareStatement("INSERT INTO "+tableName+" (StateType,TypeName,UidString,ObjectState) VALUES (?,?,?,empty_blob())");
       
                    _preparedStatements[pool][WRITE_STATE_NEW] = pstmt2;
                  }
       
                  pstmt2.setInt(1, s);
                  pstmt2.setString(2, tName);
                  pstmt2.setString(3, objUid.stringForm());
       
                  pstmt2.executeUpdate();
                  _theConnection[pool].commit();
       
                  PreparedStatement pstmt3 = _preparedStatements[pool][SELECT_FOR_WRITE_STATE];
                  if(pstmt3 == null) {
                    pstmt3 = _theConnection[pool].prepareStatement("SELECT ObjectState FROM "+tableName+" WHERE UidString = ? AND TypeName = ? AND StateType = ? FOR UPDATE");
                    _preparedStatements[pool][SELECT_FOR_WRITE_STATE] = pstmt3;
                  }
       
                  pstmt3.setString(1, objUid.stringForm());
                  pstmt3.setString(2, tName);
                  pstmt3.setInt(3, s);
       
                  rs3 = pstmt3.executeQuery();
                  rs3.next();
                  BLOB myBlob = (BLOB)rs3.getBlob(1);
                  myBlob.putBytes(1, b);
                }
       
                _theConnection[pool].commit();
                        return true ;
       
              }
              catch(Throwable e)
              {
                        if (count == MAX_RETRIES-1)
                        {
                            if (tsLogger.arjLoggerI18N.isWarnEnabled()) {
                                tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.objectstore.jdbc.oracle_2", new Object[] {e});
                            }
                            return false ;
                        }
                        try
                        {
                            reconnect(pool) ;
                        }
                        catch (final Throwable th)
                        {
                            throw new ObjectStoreException(e.toString());
                        }
              }
                }
            }
      finally
View Full Code Here

      {
        TransactionData theLogEntry = getLogName(objUid, tName, buffSize);    // always adds entry to log
        LogInstance theLog = theLogEntry.container;
     
        if (theLog == null)
          throw new ObjectStoreException();

        fname = genPathName(theLog.getName(), tName, ft);
        fd = openAndLock(fname, FileLock.F_WRLCK, true);

        if (fd == null)
        {
          if (tsLogger.arjLoggerI18N.isWarnEnabled())
          {
            tsLogger.arjLoggerI18N.warn(
                "com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore_18",
                new Object[]
                           { fname });
          }

          return false;
        }

        boolean setLength = !fd.exists();

        try
        {
          ofile = new RandomAccessFile(fd, FILE_MODE);
         
          if (setLength)
          {
            ofile.setLength(_maxFileSize);
          }
          else
          {         
            // may have to resize file if we keep updating this transaction info

            if (theLog.remaining() < buffSize)
            {
              long size = ofile.length() + buffSize - theLog.remaining();

              ofile.setLength(size);

              theLog.resize(size);
            }
          }

          java.nio.ByteBuffer buff = java.nio.ByteBuffer.allocate(buffSize);

          buff.put(_redzone);
          buff.putInt(uidString.length);
          buff.put(uidString);
          buff.putInt(imageSize);
          buff.put(state.buffer());

          synchronized (_lock)
          {
            ofile.seek(theLogEntry.offset);

            ofile.write(buff.array());
          }
        }
        catch (SyncFailedException e)
        {
          unlockAndClose(fd, ofile);

          throw new ObjectStoreException(
              "ShadowingStore::write_state() - write failed to sync for "
              + fname);
        }
        catch (FileNotFoundException e)
        {
          unlockAndClose(fd, ofile);

          e.printStackTrace();

          throw new ObjectStoreException(
              "ShadowingStore::write_state() - write failed to locate file "
              + fname + ": " + e);
        }
        catch (IOException e)
        {
          unlockAndClose(fd, ofile);

          e.printStackTrace();

          throw new ObjectStoreException(
              "ShadowingStore::write_state() - write failed for "
              + fname + ": " + e);
        }
        finally
        {
          try
          {
            if (lock != null)
              lock.release();
          }
          catch (IOException ex)
          {
            ex.printStackTrace();
          }
        }
      }
     
      if (!unlockAndClose(fd, ofile))
      {
        if (tsLogger.arjLoggerI18N.isWarnEnabled())
        {
          tsLogger.arjLoggerI18N
              .warn(
                  "com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore_19",
                  new Object[]
                  { fname });
        }
      }

      super.addToCache(fname);

      return true;
    }
    else
      throw new ObjectStoreException(
          "ShadowStore::write_state - "
              + tsLogger.log_mesg
                  .getString("com.arjuna.ats.internal.arjuna.objectstore.notypenameuid")
              + objUid);
  }
View Full Code Here

     */
   
    TransactionData td = getLogName(u, tn, -1);
   
    if (td == null)
      throw new ObjectStoreException();
   
    ArrayList<InputObjectState> states = scanLog(td.container.getName(), tn);
   
    if ((states == null) || (states.size() == 0))
      return null;
View Full Code Here

        OutputObjectState removalState = new OutputObjectState(u, tn);

        removalState.packBytes(_removedState);

        if (!write_state(u, tn, removalState, s))
          throw new ObjectStoreException();
      }
      else
        _purger.addRemovedState(u, tn, s);
    }
    catch (IOException ex)
    {
      throw new ObjectStoreException(ex.toString());
    }
    finally
    {
      removeFromLog(u);
    }
View Full Code Here

      OutputObjectState removalState = new OutputObjectState(u, tn);

      removalState.packBytes(_removedState);
     
      if (!write_state(u, tn, removalState, s))
        throw new ObjectStoreException();
    }
    catch (IOException ex)
    {
      throw new ObjectStoreException(ex.toString());
    }

    return true;
  }
View Full Code Here

              fd2.delete();

              unlockAndClose(fd2, oFile);
             
              throw new ObjectStoreException(ex.toString());
            }
          }

          try
          {
            if (force)
            {
              oFile.setLength(size);
           
              log.freeze();
            }

            fd2.renameTo(fd);
          }
          catch (final Exception ex)
          {
            ex.printStackTrace();
           
            // TODO log

            throw new ObjectStoreException(ex.toString());
          }
          finally
          {
            unlockAndClose(fd2, oFile);
          }
        }
        else
        {
          /*
           * Delete the log if there are no states in it. We could
           * keep the file around and reuse it, but the advantage of
           * this is small compared to having to cope with reusing old
           * log instances.
           */

          fd.delete();
         
          /*
           * Remember to remove the information from the memory cache.
           */
         
          delete = true;
        }
      }
      catch (final ObjectStoreException ex)
      {
        ex.printStackTrace();

        throw ex;
      }
      catch (final Exception ex)
      {
        ex.printStackTrace();

        throw new ObjectStoreException(ex.toString());
      }
    }
   
    return delete;
  }
View Full Code Here

              }
              catch (final Exception ex)
              {
                ex.printStackTrace();

                throw new ObjectStoreException(ex.toString());
              }
            }
          }

          unlockAndClose(fd, iFile);
          iFile = null;

          /*
           * At this stage we now have a list of ObjectState entries.
           * Now we need to go through and prune the list. This is
           * complicated by the fact that there can be 1.. entries for
           * a specific transaction since we continually update the
           * log as we drive recovery. If an entry hasn't been deleted
           * then we will keep the latest one we find.
           */

          /*
           * First search for those entries that have been deleted.
           */

          ArrayList<InputObjectState> deletedLogs = new ArrayList<InputObjectState>();

          for (int i = 0; i < objectStates.size(); i++)
          {
            InputObjectState curr = objectStates.get(i);

            try
            {
              if (Arrays.equals(curr.unpackBytes(), _removedState))
              {
                deletedLogs.add(curr);
              }
              else
                curr.reread()// don't forget to reset the read pointer!
            }
            catch (final Exception ex)
            {
              // if not a delete record then the first entry won't
              // be an the defined byte array.
            }
          }

          if (deletedLogs.size() > 0)
          {
            /*
             * make sure we remove them from the first list to save time.
             */
           
            objectStates.removeAll(deletedLogs);

            deleteEntries(objectStates, deletedLogs);

            /*
             * At this stage we should only have entries that refer
             * to in-flight transactions. Go through the list and
             * remove N-1 references for each transaction id.
             */

            pruneEntries(objectStates);

            /*
             * Now return the list of committed entries.
             */
           
            return objectStates;
          }
          else
            return objectStates;
        }
        finally
        {
          if (iFile != null)
            unlockAndClose(fd, iFile);
        }
      }
      catch (final ObjectStoreException ex)
      {
        ex.printStackTrace();

        throw ex;
      }
      catch (final Exception ex)
      {
        ex.printStackTrace();

        throw new ObjectStoreException(ex.toString());
      }
    }
  }
View Full Code Here

   */
  protected void setupStore(String jdbcAccessClassName, String tableName)
      throws Exception
  {
    if (jdbcAccessClassName == null || jdbcAccessClassName.length() == 0)
      throw new ObjectStoreException();

    final JDBCAccess jdbcAccess;
    synchronized (_theAccesses)
    {
      final Object jdbcAccessObject = _theAccesses
          .get(jdbcAccessClassName);
      if (jdbcAccessObject != null)
      {
        jdbcAccess = (JDBCAccess) jdbcAccessObject;
      }
      else
      {
        try
        {
          final Class jdbcAccessClass = Thread.currentThread()
              .getContextClassLoader().loadClass(
                  jdbcAccessClassName);
          jdbcAccess = (JDBCAccess) jdbcAccessClass.newInstance();
        }
        catch (final Exception ex)
        {
          if (tsLogger.arjLoggerI18N.isFatalEnabled())
          {
            tsLogger.arjLoggerI18N
                .fatal(
                    "com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
                    new Object[]
                    { ex, jdbcAccessClassName });
          }
          throw ex;
        }
        _theAccesses.put(jdbcAccessClassName, jdbcAccess);
      }
    }
    setJDBCAccess(jdbcAccess);

    final String impleTableName;
    if ((tableName != null) && (tableName.length() > 0))
    {
      impleTableName = tableName;
    }
    else
    {
      final String jdbcAccessTableName = jdbcAccess.tableName();
      if ((jdbcAccessTableName != null)
          && (jdbcAccessTableName.length() > 0))
      {
        impleTableName = jdbcAccessTableName;
      }
      else
      {
        impleTableName = getDefaultTableName();
      }
    }

    setTableName(impleTableName);

    final String impleKey = jdbcAccessClassName + ":" + impleTableName;

    synchronized (_theImples)
    {
      final Object currentImple = _theImples.get(impleKey);
      if (currentImple != null)
      {
        _theImple = (JDBCImple) currentImple;
      }
      else
      {
        try
        {
          /*
           * This had better not be an Arjuna jdbc connection!
           */
          final Connection connection;

          try
          {
            connection = jdbcAccess.getConnection();
          }
          catch (final SQLException sqle)
          {
            if (tsLogger.arjLoggerI18N.isFatalEnabled())
            {
              tsLogger.arjLoggerI18N
                  .fatal(
                      "com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
                      new Object[]
                      { sqle, "getConnection()" });
            }
            throw sqle;
          }

          if (connection == null)
          {
            if (tsLogger.arjLoggerI18N.isFatalEnabled())
            {
              tsLogger.arjLoggerI18N
                  .fatal(
                      "com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_1",
                      new Object[]
                      { getJDBCAccess(), getTableName() });
            }
            throw new SQLException("getConnection returned null");
          }
          boolean success = false;
          try
          {
            connection.setAutoCommit(true);
            final JDBCImple jdbcImple;
            try
            {
              final Class jdbcImpleClass = getJDBCClass(connection);
              jdbcImple = (JDBCImple) jdbcImpleClass
                  .newInstance();
              jdbcImple.setShareStatus(shareStatus);
            }
            catch (final Exception ex)
            {
              if (tsLogger.arjLoggerI18N.isFatalEnabled())
              {
                tsLogger.arjLoggerI18N
                    .fatal(
                        "com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
                        new Object[]
                        { ex, getJDBCAccess() });
              }
              throw ex;
            }

            if (!jdbcImple.initialise(connection, jdbcAccess,
                impleTableName))
            {
              if (tsLogger.arjLoggerI18N.isWarnEnabled())
                tsLogger.arjLoggerI18N
                    .warn("com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_3");
              throw new ObjectStoreException();
            }
            else
            {
              _theImples.put(impleKey, jdbcImple);
              _theImple = jdbcImple;
View Full Code Here

    public void sync () throws java.io.SyncFailedException, ObjectStoreException
    {
  if (_imple != null)
      _imple.sync();
  else
      throw new ObjectStoreException(tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.objectstore.ObjectStore_1"));
    }
View Full Code Here

TOP

Related Classes of com.arjuna.ats.arjuna.exceptions.ObjectStoreException

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.