/** * Creates and returns the "backup" service request buffer for the Service Manager. * * @param service Service handle * @param options The isc_spb_bkp_* parameters options to be used * @return the "backup" service request buffer for the Service Manager. */ protected ServiceRequestBuffer getBackupSRB(FbService service, int options) throws SQLException { ServiceRequestBuffer backupSPB = service.createServiceRequestBuffer(); backupSPB.addArgument(isc_action_svc_backup); backupSPB.addArgument(isc_spb_dbname, getDatabase()); addBackupsToBackupRequestBuffer(service, backupSPB); if (verboseBackup()) { backupSPB.addArgument(isc_spb_verbose); } backupSPB.addArgument(isc_spb_options, options); return backupSPB; }
@Override public byte[] getServiceInfo( ServiceParameterBuffer serviceParameterBuffer, ServiceRequestBuffer serviceRequestBuffer, int maxBufferLength) throws SQLException { try { final byte[] serviceParameterBufferBytes = serviceParameterBuffer == null ? null : serviceParameterBuffer.toBytesWithType(); final byte[] serviceRequestBufferBytes = serviceRequestBuffer == null ? null : serviceRequestBuffer.toBytes(); final ByteBuffer responseBuffer = ByteBuffer.allocateDirect(maxBufferLength); synchronized (getSynchronizationObject()) { clientLibrary.isc_service_query( statusVector, handle, new IntByReference(0), (short) (serviceParameterBufferBytes != null ? serviceParameterBufferBytes.length : 0), serviceParameterBufferBytes, (short) (serviceRequestBufferBytes != null ? serviceRequestBufferBytes.length : 0), serviceRequestBufferBytes, (short) maxBufferLength, responseBuffer); processStatusVector(); } byte[] responseArray = new byte[maxBufferLength]; responseBuffer.get(responseArray); return responseArray; } catch (SQLException e) { exceptionListenerDispatcher.errorOccurred(e); throw e; } }
/** * Creates and returns the "backup" service request buffer for the Service Manager. * * @param service Service handle * @param options The options to be used for the backup operation * @return the "backup" service request buffer for the Service Manager. */ protected ServiceRequestBuffer getRestoreSRB(FbService service, int options) { ServiceRequestBuffer restoreSPB = service.createServiceRequestBuffer(); restoreSPB.addArgument(isc_action_svc_restore); // restore files with sizes except the last one for (Iterator<PathSizeStruct> iter = restorePaths.iterator(); iter.hasNext(); ) { PathSizeStruct pathSize = iter.next(); restoreSPB.addArgument(isc_spb_dbname, pathSize.getPath()); if (iter.hasNext() && pathSize.getSize() != -1) { restoreSPB.addArgument(isc_spb_res_length, pathSize.getSize()); } } addBackupsToRestoreRequestBuffer(service, restoreSPB); if (restoreBufferCount != -1) { restoreSPB.addArgument(isc_spb_res_buffers, restoreBufferCount); } if (restorePageSize != -1) { restoreSPB.addArgument(isc_spb_res_page_size, restorePageSize); } restoreSPB.addArgument( isc_spb_res_access_mode, (byte) (restoreReadOnly ? isc_spb_res_am_readonly : isc_spb_res_am_readwrite)); if (verbose) { restoreSPB.addArgument(isc_spb_verbose); } if ((options & RESTORE_CREATE) != RESTORE_CREATE && (options & RESTORE_REPLACE) != RESTORE_REPLACE) { options |= restoreReplace ? RESTORE_REPLACE : RESTORE_CREATE; } restoreSPB.addArgument(isc_spb_options, options); return restoreSPB; }
/** * Test for service action. * * <p>Replicates the behavior of {@link FBStatisticsManager#getHeaderPage()}. */ @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"), endsWith("*END*\n"))); } finally { defaultDatabaseTearDown(fbManager); } }
@Override public void startServiceAction(ServiceRequestBuffer serviceRequestBuffer) throws SQLException { try { final byte[] serviceRequestBufferBytes = serviceRequestBuffer == null ? null : serviceRequestBuffer.toBytes(); synchronized (getSynchronizationObject()) { clientLibrary.isc_service_start( statusVector, handle, new IntByReference(0), (short) (serviceRequestBufferBytes != null ? serviceRequestBufferBytes.length : 0), serviceRequestBufferBytes); processStatusVector(); } } catch (SQLException e) { exceptionListenerDispatcher.errorOccurred(e); throw e; } }