use of org.firebirdsql.gds.ServiceParameterBuffer in project jaybird by FirebirdSQL.
the class JnaService method attach.
@Override
public void attach() throws SQLException {
try {
if (isAttached()) {
throw new SQLException("Already attached to a service");
}
final ServiceParameterBuffer spb = PARAMETER_CONVERTER.toServiceParameterBuffer(connection);
final byte[] serviceName = getEncoding().encodeToCharset(connection.getAttachUrl());
final byte[] spbArray = spb.toBytesWithType();
synchronized (getSynchronizationObject()) {
try {
clientLibrary.isc_service_attach(statusVector, (short) serviceName.length, serviceName, handle, (short) spbArray.length, spbArray);
processStatusVector();
} catch (SQLException ex) {
safelyDetach();
throw ex;
} catch (Exception ex) {
safelyDetach();
// TODO Replace with specific error (eg native client error)
throw new FbExceptionBuilder().exception(ISCConstants.isc_network_error).messageParameter(connection.getAttachUrl()).cause(ex).toSQLException();
}
setAttached();
afterAttachActions();
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.ServiceParameterBuffer in project jaybird by FirebirdSQL.
the class V10Service method attach.
@Override
public void attach() throws SQLException {
try {
checkConnected();
if (isAttached()) {
throw new SQLException("Already attached to a service");
}
final ServiceParameterBuffer spb = protocolDescriptor.createAttachServiceParameterBuffer(connection);
synchronized (getSynchronizationObject()) {
try {
try {
sendAttachToBuffer(spb);
getXdrOut().flush();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
}
try {
authReceiveResponse(null);
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
}
} catch (SQLException e) {
safelyDetach();
throw e;
}
setAttached();
afterAttachActions();
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.ServiceParameterBuffer in project jaybird by FirebirdSQL.
the class FBStreamingBackupManager method executeServiceRestoreOperation.
private void executeServiceRestoreOperation(FbService service, ServiceRequestBuffer srb) throws SQLException {
try {
service.startServiceAction(srb);
OutputStream currentLogger = getLogger();
ServiceRequestBuffer infoSRB = service.createServiceRequestBuffer();
ServiceParameterBuffer infoSPB = null;
infoSRB.addArgument(isc_info_svc_stdin);
infoSRB.addArgument(isc_info_svc_line);
if (this.verbose && currentLogger == null)
throw new SQLException("Verbose mode was requested but there is no logger provided.");
int bufferSize = BUFFER_SIZE;
byte[] stdinBuffer = new byte[MAX_RESTORE_CHUNK];
byte[] newLine = System.lineSeparator().getBytes();
boolean processing = true;
boolean sending = true;
byte[] buffer;
while (processing || infoSPB != null) {
buffer = service.getServiceInfo(infoSPB, infoSRB, bufferSize);
if (infoSPB != null && !sending) {
infoSRB = service.createServiceRequestBuffer();
infoSRB.addArgument(isc_info_svc_line);
}
infoSPB = null;
for (int codePos = 0; codePos < buffer.length && buffer[codePos] != isc_info_end; ) {
switch(buffer[codePos]) {
case isc_info_svc_stdin:
int requestedBytes = Math.min(iscVaxInteger(buffer, ++codePos, 4), stdinBuffer.length);
codePos += 4;
if (requestedBytes > 0) {
int actuallyReadBytes = restoreInputStream.read(stdinBuffer, 0, requestedBytes);
if (actuallyReadBytes > 0) {
infoSPB = service.createServiceParameterBuffer();
if (stdinBuffer.length == actuallyReadBytes)
infoSPB.addArgument(isc_info_svc_line, stdinBuffer);
else
infoSPB.addArgument(isc_info_svc_line, Arrays.copyOfRange(stdinBuffer, 0, actuallyReadBytes));
}
restoreInputStream.mark(2);
if (restoreInputStream.read() < 0)
sending = false;
else
restoreInputStream.reset();
}
break;
case isc_info_truncated:
bufferSize *= 2;
++codePos;
break;
case isc_info_svc_line:
int bytesToLog = readOutput(buffer, codePos, currentLogger);
codePos += 3;
switch(bytesToLog) {
case DATA_NOT_READY:
++codePos;
break;
case END_OF_STREAM:
processing = false;
break;
default:
codePos += bytesToLog;
if (currentLogger != null)
currentLogger.write(newLine);
}
break;
case isc_info_end:
break;
default:
throw new SQLException("Unexpected response from service.");
}
}
}
} catch (IOException ioe) {
throw new SQLException(ioe);
}
}
use of org.firebirdsql.gds.ServiceParameterBuffer in project jaybird by FirebirdSQL.
the class V12ParameterConverter method createServiceParameterBuffer.
protected ServiceParameterBuffer createServiceParameterBuffer(WireServiceConnection connection) {
final Encoding stringEncoding = connection.getEncodingFactory().getEncodingForFirebirdName("UTF8");
ServiceParameterBuffer spb = new ServiceParameterBufferImp(ServiceParameterBufferImp.SpbMetaData.SPB_VERSION_2_ATTACH, stringEncoding);
spb.addArgument(SpbItems.isc_spb_utf8_filename);
return spb;
}
Aggregations