Search in sources :

Example 1 with NotUpdatable

use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project aws-mysql-jdbc by awslabs.

the class UpdatableResultSet method moveToInsertRow.

@Override
public void moveToInsertRow() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.isUpdatable) {
            throw new NotUpdatable(this.notUpdatableReason);
        }
        if (this.inserter == null) {
            if (this.insertSQL == null) {
                generateStatements();
            }
            this.inserter = (ClientPreparedStatement) this.getConnection().clientPrepareStatement(this.insertSQL);
            this.inserter.getQueryBindings().setColumnDefinition(this.getMetadata());
            if (this.populateInserterWithDefaultValues) {
                extractDefaultValues();
            }
        }
        resetInserter();
        Field[] fields = this.getMetadata().getFields();
        int numFields = fields.length;
        this.onInsertRow = true;
        this.doingUpdates = false;
        this.savedCurrentRow = this.thisRow;
        byte[][] newRowData = new byte[numFields][];
        this.thisRow = new ByteArrayRow(newRowData, getExceptionInterceptor());
        this.thisRow.setMetadata(this.getMetadata());
        for (int i = 0; i < numFields; i++) {
            if (!this.populateInserterWithDefaultValues) {
                this.inserter.setBytesNoEscapeNoQuotes(i + 1, StringUtils.getBytes("DEFAULT"));
                newRowData = null;
            } else {
                if (this.defaultColumnValue[i] != null) {
                    Field f = fields[i];
                    switch(f.getMysqlTypeId()) {
                        case MysqlType.FIELD_TYPE_DATE:
                        case MysqlType.FIELD_TYPE_DATETIME:
                        case MysqlType.FIELD_TYPE_TIME:
                        case MysqlType.FIELD_TYPE_TIMESTAMP:
                            if (this.defaultColumnValue[i].length > 7 && this.defaultColumnValue[i][0] == (byte) 'C' && this.defaultColumnValue[i][1] == (byte) 'U' && this.defaultColumnValue[i][2] == (byte) 'R' && this.defaultColumnValue[i][3] == (byte) 'R' && this.defaultColumnValue[i][4] == (byte) 'E' && this.defaultColumnValue[i][5] == (byte) 'N' && this.defaultColumnValue[i][6] == (byte) 'T' && this.defaultColumnValue[i][7] == (byte) '_') {
                                this.inserter.setBytesNoEscapeNoQuotes(i + 1, this.defaultColumnValue[i]);
                            } else {
                                this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
                            }
                            break;
                        default:
                            this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
                    }
                    // This value _could_ be changed from a getBytes(), so we need a copy....
                    byte[] defaultValueCopy = new byte[this.defaultColumnValue[i].length];
                    System.arraycopy(this.defaultColumnValue[i], 0, defaultValueCopy, 0, defaultValueCopy.length);
                    newRowData[i] = defaultValueCopy;
                } else {
                    this.inserter.setNull(i + 1, MysqlType.NULL);
                    newRowData[i] = null;
                }
            }
        }
    }
}
Also used : NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) Field(com.mysql.cj.result.Field) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Example 2 with NotUpdatable

use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project aws-mysql-jdbc by awslabs.

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Example 3 with NotUpdatable

use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project ABC by RuiPinto96274.

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Example 4 with NotUpdatable

use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project JavaSegundasQuintas by ecteruel.

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Example 5 with NotUpdatable

use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project JavaSegundasQuintas by ecteruel.

the class UpdatableResultSet method moveToInsertRow.

@Override
public void moveToInsertRow() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.isUpdatable) {
            throw new NotUpdatable(this.notUpdatableReason);
        }
        if (this.inserter == null) {
            if (this.insertSQL == null) {
                generateStatements();
            }
            this.inserter = (ClientPreparedStatement) this.getConnection().clientPrepareStatement(this.insertSQL);
            this.inserter.getQueryBindings().setColumnDefinition(this.getMetadata());
            if (this.populateInserterWithDefaultValues) {
                extractDefaultValues();
            }
        }
        resetInserter();
        Field[] fields = this.getMetadata().getFields();
        int numFields = fields.length;
        this.onInsertRow = true;
        this.doingUpdates = false;
        this.savedCurrentRow = this.thisRow;
        byte[][] newRowData = new byte[numFields][];
        this.thisRow = new ByteArrayRow(newRowData, getExceptionInterceptor());
        this.thisRow.setMetadata(this.getMetadata());
        for (int i = 0; i < numFields; i++) {
            if (!this.populateInserterWithDefaultValues) {
                this.inserter.setBytesNoEscapeNoQuotes(i + 1, StringUtils.getBytes("DEFAULT"));
                newRowData = null;
            } else {
                if (this.defaultColumnValue[i] != null) {
                    Field f = fields[i];
                    switch(f.getMysqlTypeId()) {
                        case MysqlType.FIELD_TYPE_DATE:
                        case MysqlType.FIELD_TYPE_DATETIME:
                        case MysqlType.FIELD_TYPE_TIME:
                        case MysqlType.FIELD_TYPE_TIMESTAMP:
                            if (this.defaultColumnValue[i].length > 7 && this.defaultColumnValue[i][0] == (byte) 'C' && this.defaultColumnValue[i][1] == (byte) 'U' && this.defaultColumnValue[i][2] == (byte) 'R' && this.defaultColumnValue[i][3] == (byte) 'R' && this.defaultColumnValue[i][4] == (byte) 'E' && this.defaultColumnValue[i][5] == (byte) 'N' && this.defaultColumnValue[i][6] == (byte) 'T' && this.defaultColumnValue[i][7] == (byte) '_') {
                                this.inserter.setBytesNoEscapeNoQuotes(i + 1, this.defaultColumnValue[i]);
                            } else {
                                this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
                            }
                            break;
                        default:
                            this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
                    }
                    // This value _could_ be changed from a getBytes(), so we need a copy....
                    byte[] defaultValueCopy = new byte[this.defaultColumnValue[i].length];
                    System.arraycopy(this.defaultColumnValue[i], 0, defaultValueCopy, 0, defaultValueCopy.length);
                    newRowData[i] = defaultValueCopy;
                } else {
                    this.inserter.setNull(i + 1, MysqlType.NULL);
                    newRowData[i] = null;
                }
            }
        }
    }
}
Also used : NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) Field(com.mysql.cj.result.Field) ByteArrayRow(com.mysql.cj.protocol.a.result.ByteArrayRow)

Aggregations

NotUpdatable (com.mysql.cj.jdbc.exceptions.NotUpdatable)6 CommunicationsException (com.mysql.cj.jdbc.exceptions.CommunicationsException)3 ConnectionFeatureNotAvailableException (com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException)3 MySQLQueryInterruptedException (com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException)3 MySQLStatementCancelledException (com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException)3 MySQLTimeoutException (com.mysql.cj.jdbc.exceptions.MySQLTimeoutException)3 MySQLTransactionRollbackException (com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException)3 MysqlDataTruncation (com.mysql.cj.jdbc.exceptions.MysqlDataTruncation)3 OperationNotSupportedException (com.mysql.cj.jdbc.exceptions.OperationNotSupportedException)3 PacketTooBigException (com.mysql.cj.jdbc.exceptions.PacketTooBigException)3 SQLError (com.mysql.cj.jdbc.exceptions.SQLError)3 PacketReceivedTimeHolder (com.mysql.cj.protocol.PacketReceivedTimeHolder)3 PacketSentTimeHolder (com.mysql.cj.protocol.PacketSentTimeHolder)3 ByteArrayRow (com.mysql.cj.protocol.a.result.ByteArrayRow)3 Field (com.mysql.cj.result.Field)3 SQLException (java.sql.SQLException)3 Test (org.junit.jupiter.api.Test)3