public TimeSeriesOptionsDAO(Connection connection) {
this.connection = connection;
}
public int createGraphOptions(TimeSeriesOptions options) throws DBException {
SetDisplayDAO displayDAO;
PreparedStatement statement;
ResultSet results;
int graphOptionsID;
int setDisplayID;
try {
statement = connection.prepareStatement(CREATE_OPTIONS, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, options.getAggregation().toString());
statement.setString(2, options.getInterpolation().toString());
statement.setInt(3, options.getUseFixedGraphTop() ? 1 : 0);
statement.setDouble(4, options.getFixedGraphTop());
statement.setString(5, Character.toString(options.getFixedGraphTopUnits()));
statement.setInt(6, options.getXAxisAbsoluteTimes() ? 1 : 0);
statement.setInt(7, options.getYAxisFormattedUnits() ? 1 : 0);
statement.setInt(8, options.getBottomLeftLegend() ? 1 : 0);
statement.setInt(9, options.getHorizontalGridLines() ? 1 : 0);
statement.setInt(10, options.getHorizontalMinorLines() ? 1 : 0);
statement.setInt(11, options.getVerticalGridLines() ? 1 : 0);
statement.setInt(12, options.getVerticalMinorLines() ? 1 : 0);
statement.setInt(13, options.getLinesInFront() ? 1 : 0);
statement.setInt(14, options.getStickyWindow() ? 1 : 0);
statement.setInt(15, options.getShowLabels() ? 1 : 0);
statement.setInt(16, options.getShowTrim() ? 1 : 0);
statement.setString(17, options.getSetsPositioning().toString());
statement.executeUpdate();
results = statement.getGeneratedKeys();
results.next();
graphOptionsID = results.getInt(1);
results.close();
statement.close();
logger.debug("Adding new graph options with ID " + graphOptionsID);
displayDAO = DAOFactory.getSetDisplayDAO();
for ( int set = 0 ; set < options.getSetDisplays().size() ; set++ ) {
//setDisplayID = options.getSetDisplay(set).store();
setDisplayID = displayDAO.create(options.getSetDisplay(set));
statement = connection.prepareStatement(CREATE_OPTIONS_SETDISPLAYS);
statement.setInt(1, graphOptionsID);
statement.setInt(2, set);
statement.setInt(3, setDisplayID);
statement.executeUpdate();
statement.close();
}
displayDAO.closeConnection();
return graphOptionsID;
} catch (SQLException e) {
logger.error("Problem creating graph options in database");
throw new DBException("Problem creating graph options in database", e);
}