Subject Re: [Firebird-Java] Re: Backup with Java
Author Ivens Tadeu Silveira
        Thanks Ryan!
----- Original Message -----
Sent: Thursday, January 08, 2004 9:35 AM
Subject: RE: [Firebird-Java] Re: Backup with Java

Hi

>Another option would be to use ServicesAPI, but they are not supported
>in type 4 driver. Type 2 driver seems to support them, but I do not
>know how to use it. Ryan, any comments?

Services API is implemented at the GDS level for type2 and embedded mode.
(For Ivans Benifit)It is possible too use this GDS level Services API
from your application(I have done so too provide my app with ability to back
up live database when using embedded server) - but it is a low level API and
subject too change(although I cant see any huge changes being necesary).

You will need the latest Jaybird 1.5 and the native code too use this.

I believe that eventually it would be nice too have a high level Services
API
for Jaybird. This would deal with some of the drudgery of using the Services
API.

Anyhow at the end of this post is an example of using this too do a backup.
This code is taken
from the TestServicesAPI test case from the ngds tests package.

The API is very similar too the firbirds C API - and the the doccumentation
for this can be used as a reference.

Hope this helps.

Ryan



// HERE WE SET THINGS UP

final GDS                    gds                    =
GDSFactory.getGDSForType(GDSType.NATIVE_EMBEDDED);
final ServiceParameterBuffer serviceParameterBuffer =
gds.newServiceParameterBuffer();
final isc_svc_handle         handle                 =
gds.get_new_isc_svc_handle();

serviceParameterBuffer.addArgument(ISCConstants.isc_spb_user_name,
"SYSDBA");
serviceParameterBuffer.addArgument(ISCConstants.isc_spb_password,
"masterkey");

gds.isc_service_attach( "service_mgr", handle, serviceParameterBuffer );

// HERE WE KICK OFF A BACKUP

final ServiceRequestBuffer serviceRequestBuffer =
gds.newServiceRequestBuffer(ISCConstants.isc_action_svc_backup);

serviceRequestBuffer.addArgument(ISCConstants.isc_spb_verbose);
serviceRequestBuffer.addArgument(ISCConstants.isc_spb_dbname,
"MyDatabase.fdb");
serviceRequestBuffer.addArgument(ISCConstants.isc_spb_bkp_file,
"MyBackup.gbk");

gds.isc_service_start( handle, serviceRequestBuffer );


// NOW WE MONITOR PROGRESS - THIS CODE WILL WRITE THE OUTPUT TOO output.txt

final ServiceRequestBuffer serviceRequestBuffer =
gds.newServiceRequestBuffer(ISCConstants.isc_info_svc_to_eof);

final byte[] buffer = new byte[1024];

boolean finished = false;

final FileOutputStream file = new FileOutputStream("output.txt");

while(finished==false)
      {
      gds.isc_service_query(handle, null, serviceRequestBuffer, buffer);

      final ByteArrayInputStream byteArrayInputStream  = new
ByteArrayInputStream(buffer);

      final byte firstByte = (byte) byteArrayInputStream.read();

      int numberOfBytes = (short)((byteArrayInputStream.read() << 0) +
(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());
            }

      file.flush();
      }

// NOW WE CAN DETATCH

gds.isc_service_detach(handle);









Yahoo! Groups Links