Accessing Custom Data Source (Objects) Problem
Some businesses require reports or dashboards to be created from a custom data store. This data store can be presented as an object but cannot be easily integrated with other dashboard or reporting tools.
The Style Intelligence Solution
Style Intelligence goes beyond reporting against traditional data sources such as relational databases, XML, and flat files by providing a unique object data source interface. More and more businesses are creating object data stores in order to provide a unified data interface and persistent data store for all applications across the entire enterprise. The most common approach is to retrieve data from a relational or hierarchal data source such as an RDBMS or XML file, and then transform it into objects. The problem is accessing these objects. Since Style Intelligence is a 100% Java application, it requires a Java interface to access custom data sources. This Java object layer can retrieve its data from any location so Java is only required at the top level, not at every level.
Let’s look at an example of utilizing an object data layer to produce reports. A particular company needs to retrieve customer information from an object that in turn, retrieves its data from a relational data base when the system is initialized. This information is stored in an Object called Customer that has standard “get” and “set” functions for members called: customerId, companyName, address, city, state, zip, and reseller. The Customer object is accessed through two other classes that must be created.
The “Loader” retrieves the data, populates the objects, and provides the functions to retrieve data into Collections. The “Data Helper” provides information on the data types returned. Below is a code example of the Loader and DataHelper created for the Customer data Object.
---- Begin Loader.java ---
public class Loader {
public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String URL = "jdbc:odbc:Orders";
private Vector loadCustomers(String whereClause)
throws SQLException, ClassNotFoundException {
Vector result = new Vector();
Customer cust = null;
Class.forName(DRIVER);
Connection conn = DriverManager.getConnection(URL, null, null);
Statement st = conn.createStatement();
ResultSet rs = null;
if (whereClause == null)
{rs = st.executeQuery(Customer.SQL);
} else {
rs = st.executeQuery(Customer.SQL+whereClause);
}
while (rs.next()) {
cust = new Customer();
cust.setCustomerId(rs.getInt("customer_id"));
cust.setCompanyName(rs.getString("company_name"));
cust.setAddress(rs.getString("address"));
cust.setCity(rs.getString("city"));
cust.setState(rs.getString("state"));
cust.setZip(rs.getString("zip"));
cust.setReseller((rs.getInt("reseller") == -1));
result.add(cust);
}
rs.close();
st.close();
conn.close();
return result;
}
public Vector getAllCustomers() {
Vector result = null;
try {
result = loadCustomers(null);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException cne) {
cne.printStackTrace();
}
return result;
}
public Vector getCustomerById(int customerId) {
Vector result = null;
try {
result = loadCustomers(" WHERE customer_id="+customerId);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException cne) {
cne.printStackTrace();
}
return result;
}
public Vector getCustomerByState(String state) {
Vector result = null;
try {
result = loadCustomers(" WHERE state='"+state+"'");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException cne) {
.printStackTrace();
}
return result;
}
}
---- End Loader.java ----
In this example, the Loader retrieves data from a relational database using a single query. This example could be expanded to include many data base tables or other data sources if needed. The functions getAllCustomers(),getCustomerById(), and getCustomerByState(String state) are used to retrieve data from the Query Builder into the report. Once can see that the interface is so generic that any data set can be retrieved from any location
.