Java Code Examples for com.mysql.cj.exceptions.AssertionFailedException#shouldNotHappen()

The following examples show how to use com.mysql.cj.exceptions.AssertionFailedException#shouldNotHappen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Close any open result sets that have been 'held open'
 */
protected void closeAllOpenResults() throws SQLException {
    JdbcConnection locallyScopedConn = this.connection;

    if (locallyScopedConn == null) {
        return; // already closed
    }

    synchronized (locallyScopedConn.getConnectionMutex()) {
        if (this.openResults != null) {
            for (ResultSetInternalMethods element : this.openResults) {
                try {
                    element.realClose(false);
                } catch (SQLException sqlEx) {
                    AssertionFailedException.shouldNotHappen(sqlEx);
                }
            }

            this.openResults.clear();
        }
    }
}
 
Example 2
Source File: AddStatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AddStatement add(String jsonString) {
    try {
        DbDoc doc = JsonParser.parseDoc(new StringReader(jsonString));
        return add(doc);
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 3
Source File: CreateIndexParams.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param indexName
 *            index name
 * @param jsonIndexDefinition
 *            special JSON document containing index definition; see {@link Collection#createIndex(String, String)} description
 */
public CreateIndexParams(String indexName, String jsonIndexDefinition) {
    if (jsonIndexDefinition == null || jsonIndexDefinition.trim().length() == 0) {
        throw new XDevAPIError(Messages.getString("CreateIndexParams.0", new String[] { "jsonIndexDefinition" }));
    }
    try {
        init(indexName, JsonParser.parseDoc(new StringReader(jsonIndexDefinition)));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 4
Source File: AddStatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public AddStatement add(String jsonString) {
    try {
        DbDoc doc = JsonParser.parseDoc(new StringReader(jsonString));
        return add(doc);
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 5
Source File: JsonParser.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create {@link DbDoc} object from JSON string.
 * 
 * @param jsonString
 *            JSON string representing a document
 * @return New {@link DbDoc} object initialized by parsed JSON string.
 */
public static DbDoc parseDoc(String jsonString) {
    try {
        return JsonParser.parseDoc(new StringReader(jsonString));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 6
Source File: CollectionImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Result addOrReplaceOne(String id, String jsonString) {
    if (id == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "id" }));
    }
    if (jsonString == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "jsonString" }));
    }
    try {
        return addOrReplaceOne(id, JsonParser.parseDoc(new StringReader(jsonString)));
    } catch (IOException e) {
        throw AssertionFailedException.shouldNotHappen(e);
    }
}
 
Example 7
Source File: CollectionImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Result replaceOne(String id, String jsonString) {
    if (id == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "id" }));
    }
    if (jsonString == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "jsonString" }));
    }
    try {
        return replaceOne(id, JsonParser.parseDoc(new StringReader(jsonString)));
    } catch (IOException e) {
        throw AssertionFailedException.shouldNotHappen(e);
    }
}
 
Example 8
Source File: XProtocol.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public byte[] readAuthenticateContinue() {
    try {
        AuthenticateContinue msg = (AuthenticateContinue) this.reader.readMessage(null, ServerMessages.Type.SESS_AUTHENTICATE_CONTINUE_VALUE).getMessage();
        byte[] data = msg.getAuthData().toByteArray();
        if (data.length != 20) {
            throw AssertionFailedException.shouldNotHappen("Salt length should be 20, but is " + data.length);
        }
        return data;
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
 
Example 9
Source File: DbDocValueFactory.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Interpret the given byte array as a string. This value factory needs to know the encoding to interpret the string. The default (null) will interpret the
 * byte array using the platform encoding.
 */
@Override
public DbDoc createFromBytes(byte[] bytes, int offset, int length) {
    try {
        return JsonParser.parseDoc(new StringReader(StringUtils.toString(bytes, offset, length, this.encoding)));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 10
Source File: MessageConstants.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public static Class<? extends GeneratedMessageV3> getMessageClassForType(int type) {
    Class<? extends GeneratedMessageV3> messageClass = MessageConstants.MESSAGE_TYPE_TO_CLASS.get(type);
    if (messageClass == null) {
        // check if there's a mapping that we don't explicitly handle
        ServerMessages.Type serverMessageMapping = ServerMessages.Type.forNumber(type);
        throw AssertionFailedException.shouldNotHappen("Unknown message type: " + type + " (server messages mapping: " + serverMessageMapping + ")");
    }
    return messageClass;
}
 
Example 11
Source File: CreateIndexParams.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public CreateIndexParams(String indexName, String jsonIndexDefinition) {
    if (jsonIndexDefinition == null || jsonIndexDefinition.trim().length() == 0) {
        throw new XDevAPIError(Messages.getString("CreateIndexParams.0", new String[] { "jsonIndexDefinition" }));
    }
    try {
        init(indexName, JsonParser.parseDoc(new StringReader(jsonIndexDefinition)));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 12
Source File: MessageConstants.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static Class<? extends GeneratedMessage> getMessageClassForType(int type) {
    Class<? extends GeneratedMessage> messageClass = MessageConstants.MESSAGE_TYPE_TO_CLASS.get(type);
    if (messageClass == null) {
        // check if there's a mapping that we don't explicitly handle
        ServerMessages.Type serverMessageMapping = ServerMessages.Type.valueOf(type);
        throw AssertionFailedException.shouldNotHappen("Unknown message type: " + type + " (server messages mapping: " + serverMessageMapping + ")");
    }
    return messageClass;
}
 
Example 13
Source File: JsonParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static DbDoc parseDoc(String jsonString) {
    try {
        return JsonParser.parseDoc(new StringReader(jsonString));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 14
Source File: CollectionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Result addOrReplaceOne(String id, String jsonString) {
    if (id == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "id" }));
    }
    if (jsonString == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "jsonString" }));
    }
    try {
        return addOrReplaceOne(id, JsonParser.parseDoc(new StringReader(jsonString)));
    } catch (IOException e) {
        throw AssertionFailedException.shouldNotHappen(e);
    }
}
 
Example 15
Source File: CollectionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Result replaceOne(String id, String jsonString) {
    if (id == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "id" }));
    }
    if (jsonString == null) {
        throw new XDevAPIError(Messages.getString("CreateTableStatement.0", new String[] { "jsonString" }));
    }
    try {
        return replaceOne(id, JsonParser.parseDoc(new StringReader(jsonString)));
    } catch (IOException e) {
        throw AssertionFailedException.shouldNotHappen(e);
    }
}
 
Example 16
Source File: CollectionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AddStatement add(String... jsonString) {
    try {
        DbDoc[] docs = new DbDoc[jsonString.length];
        for (int i = 0; i < jsonString.length; i++) {
            docs[i] = JsonParser.parseDoc(new StringReader(jsonString[i]));
        }
        return add(docs);
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 17
Source File: DbDocValueFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Interpret the given byte array as a string. This value factory needs to know the encoding to interpret the string. The default (null) will interpet the
 * byte array using the platform encoding.
 */
@Override
public DbDoc createFromBytes(byte[] bytes, int offset, int length) {
    try {
        return JsonParser.parseDoc(new StringReader(StringUtils.toString(bytes, offset, length, this.encoding)));
    } catch (IOException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}
 
Example 18
Source File: XProtocol.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public byte[] readAuthenticateContinue() {
    try {
        AuthenticateContinue msg = (AuthenticateContinue) this.reader.readMessage(null, ServerMessages.Type.SESS_AUTHENTICATE_CONTINUE_VALUE).getMessage();
        byte[] data = msg.getAuthData().toByteArray();
        if (data.length != 20) {
            throw AssertionFailedException.shouldNotHappen("Salt length should be 20, but is " + data.length);
        }
        return data;
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
 
Example 19
Source File: XProtocolDecoder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    try {
        CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
        // packed BCD format (c.f. wikipedia)
        // TODO: optimization possibilities include using int/long if the digits is < X and scale = 0
        byte scale = inputStream.readRawByte();
        // we allocate an extra char for the sign
        CharBuffer unscaledString = CharBuffer.allocate(2 * inputStream.getBytesUntilLimit());
        unscaledString.position(1);
        byte sign = 0;
        // read until we encounter the sign bit
        while (true) {
            int b = 0xFF & inputStream.readRawByte();
            if ((b >> 4) > 9) {
                sign = (byte) (b >> 4);
                break;
            }
            unscaledString.append((char) ((b >> 4) + '0'));
            if ((b & 0x0f) > 9) {
                sign = (byte) (b & 0x0f);
                break;
            }
            unscaledString.append((char) ((b & 0x0f) + '0'));
        }
        if (inputStream.getBytesUntilLimit() > 0) {
            throw AssertionFailedException
                    .shouldNotHappen("Did not read all bytes while decoding decimal. Bytes left: " + inputStream.getBytesUntilLimit());
        }
        switch (sign) {
            case 0xa:
            case 0xc:
            case 0xe:
            case 0xf:
                unscaledString.put(0, '+');
                break;
            case 0xb:
            case 0xd:
                unscaledString.put(0, '-');
                break;
        }
        // may have filled the CharBuffer or one remaining. need to remove it before toString()
        int characters = unscaledString.position();
        unscaledString.clear(); // reset position
        BigInteger unscaled = new BigInteger(unscaledString.subSequence(0, characters).toString());
        return vf.createFromBigDecimal(new BigDecimal(unscaled, scale));
    } catch (IOException e) {
        throw new DataReadException(e);
    }
}
 
Example 20
Source File: AsyncMessageReader.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Parse a message.
 * 
 * @param messageClass
 *            class extending {@link GeneratedMessage}
 * @param buf
 *            message buffer
 * @return {@link GeneratedMessage}
 */
private GeneratedMessage parseMessage(Class<? extends GeneratedMessage> messageClass, ByteBuffer buf) {
    try {
        Parser<? extends GeneratedMessage> parser = MessageConstants.MESSAGE_CLASS_TO_PARSER.get(messageClass);
        return parser.parseFrom(CodedInputStream.newInstance(buf));
    } catch (InvalidProtocolBufferException ex) {
        throw AssertionFailedException.shouldNotHappen(ex);
    }
}