* @throws SQLException
*/
@Override
public void stage4LoadKAM(DBConnection dbConnection, ProtoNetwork p2pn,
String schema) throws DatabaseError, CreateKAMFailure {
JdbcKAMLoaderImpl jkl;
try {
jkl = new JdbcKAMLoaderImpl(dbConnection, schema);
} catch (SQLException e) {
final String msg = "Error creating KAM loader";
throw new DatabaseError(schema, msg, e);
}
if (!jkl.schemaExists()) {
final String fmt = "schema \"%s\" does not exist";
final String msg = format(fmt, jkl.getSchemaName());
throw new CreateKAMFailure(dbConnection, msg);
}
try {
// load type tables
jkl.loadObjectTypes();
} catch (SQLException e) {
final String msg = "Error loading object types";
throw new DatabaseError(schema, msg, e);
}
try {
jkl.loadFunctionTypes();
} catch (SQLException e) {
final String msg = "Error loading function types";
throw new DatabaseError(schema, msg, e);
}
try {
jkl.loadRelationshipTypes();
} catch (SQLException e) {
final String msg = "Error loading relationship types";
throw new DatabaseError(schema, msg, e);
}
try {
jkl.loadAnnotationDefinitionTypes();
} catch (SQLException e) {
final String msg = "Error loading annotation definitions types";
throw new DatabaseError(schema, msg, e);
}
// load documents
List<DocumentHeader> dhs = p2pn.getDocumentTable().getDocumentHeaders();
try {
jkl.loadDocuments(dhs);
} catch (SQLException e) {
final String msg = "Error loading documents";
throw new DatabaseError(schema, msg, e);
}
// load namespaces
NamespaceTable nt = p2pn.getNamespaceTable();
Set<TableNamespace> nsl = nt.getNamespaces();
Map<TableNamespace, Integer> nsi = nt.getNamespaceIndex();
for (TableNamespace ns : nsl) {
try {
jkl.loadNamespace(nsi.get(ns), ns);
} catch (SQLException e) {
final String fmt = "Error loading namespace %s/%s";
final String msg =
format(fmt, ns.getPrefix(), ns.getResourceLocation());
throw new DatabaseError(schema, msg, e);
}
}
// load annotation definitions
try {
jkl.loadAnnotationDefinitions(p2pn.getAnnotationDefinitionTable());
} catch (SQLException e) {
final String msg = "Error loading annotation definitions";
throw new DatabaseError(schema, msg, e);
}
try {
// load annotations
jkl.loadAnnotationValues(p2pn.getAnnotationValueTable());
} catch (SQLException e) {
final String msg = "Error loading annotation values";
throw new DatabaseError(schema, msg, e);
}
try {
// load document to namespace map
jkl.loadDocumentNamespaceMap(nt.getDocumentNamespaces());
} catch (SQLException e) {
final String msg = "Error loading document namespaces";
throw new DatabaseError(schema, msg, e);
}
try {
// load nodes
jkl.loadNodes(p2pn.getNamespaceTable(), p2pn.getParameterTable(),
p2pn.getTermTable(),
p2pn.getTermParameterMapTable(),
p2pn.getProtoNodeTable());
} catch (SQLException e) {
final String msg = "Error loading nodes";
throw new DatabaseError(schema, msg, e);
}
try {
// load edges
jkl.loadEdges(p2pn.getStatementTable(), p2pn.getTermTable(),
p2pn.getProtoNodeTable(), p2pn.getProtoEdgeTable());
} catch (SQLException e) {
final String msg = "Error loading edges";
throw new DatabaseError(schema, msg, e);
}
try {
// associate annotations to statements
jkl.loadStatementAnnotationMap(p2pn
.getStatementAnnotationMapTable());
} catch (SQLException e) {
final String msg = "Error loading statement annotations";
throw new DatabaseError(schema, msg, e);
}
// close loader dao
jkl.terminate();
}