Search in sources :

Example 56 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class SQLDate method parseDate.

private void parseDate(String dateStr, boolean isJdbcEscape, LocaleFinder localeFinder, Calendar cal) throws StandardException {
    boolean validSyntax = true;
    DateTimeParser parser = new DateTimeParser(dateStr);
    int year = 0;
    int month = 0;
    int day = 0;
    StandardException thrownSE = null;
    try {
        switch(parser.nextSeparator()) {
            case ISO_SEPARATOR:
                encodedDate = SQLTimestamp.parseDateOrTimestamp(parser, false)[0];
                return;
            case IBM_USA_SEPARATOR:
                if (isJdbcEscape) {
                    validSyntax = false;
                    break;
                }
                month = parser.parseInt(2, true, IBM_USA_SEPARATOR_ONLY, false);
                day = parser.parseInt(2, true, IBM_USA_SEPARATOR_ONLY, false);
                year = parser.parseInt(4, false, END_OF_STRING, false);
                break;
            case IBM_EUR_SEPARATOR:
                if (isJdbcEscape) {
                    validSyntax = false;
                    break;
                }
                day = parser.parseInt(2, true, IBM_EUR_SEPARATOR_ONLY, false);
                month = parser.parseInt(2, true, IBM_EUR_SEPARATOR_ONLY, false);
                year = parser.parseInt(4, false, END_OF_STRING, false);
                break;
            default:
                validSyntax = false;
        }
    } catch (StandardException se) {
        validSyntax = false;
        thrownSE = se;
    }
    if (validSyntax) {
        encodedDate = computeEncodedDate(year, month, day);
    } else {
        // See if it is a localized date or timestamp.
        dateStr = StringUtil.trimTrailing(dateStr);
        DateFormat dateFormat = null;
        if (localeFinder == null)
            dateFormat = DateFormat.getDateInstance();
        else if (cal == null)
            dateFormat = localeFinder.getDateFormat();
        else
            dateFormat = (DateFormat) localeFinder.getDateFormat().clone();
        if (cal != null)
            dateFormat.setCalendar(cal);
        try {
            encodedDate = computeEncodedDate(dateFormat.parse(dateStr), cal);
        } catch (ParseException pe) {
            // Maybe it is a localized timestamp
            try {
                encodedDate = SQLTimestamp.parseLocalTimestamp(dateStr, localeFinder, cal)[0];
            } catch (ParseException pe2) {
                if (thrownSE != null)
                    throw thrownSE;
                throw StandardException.newException(SQLState.LANG_DATE_SYNTAX_EXCEPTION);
            }
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException)

Example 57 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class SQLBinary method writeBlob.

/**
 *		Serialize a blob using the 8.1 encoding. Not called if null.
 *
 * @exception IOException		io exception
 */
private void writeBlob(ObjectOutput out) throws IOException {
    try {
        int len = getBlobLength();
        InputStream is = _blobValue.getBinaryStream();
        writeLength(out, len);
        int bytesRead = 0;
        int numOfBytes = 0;
        byte[] buffer = new byte[Math.min(len, LEN_OF_BUFFER_TO_WRITE_BLOB)];
        while (bytesRead < len) {
            numOfBytes = is.read(buffer);
            if (numOfBytes == -1) {
                throw new DerbyIOException(MessageService.getTextMessage(SQLState.SET_STREAM_INEXACT_LENGTH_DATA), SQLState.SET_STREAM_INEXACT_LENGTH_DATA);
            }
            out.write(buffer, 0, numOfBytes);
            bytesRead += numOfBytes;
        }
    } catch (StandardException se) {
        throw new IOException(se.getMessage());
    } catch (SQLException se) {
        throw new IOException(se.getMessage());
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLException(java.sql.SQLException) FormatIdInputStream(org.apache.derby.iapi.services.io.FormatIdInputStream) InputStream(java.io.InputStream) DerbyIOException(org.apache.derby.iapi.services.io.DerbyIOException) IOException(java.io.IOException) DerbyIOException(org.apache.derby.iapi.services.io.DerbyIOException)

Example 58 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class SQLTimestamp method addInternal.

// end of timestampAdd
private void addInternal(int calIntervalType, int count, SQLTimestamp tsResult) throws StandardException {
    Calendar cal = new GregorianCalendar();
    setCalendar(cal);
    try {
        cal.add(calIntervalType, count);
        tsResult.encodedTime = SQLTime.computeEncodedTime(cal);
        tsResult.encodedDate = SQLDate.computeEncodedDate(cal);
    } catch (StandardException se) {
        String state = se.getSQLState();
        if (state != null && state.length() > 0 && SQLState.LANG_DATE_RANGE_EXCEPTION.startsWith(state)) {
            throw StandardException.newException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, "TIMESTAMP");
        }
        throw se;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 59 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class Deadlock method buildException.

/**
 * Build an exception that describes a deadlock.
 *
 * @param factory the lock factory requesting the exception
 * @param data an array with information about who's involved in
 * a deadlock (as returned by {@link #handle})
 * @return a deadlock exception
 */
static StandardException buildException(AbstractPool factory, Object[] data) {
    Stack chain = (Stack) data[0];
    Dictionary waiters = (Dictionary) data[1];
    LanguageConnectionContext lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
    TableNameInfo tabInfo = null;
    TransactionInfo[] tt = null;
    TransactionController tc = null;
    if (lcc != null) {
        try {
            tc = lcc.getTransactionExecute();
            tabInfo = new TableNameInfo(lcc, false);
            tt = tc.getAccessManager().getTransactionInfo();
        } catch (StandardException se) {
        // just don't get any table info.
        }
    }
    StringBuffer sb = new StringBuffer(200);
    Hashtable<String, Object> attributes = new Hashtable<String, Object>(17);
    String victimXID = null;
    for (int i = 0; i < chain.size(); i++) {
        Object space = chain.elementAt(i);
        if (space instanceof List) {
            List grants = (List) space;
            if (grants.size() != 0) {
                sb.append("  Granted XID : ");
                for (int j = 0; j < grants.size(); j++) {
                    if (j != 0)
                        sb.append(", ");
                    Lock gl = (Lock) grants.get(j);
                    sb.append("{");
                    sb.append(gl.getCompatabilitySpace().getOwner());
                    sb.append(", ");
                    sb.append(gl.getQualifier());
                    sb.append("} ");
                }
                sb.append('\n');
            }
            continue;
        }
        // Information about the lock we are waiting on
        // TYPE |TABLENAME                     |LOCKNAME
        Lock lock = ((Lock) waiters.get(space));
        // see if this lockable object wants to participate
        lock.getLockable().lockAttributes(VirtualLockTable.ALL, attributes);
        addInfo(sb, "Lock : ", attributes.get(VirtualLockTable.LOCKTYPE));
        if (tabInfo != null) {
            Long conglomId = (Long) attributes.get(VirtualLockTable.CONGLOMID);
            if (conglomId == null) {
                Long containerId = (Long) attributes.get(VirtualLockTable.CONTAINERID);
                try {
                    conglomId = tc.findConglomid(containerId.longValue());
                } catch (StandardException se) {
                }
            }
            addInfo(sb, ", ", tabInfo.getTableName(conglomId));
        }
        addInfo(sb, ", ", attributes.get(VirtualLockTable.LOCKNAME));
        sb.append('\n');
        String xid = String.valueOf(lock.getCompatabilitySpace().getOwner());
        if (i == 0)
            victimXID = xid;
        addInfo(sb, "  Waiting XID : {", xid);
        addInfo(sb, ", ", lock.getQualifier());
        sb.append("} ");
        if (tt != null) {
            for (int tti = tt.length - 1; tti >= 0; tti--) {
                TransactionInfo ti = tt[tti];
                // ti.getTransactionIdString() or ti can return null.
                if (ti != null) {
                    String idString = ti.getTransactionIdString();
                    if (idString != null && idString.equals(xid)) {
                        addInfo(sb, ", ", ti.getUsernameString());
                        addInfo(sb, ", ", ti.getStatementTextString());
                        break;
                    }
                }
            }
        }
        sb.append('\n');
        attributes.clear();
    }
    StandardException se = StandardException.newException(SQLState.DEADLOCK, sb.toString(), victimXID);
    se.setReport(factory.deadlockMonitor);
    return se;
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) Stack(java.util.Stack) StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) TransactionInfo(org.apache.derby.iapi.store.access.TransactionInfo) List(java.util.List) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 60 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class Timeout method dumpLock.

/**
 * dumpLock puts information about currentLock into currentRow for output later.
 * @throws StandardException
 */
private void dumpLock() throws StandardException {
    Hashtable<String, Object> attributes = new Hashtable<String, Object>(17);
    Object lock_type = currentLock.getQualifier();
    // want containerId, segmentId, pageNum, recId from locktable
    Lockable lockable = currentLock.getLockable();
    // See if the lockable object wants to participate
    if (!lockable.lockAttributes(ALL, attributes)) {
        currentRow = null;
        return;
    }
    // fields
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(attributes.get(VirtualLockTable.LOCKNAME) != null, "lock table can only represent locks that have a LOCKNAME");
        SanityManager.ASSERT(attributes.get(VirtualLockTable.LOCKTYPE) != null, "lock table can only represent locks that have a LOCKTYPE");
        if (attributes.get(VirtualLockTable.CONTAINERID) == null && attributes.get(VirtualLockTable.CONGLOMID) == null)
            SanityManager.THROWASSERT("lock table can only represent locks that are associated with a container or conglomerate");
    }
    Long conglomId = (Long) attributes.get(VirtualLockTable.CONGLOMID);
    if (conglomId == null) {
        if (attributes.get(VirtualLockTable.CONTAINERID) != null && tc != null) {
            Long value = (Long) attributes.get(VirtualLockTable.CONTAINERID);
            conglomId = tc.findConglomid(value.longValue());
            attributes.put(VirtualLockTable.CONGLOMID, conglomId);
        }
    }
    Long containerId = (Long) attributes.get(VirtualLockTable.CONTAINERID);
    if (containerId == null) {
        if (conglomId != null && tc != null) {
            try {
                containerId = tc.findContainerid(conglomId.longValue());
                attributes.put(VirtualLockTable.CONTAINERID, containerId);
            } catch (Exception e) {
            // just don't do anything
            }
        }
    }
    attributes.put(VirtualLockTable.LOCKOBJ, currentLock);
    attributes.put(VirtualLockTable.XACTID, String.valueOf(currentLock.getCompatabilitySpace().getOwner()));
    attributes.put(VirtualLockTable.LOCKMODE, lock_type.toString());
    attributes.put(VirtualLockTable.LOCKCOUNT, Integer.toString(currentLock.getCount()));
    attributes.put(VirtualLockTable.STATE, (currentLock.getCount() != 0) ? "GRANT" : "WAIT");
    if (tabInfo != null && conglomId != null) {
        try {
            String tableName = tabInfo.getTableName(conglomId);
            attributes.put(VirtualLockTable.TABLENAME, tableName);
        } catch (NullPointerException e) {
            attributes.put(VirtualLockTable.TABLENAME, conglomId);
        }
        try {
            String indexName = tabInfo.getIndexName(conglomId);
            if (indexName != null)
                attributes.put(VirtualLockTable.INDEXNAME, indexName);
            else {
                if (attributes.get(VirtualLockTable.LOCKTYPE).equals("LATCH")) {
                    // because MODE field is way to short to display this,
                    // just put it in the indexname field for LATCH only.
                    attributes.put(VirtualLockTable.INDEXNAME, attributes.get(VirtualLockTable.LOCKMODE));
                } else
                    attributes.put(VirtualLockTable.INDEXNAME, "NULL");
            }
        } catch (Exception e) {
            // we are here because tabInfo.indexCache is null
            if (VirtualLockTable.CONTAINERID != null)
                attributes.put(VirtualLockTable.INDEXNAME, VirtualLockTable.CONTAINERID);
            else
                attributes.put(VirtualLockTable.INDEXNAME, "NULL");
        }
        String tableType = tabInfo.getTableType(conglomId);
        attributes.put(VirtualLockTable.TABLETYPE, tableType);
    } else {
        if (conglomId != null)
            attributes.put(VirtualLockTable.TABLENAME, VirtualLockTable.CONGLOMID);
        else
            attributes.put(VirtualLockTable.TABLENAME, "NULL");
        if (VirtualLockTable.CONTAINERID != null)
            attributes.put(VirtualLockTable.INDEXNAME, VirtualLockTable.CONTAINERID);
        else
            attributes.put(VirtualLockTable.INDEXNAME, "NULL");
        attributes.put(VirtualLockTable.TABLETYPE, currentLock.toString());
    }
    currentRow = attributes;
}
Also used : Hashtable(java.util.Hashtable) Lockable(org.apache.derby.iapi.services.locks.Lockable) StandardException(org.apache.derby.shared.common.error.StandardException)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8