Search in sources :

Example 36 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBMaintenanceManager method setDatabaseDialect.

public void setDatabaseDialect(int dialect) throws SQLException {
    if (dialect != 1 && dialect != 3) {
        throw new IllegalArgumentException("dialect must be either 1 or 3");
    }
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createDefaultPropertiesSRB(service);
        srb.addArgument(isc_spb_prp_set_sql_dialect, dialect);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 37 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBMaintenanceManager method setForcedWrites.

public void setForcedWrites(boolean forced) throws SQLException {
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createDefaultPropertiesSRB(service);
        srb.addArgument(isc_spb_prp_write_mode, (byte) (forced ? isc_spb_prp_wm_sync : isc_spb_prp_wm_async));
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 38 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBMaintenanceManager method validateDatabase.

public void validateDatabase(int options) throws SQLException {
    if (options < 0 || options != 0 && options != VALIDATE_IGNORE_CHECKSUM && (options & ~VALIDATE_IGNORE_CHECKSUM) != VALIDATE_READ_ONLY && (options & ~VALIDATE_IGNORE_CHECKSUM) != VALIDATE_FULL && (options | (VALIDATE_READ_ONLY | VALIDATE_IGNORE_CHECKSUM)) != options && (options | (VALIDATE_FULL | VALIDATE_IGNORE_CHECKSUM)) != options) {
        throw new IllegalArgumentException("options must be either 0, " + "VALIDATE_READ_ONLY, or VALIDATE_FULL, optionally combined with VALIDATE_IGNORE_CHECKSUM");
    }
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createRepairSRB(service, options | isc_spb_rpr_validate_db);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 39 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBMaintenanceManager method executeRepairOperation.

// ----------- Private implementation methods --------------------
/**
 * Execute a isc_spb_rpr_* (repair) services operation.
 *
 * @param operation
 *         The identifier for the operation to be executed
 * @throws SQLException
 *         if a database access error occurs
 */
private void executeRepairOperation(int operation) throws SQLException {
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createRepairSRB(service, operation);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 40 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class TestV10Service method testStartServiceAction.

/**
 * Test for service action.
 * <p>
 * Replicates the behavior of {@link FBStatisticsManager#getHeaderPage()}.
 * </p>
 */
@Test
public void testStartServiceAction() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireServiceConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireService service = gdsConnection.identify()) {
            assertEquals("Unexpected FbWireService implementation", getExpectedServiceType(), service.getClass());
            service.attach();
            ServiceRequestBuffer actionSrb = service.createServiceRequestBuffer();
            actionSrb.addArgument(isc_action_svc_db_stats);
            actionSrb.addArgument(isc_spb_dbname, getDatabasePath());
            actionSrb.addArgument(isc_spb_options, isc_spb_sts_hdr_pages);
            service.startServiceAction(actionSrb);
            ServiceRequestBuffer infoSrb = service.createServiceRequestBuffer();
            infoSrb.addArgument(isc_info_svc_to_eof);
            int bufferSize = 1024;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            boolean processing = true;
            while (processing) {
                byte[] buffer = service.getServiceInfo(null, infoSrb, bufferSize);
                switch(buffer[0]) {
                    case isc_info_svc_to_eof:
                        int dataLength = iscVaxInteger2(buffer, 1);
                        if (dataLength == 0) {
                            if (buffer[3] != isc_info_end) {
                                throw new SQLException("Unexpected end of stream reached.");
                            } else {
                                processing = false;
                                break;
                            }
                        }
                        bos.write(buffer, 3, dataLength);
                        break;
                    case isc_info_truncated:
                        bufferSize = bufferSize * 2;
                        break;
                    case isc_info_end:
                        processing = false;
                        break;
                }
            }
            String headerPage = service.getEncoding().decodeFromCharset(bos.toByteArray());
            assertThat("Expected database header page content", headerPage, allOf(startsWith("\nDatabase"), containsString("Database header page information"), containsString("*END*\n")));
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) WireServiceConnection(org.firebirdsql.gds.ng.wire.WireServiceConnection) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FbWireService(org.firebirdsql.gds.ng.wire.FbWireService) AbstractFbWireService(org.firebirdsql.gds.ng.wire.AbstractFbWireService) Test(org.junit.Test)

Aggregations

ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)40 FbService (org.firebirdsql.gds.ng.FbService)20 SQLException (java.sql.SQLException)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 FBManager (org.firebirdsql.management.FBManager)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ServiceParameterBuffer (org.firebirdsql.gds.ServiceParameterBuffer)1 AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)1 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)1 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)1