Caching Metadata
For each query you wish to perform, the RSSBus JDBC Driver for Salesforce V3 must rely on the metadata or schemas that describe the tables queried. If the metadata is not present, the RSSBus JDBC Driver for Salesforce V3 establishes a separate connection with the live data source to retrieve the metadata before querying the data. This process can be slow and expensive, especially if multiple tables need to be queried.
The solution is to cache table metadata. Instead of retrieving the metadata fresh for each table per each query, caching the metadata locally stores the metadata that describes the table. Thus, the metadata from the live data source need be fetched only once. To enable this feature, simply set a cache location in your connection string and RSSBus JDBC Driver for Salesforce V3 handles the rest automatically. The RSSBus JDBC Driver for Salesforce V3 will cache the metadata the first time it is needed and use it onwards.
Do note that altering the schema on the live data source -- say, in the event a column is added or dropped -- is not reflected automatically in the local metadata cache. So you would want to delete the cache file if you expect your data definitions to have changed.
The following code can be used to build the metadata cache. This is especially useful in using the Object-Relational Mapping Framework (e.g. Hibernate).
Connection conn = DriverManager.getConnection("jdbc:rssbus:Cache Location=C:\\rssbus.salesforce.db;AutoCache=True;User=myUser;Password=myPassword;Access Token=myToken;");
DatabaseMetaData table_meta = conn.getMetaData();
ResultSet set=table_meta.getTables(null, null, "%", null);
while (set.next()) {
String tableName = set.getString("TABLE_NAME");
System.out.println("Cached metadata for table: "+tableName);
ResultSet rs = table_meta.getColumns(null, null, tableName, null);
while(rs.next()){
}
}
System.out.println();
System.out.println("All tables cached.");
conn.close();