Search in sources :

Example 21 with ServiceRequestBuffer

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

the class TestJaybirdBlobBackupProblem method startBackup.

private void startBackup(FbService service) throws SQLException {
    final ServiceRequestBuffer serviceRequestBuffer = service.createServiceRequestBuffer();
    serviceRequestBuffer.addArgument(ISCConstants.isc_action_svc_backup);
    serviceRequestBuffer.addArgument(SpbItems.isc_spb_verbose);
    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 22 with ServiceRequestBuffer

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

the class TestServicesAPI method startBackup.

private void startBackup(FbService service) throws SQLException {
    ServiceRequestBuffer serviceRequestBuffer = service.createServiceRequestBuffer();
    serviceRequestBuffer.addArgument(ISCConstants.isc_action_svc_backup);
    serviceRequestBuffer.addArgument(SpbItems.isc_spb_verbose);
    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 23 with ServiceRequestBuffer

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

the class TestServicesAPI method queryService.

private void queryService(FbService service, String outputFilename) throws Exception {
    final ServiceRequestBuffer serviceRequestBuffer = service.createServiceRequestBuffer();
    serviceRequestBuffer.addArgument(ISCConstants.isc_info_svc_to_eof);
    boolean finished = false;
    try (FileOutputStream file = new FileOutputStream(outputFilename)) {
        while (!finished) {
            byte[] buffer = service.getServiceInfo(null, serviceRequestBuffer, 1024);
            final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer);
            // TODO Find out why unused
            final byte firstByte = (byte) byteArrayInputStream.read();
            int numberOfBytes = (short) ((byteArrayInputStream.read()) + (byteArrayInputStream.read() << 8));
            if (numberOfBytes == 0) {
                if (byteArrayInputStream.read() != ISCConstants.isc_info_end)
                    throw new Exception("Expect ISCConstants.isc_info_end here");
                finished = true;
            } else {
                for (; numberOfBytes >= 0; numberOfBytes--) file.write(byteArrayInputStream.read());
            }
        }
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException)

Example 24 with ServiceRequestBuffer

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

the class FBNBackupManager method getBackupSRB.

/**
 * Creates and returns the "backup" service request buffer for the Service Manager.
 *
 * @param service
 *         Service handle
 * @return the "backup" service request buffer for the Service Manager.
 */
private ServiceRequestBuffer getBackupSRB(FbService service) throws SQLException {
    ServiceRequestBuffer backupSPB = service.createServiceRequestBuffer();
    backupSPB.addArgument(isc_action_svc_nbak);
    backupSPB.addArgument(isc_spb_dbname, getDatabase());
    if (backupFiles.isEmpty()) {
        throw new SQLException("No backup file specified");
    }
    String backupFile = backupFiles.get(0);
    backupSPB.addArgument(isc_spb_nbk_file, backupFile);
    // Previously, the default level was 0, retain that default if no backup GUID has been set
    int resolvedBackupLevel = backupLevel == -1 && backupGuid == null ? 0 : backupLevel;
    backupSPB.addArgument(isc_spb_nbk_level, resolvedBackupLevel);
    if (backupGuid != null) {
        backupSPB.addArgument(isc_spb_nbk_guid, backupGuid);
    }
    int options = getOptions();
    if (options != 0) {
        backupSPB.addArgument(isc_spb_options, options);
    }
    return backupSPB;
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException)

Example 25 with ServiceRequestBuffer

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

the class FBNBackupManager method getRestoreSRB.

/**
 * Creates and returns the "restore" service request buffer for the Service Manager.
 *
 * @return the "restore" service request buffer for the Service Manager.
 */
private ServiceRequestBuffer getRestoreSRB(FbService service) throws SQLException {
    ServiceRequestBuffer restoreSPB = service.createServiceRequestBuffer();
    restoreSPB.addArgument(isc_action_svc_nrest);
    restoreSPB.addArgument(isc_spb_dbname, getDatabase());
    if (backupFiles.isEmpty()) {
        throw new SQLException("No backup file specified");
    }
    for (String backupFile : backupFiles) {
        restoreSPB.addArgument(isc_spb_nbk_file, backupFile);
    }
    int options = getOptions();
    if (options != 0) {
        restoreSPB.addArgument(isc_spb_options, options);
    }
    return restoreSPB;
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException)

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