Subject | Services API |
---|---|
Author | Ruslan Cheremin |
Post date | 2009-03-10T10:41:25Z |
Hello, all!
I have some questions about using FB Services API from JBird. I'm new in using services API at all, I've just know it's easy way to gather DB stats. As I can understand, it should be done via FBServiceManager subclassing. After digging sources and experimenting it seems like I've found the way. Here is the example of getting PAGE_SIZE from db
public class FBServiceManagerEx extends org.firebirdsql.management.FBServiceManager {
//.... constructors skipped ...
public int queryPageSize() throws SQLException {
final GDS gds = getGds();
final GDSType type = ( ( AbstractGDS )gds ).getType();
try {
final IscDbHandle db = gds.createIscDbHandle();
final DatabaseParameterBuffer dpb = gds.createDatabaseParameterBuffer();
dpb.addArgument( DatabaseParameterBuffer.USER_NAME, getUser() );
dpb.addArgument( DatabaseParameterBuffer.PASSWORD, getPassword() );
final String dbPath = GDSFactory.getDatabasePath(
type,
getHost(), getPort(), getDatabase()
);
gds.iscAttachDatabase( dbPath, db, dpb );
try {
final byte[] result = gds.iscDatabaseInfo(
db,
new byte[]{ ISCConstants.isc_info_page_size },
1024
);
final int lengthLen = 2;
int i = 0;
while ( result[i] != ISCConstants.isc_info_end ) {
switch ( result[i++] ) {
case ISCConstants.isc_info_page_size:
final int valueLen = gds.iscVaxInteger( result, i, lengthLen );
i += lengthLen;
final int res = gds.iscVaxInteger( result, i, valueLen );
return res;
default:
throw new FBSQLException( "Shit happens" );
}
}
throw new FBSQLException( "Shit happens" );
} finally {
gds.iscDetachDatabase( db );
}
} catch ( GDSException ex ) {
throw new FBSQLException( ex );
}
}
So, first of my question is: is it "the right (expected) way" to call services api from JBird, or a kind of Frankenstein creature built up from pieces of code? What is the right way, and where can I find Dao of calling services API from JBird? For example, do I really need to finish every query buffer with ISCConstants.isc_info_end -- here I ommit it, but somewhere in sources I've seen it was used (I mean format buffer like new byte[]{ISCConstants.isc_info_page_size, ISCConstants.isc_info_end} )
Second question is about quering DB transaction info via services API. I modify query buffer in code above:
//..
final byte[] queryItems = {
ISCConstants.isc_info_oldest_transaction,
ISCConstants.isc_info_oldest_active,
ISCConstants.isc_info_oldest_snapshot,
ISCConstants.isc_info_next_transaction,
ISCConstants.isc_info_active_transactions,
ISCConstants.isc_info_end
};
final byte[] result = gds.iscDatabaseInfo(
db,
queryItems,
1024
);
//....same processing as above...
And I've really got info about oldest_* and next_* transactions. But
1. Server tell me nothing about active_*! It's simply nothing about it in responce buffer!
2. It seems like quering transaction info itself doing in transaction, and not one transaction -- I've noticed transactions counters incremented by 3 every time I've run last script. Is it any way to "just check, don't touch" this kind of statistics? And if no -- is it, at least, any way to gather all stats I need in one transaction?
Thanks in advance!
Ruslan
I have some questions about using FB Services API from JBird. I'm new in using services API at all, I've just know it's easy way to gather DB stats. As I can understand, it should be done via FBServiceManager subclassing. After digging sources and experimenting it seems like I've found the way. Here is the example of getting PAGE_SIZE from db
public class FBServiceManagerEx extends org.firebirdsql.management.FBServiceManager {
//.... constructors skipped ...
public int queryPageSize() throws SQLException {
final GDS gds = getGds();
final GDSType type = ( ( AbstractGDS )gds ).getType();
try {
final IscDbHandle db = gds.createIscDbHandle();
final DatabaseParameterBuffer dpb = gds.createDatabaseParameterBuffer();
dpb.addArgument( DatabaseParameterBuffer.USER_NAME, getUser() );
dpb.addArgument( DatabaseParameterBuffer.PASSWORD, getPassword() );
final String dbPath = GDSFactory.getDatabasePath(
type,
getHost(), getPort(), getDatabase()
);
gds.iscAttachDatabase( dbPath, db, dpb );
try {
final byte[] result = gds.iscDatabaseInfo(
db,
new byte[]{ ISCConstants.isc_info_page_size },
1024
);
final int lengthLen = 2;
int i = 0;
while ( result[i] != ISCConstants.isc_info_end ) {
switch ( result[i++] ) {
case ISCConstants.isc_info_page_size:
final int valueLen = gds.iscVaxInteger( result, i, lengthLen );
i += lengthLen;
final int res = gds.iscVaxInteger( result, i, valueLen );
return res;
default:
throw new FBSQLException( "Shit happens" );
}
}
throw new FBSQLException( "Shit happens" );
} finally {
gds.iscDetachDatabase( db );
}
} catch ( GDSException ex ) {
throw new FBSQLException( ex );
}
}
So, first of my question is: is it "the right (expected) way" to call services api from JBird, or a kind of Frankenstein creature built up from pieces of code? What is the right way, and where can I find Dao of calling services API from JBird? For example, do I really need to finish every query buffer with ISCConstants.isc_info_end -- here I ommit it, but somewhere in sources I've seen it was used (I mean format buffer like new byte[]{ISCConstants.isc_info_page_size, ISCConstants.isc_info_end} )
Second question is about quering DB transaction info via services API. I modify query buffer in code above:
//..
final byte[] queryItems = {
ISCConstants.isc_info_oldest_transaction,
ISCConstants.isc_info_oldest_active,
ISCConstants.isc_info_oldest_snapshot,
ISCConstants.isc_info_next_transaction,
ISCConstants.isc_info_active_transactions,
ISCConstants.isc_info_end
};
final byte[] result = gds.iscDatabaseInfo(
db,
queryItems,
1024
);
//....same processing as above...
And I've really got info about oldest_* and next_* transactions. But
1. Server tell me nothing about active_*! It's simply nothing about it in responce buffer!
2. It seems like quering transaction info itself doing in transaction, and not one transaction -- I've noticed transactions counters incremented by 3 every time I've run last script. Is it any way to "just check, don't touch" this kind of statistics? And if no -- is it, at least, any way to gather all stats I need in one transaction?
Thanks in advance!
Ruslan