package com.sun.j2ee.blueprints.petstore.tools.populate;
import java.util.*;
import java.sql.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class CategoryPopulator {
public static final String XML_CATEGORIES = "Categories";
static final String XML_CATEGORY = "Category";
static final String XML_ID = "Category/@id";
private static final String[] PARAMETER_NAMES = { XML_ID };
private String rootTag;
private CategoryDetailsPopulator categoryDetailsPopulator;
private Map sqlStatements;
public CategoryPopulator(Map sqlStatements) throws PopulateException {
this(XML_CATEGORIES, sqlStatements);
return;
}
public CategoryPopulator(String rootTag, Map sqlStatements) throws PopulateException {
this.rootTag = rootTag;
this.sqlStatements = sqlStatements;
categoryDetailsPopulator = new CategoryDetailsPopulator(XML_CATEGORY, sqlStatements);
return;
}
public XMLFilter setup(XMLReader reader, final Connection connection) {
return new XMLDBHandler(categoryDetailsPopulator.setup(reader, connection), rootTag, XML_CATEGORY, true) {
public void update() throws PopulateException {}
public void create() throws PopulateException {
if (connection == null) {
PopulateUtils.printSQLStatement(sqlStatements, PopulateUtils.makeSQLStatementKey(PopulateUtils.INSERT_OPERATION, "category"), PARAMETER_NAMES, this);
} else {
PopulateUtils.executeSQLStatement(connection, sqlStatements, PopulateUtils.makeSQLStatementKey(PopulateUtils.INSERT_OPERATION, "category"), PARAMETER_NAMES, this);
}
}
};
}
public boolean check(Connection connection) throws PopulateException {
return PopulateUtils.executeSQLStatement(connection, sqlStatements, PopulateUtils.makeSQLStatementKey(PopulateUtils.CHECK_OPERATION, "category"), null, null) && categoryDetailsPopulator.check(connection);
}
public void dropTables(Connection connection) throws PopulateException {
try {
categoryDetailsPopulator.dropTables(connection);
} catch (PopulateException exception) {
}
PopulateUtils.executeSQLStatement(connection, sqlStatements, PopulateUtils.makeSQLStatementKey(PopulateUtils.DROP_OPERATION, "category"), null, null);
return;
}
public void createTables(Connection connection) throws PopulateException {
PopulateUtils.executeSQLStatement(connection, sqlStatements, PopulateUtils.makeSQLStatementKey(PopulateUtils.CREATE_OPERATION, "category"), null, null);
categoryDetailsPopulator.createTables(connection);
return;
}
}