Search in sources :

Example 1 with ServiceRequestBuffer

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

the class TestServicesAPI method startRestore.

private void startRestore(FbService service) throws SQLException {
    final ServiceRequestBuffer serviceRequestBuffer = service.createServiceRequestBuffer();
    serviceRequestBuffer.addArgument(ISCConstants.isc_action_svc_restore);
    serviceRequestBuffer.addArgument(SpbItems.isc_spb_verbose);
    serviceRequestBuffer.addArgument(SpbItems.isc_spb_options, ISCConstants.isc_spb_res_create);
    serviceRequestBuffer.addArgument(SpbItems.isc_spb_dbname, mAbsoluteDatabasePath);
    serviceRequestBuffer.addArgument(ISCConstants.isc_spb_bkp_file, mAbsoluteBackupPath);
    service.startServiceAction(serviceRequestBuffer);
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer)

Example 2 with ServiceRequestBuffer

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

the class TestJnaService 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 (JnaService service = factory.serviceConnect(connectionInfo)) {
        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) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with ServiceRequestBuffer

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

the class FBMaintenanceManager method shutdownDatabase.

public void shutdownDatabase(byte operationMode, int shutdownModeEx, int timeout) throws SQLException {
    if (operationMode != OPERATION_MODE_MULTI && operationMode != OPERATION_MODE_SINGLE && operationMode != OPERATION_MODE_FULL_SHUTDOWN) {
        throw new IllegalArgumentException("Operation mode must be one of: OPERATION_MODE_MULTI, " + "OPERATION_MODE_SINGLE, OPERATION_MODE_FULL_SHUTDOWN");
    }
    if (shutdownModeEx != SHUTDOWNEX_FORCE && shutdownModeEx != SHUTDOWNEX_ATTACHMENTS && shutdownModeEx != SHUTDOWNEX_TRANSACTIONS) {
        throw new IllegalArgumentException("Extended shutdown mode must be " + "one of: SHUTDOWNEX_FORCE, SHUTDOWNEX_ATTACHMENTS, SHUTDOWNEX_TRANSACTIONS");
    }
    if (timeout < 0) {
        throw new IllegalArgumentException("Timeout must be >= 0");
    }
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createDefaultPropertiesSRB(service);
        srb.addArgument(isc_spb_prp_shutdown_mode, operationMode);
        srb.addArgument(shutdownModeEx, timeout);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 4 with ServiceRequestBuffer

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

the class FBMaintenanceManager method setSweepThreshold.

// ----------- Sweeping -------------------------
public void setSweepThreshold(int transactions) throws SQLException {
    if (transactions < 0) {
        throw new IllegalArgumentException("transactions must be >= 0");
    }
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createDefaultPropertiesSRB(service);
        srb.addArgument(isc_spb_prp_sweep_interval, transactions);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) FbService(org.firebirdsql.gds.ng.FbService)

Example 5 with ServiceRequestBuffer

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

the class FBMaintenanceManager method handleTransaction.

private void handleTransaction(final long transactionId, final int action32bit, final int action64bit) throws SQLException {
    if (transactionId < 0) {
        throw new SQLException("Only positive transactionIds are supported");
    }
    final boolean is32Bit = NumericHelper.fitsUnsigned32BitInteger(transactionId);
    try (FbService service = attachServiceManager()) {
        ServiceRequestBuffer srb = createDefaultRepairSRB(service);
        srb.addArgument(is32Bit ? action32bit : action64bit, transactionId);
        executeServicesOperation(service, srb);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException) FbService(org.firebirdsql.gds.ng.FbService)

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