Package org.apache.derby.impl.jdbc

Examples of org.apache.derby.impl.jdbc.EmbedSQLException


  public static StandardException unexpectedUserException(Throwable t)
  {
        // If the exception is an SQLException generated by Derby, it has an
        // argument ferry which is an EmbedSQLException. Use this to check
        // whether the exception was generated by Derby.
        EmbedSQLException ferry = null;
        if (t instanceof SQLException) {
            SQLException sqle =
                Util.getExceptionFactory().getArgumentFerry((SQLException) t);
            if (sqle instanceof EmbedSQLException) {
                ferry = (EmbedSQLException) sqle;
            }
        }

    /*
    ** If we have a SQLException that isn't an EmbedSQLException
    ** (i.e. it didn't come from Derby), then we check
    ** to see if it is a valid user defined exception range
    ** (38001-38XXX).  If so, then we convert it into a
    ** StandardException without further ado.
    */
    if ((t instanceof SQLException) && (ferry == null))
    {
      SQLException sqlex  = (SQLException)t;
      String state = sqlex.getSQLState();
      if ((state != null) &&
        (state.length() == 5) &&
        state.startsWith("38") &&
        !state.equals("38000"))
      {
        StandardException se = new StandardException(state, sqlex.getMessage());
        if (sqlex.getNextException() != null)   
        { 
          se.initCause(sqlex.getNextException());
        }
        return se;
      }
    }

    // Look for simple wrappers for 3.0.1 - will be cleaned up in main
    if (ferry != null) {
      if (ferry.isSimpleWrapper()) {
        Throwable wrapped = ferry.getCause();
        if (wrapped instanceof StandardException)
          return (StandardException) wrapped;
      }
    }


    // no need to wrap a StandardException
    if (t instanceof StandardException)
    {
      return (StandardException) t;
    }
    else
    {
      /*
      **
      ** The exception at this point could be a:
      **
      **    standard java exception, e.g. NullPointerException
      **    SQL Exception - from some server-side JDBC
      **    3rd party exception - from some application
      **    some Derby exception that is not a standard exception.
      **   
      **   
      ** We don't want to call t.toString() here, because the JVM is
      ** inconsistent about whether it includes a detail message
      ** with some exceptions (esp. NullPointerException).  In those
      ** cases where there is a detail message, t.toString() puts in
      ** a colon character, even when the detail message is blank.
      ** So, we do our own string formatting here, including the colon
      ** only when there is a non-blank message.
      **
      ** The above is because our test canons contain the text of
      ** error messages.
      **
      ** In the past we didn't want to place the class name in
      ** an exception because Cloudscape builds were
      ** obfuscated, so the class name would change from build
                        ** to build. This is no longer true for Derby, but for
      ** exceptions that are Derby's, i.e. EmbedSQLException,
      ** we use toString(). If this returns an empty or null
      ** then we use the class name to make tracking the
                        ** problem down easier, though the lack of a message
      ** should be seen as a bug.
      */
      String  detailMessage;
      boolean derbyException = false;

      if (ferry != null) {
        detailMessage = ferry.toString();
        derbyException = true;
      }
      else {
        detailMessage = t.getMessage();
      }
View Full Code Here


      }
    }

    // Look for simple wrappers for 3.0.1 - will be cleaned up in main
    if (t instanceof EmbedSQLException) {
      EmbedSQLException csqle = (EmbedSQLException) t;
      if (csqle.isSimpleWrapper()) {
        Throwable wrapped = csqle.getJavaException();
        if (wrapped instanceof StandardException)
          return (StandardException) wrapped;
      }
    }
View Full Code Here

            log.error(e.getNextException().getMessage(), e.getNextException());
         }

         if (e instanceof EmbedSQLException)
         {
            EmbedSQLException es = (EmbedSQLException) e;

            if ("XJ040.C".equals(es.getMessageId()))
            {
               throw new HermesException("Is another instance of HermesJMS running?", e);
            }
         }
View Full Code Here

      }
    }

    // Look for simple wrappers for 3.0.1 - will be cleaned up in main
    if (t instanceof EmbedSQLException) {
      EmbedSQLException csqle = (EmbedSQLException) t;
      if (csqle.isSimpleWrapper()) {
        Throwable wrapped = csqle.getJavaException();
        if (wrapped instanceof StandardException)
          return (StandardException) wrapped;
      }
    }
View Full Code Here

        }
      }
      sqlState = e.getSQLState();
      if (e instanceof EmbedSQLException)
      {
        EmbedSQLException ce = (EmbedSQLException) e;
        boolean severeException = (ce.getErrorCode() >=  ExceptionSeverity.SESSION_SEVERITY);
        /* we need messageId to retrieve the localized message, just using
         * sqlstate may not be easy, because it is the messageId that we
         * used as key in the property file, for many sqlstates, they are
         * just the first 5 characters of the corresponding messageId.
         * We append messageId as the last element of sqlerrmc.  We can't
         * send messageId in the place of sqlstate because jcc expects only
         * 5 chars for sqlstate.
         */
        sqlerrmc = "";
        byte[] sep = {20}// use it as separator of sqlerrmc tokens
        byte[] errSep = {20, 20, 20}// mark between exceptions
        String separator = new String(sep);
        String errSeparator = new String(errSep);
        String dbname = null;
        if (database != null)
          dbname = database.dbName;
       
        do {
          String messageId = ce.getMessageId();
         
          // arguments are variable part of a message
          Object[] args = ce.getArguments();
          for (int i = 0; args != null &&  i < args.length; i++)
            sqlerrmc += args[i].toString() + separator;
         
          // Severe exceptions need to be logged in the error log
          // also log location and non-localized message will be
          // returned to client as appended arguments
          if (severeException
          {
            if (severeExceptionInfo == null)
              severeExceptionInfo = "";
            severeExceptionInfo += ce.getMessage() + separator;
            println2Log(dbname, session.drdaID, ce.getMessage());
          }
          sqlerrmc += messageId;   //append MessageId
       
          e = ce.getNextException();
          if (e != null) {
            if (e instanceof EmbedSQLException) {
              ce = (EmbedSQLException)e;
              sqlerrmc += errSeparator + ce.getSQLState() + ":";
            }
            else {
              sqlerrmc += errSeparator + e.getSQLState() + ":";
              ce = null;
            }
View Full Code Here

      }
    }

    // Look for simple wrappers for 3.0.1 - will be cleaned up in main
    if (t instanceof EmbedSQLException) {
      EmbedSQLException csqle = (EmbedSQLException) t;
      if (csqle.isSimpleWrapper()) {
        Throwable wrapped = csqle.getJavaException();
        if (wrapped instanceof StandardException)
          return (StandardException) wrapped;
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.derby.impl.jdbc.EmbedSQLException

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.