01: /*
02: * $Id: JGraphSQLBusinessModel.java,v 1.2 2005/08/09 08:40:47 david Exp $
03: *
04: * Copyright (c) 2001-2005, Gaudenz Alder
05: *
06: * See LICENSE file in distribution for licensing details of this source file
07: */
08: package com.jgraph.example.adapter;
09:
10: import java.sql.SQLException;
11: import java.util.Collection;
12: import java.util.List;
13:
14: import org.jgraph.graph.AttributeMap;
15:
16: /**
17: * Allows to set the properties of user objects via the edit method's nested
18: * argument. You must add (userObject, Map) pairs to the nested map for each
19: * user object's new attributes.
20: */
21: public class JGraphSQLBusinessModel extends JGraphAdapterModel {
22:
23: public JGraphSQLBusinessModel() {
24: super ();
25: }
26:
27: /**
28: * @param roots
29: * @param attributes
30: */
31: public JGraphSQLBusinessModel(List roots, AttributeMap attributes) {
32: this (roots, attributes, null);
33: }
34:
35: /**
36: * @param roots
37: * @param attributes
38: * @param backend
39: */
40: public JGraphSQLBusinessModel(List roots, AttributeMap attributes,
41: JGraphAdapterBackend backend) {
42: super (roots, attributes, backend);
43: }
44:
45: public void addProperty(Object cell, Object key, Object value) {
46: if (key != null && value != null) {
47: try {
48: Object userObj = getValue(cell);
49: if (userObj instanceof JGraphSQLEntity
50: && getBackend() instanceof JGraphSQLBackend) {
51: ((JGraphSQLBackend) getBackend()).propertyAdded(
52: (JGraphSQLEntity) userObj, key, value);
53: fireCommit();
54: }
55: } catch (Exception e) {
56: e.printStackTrace();
57: try {
58: fireRollback();
59: } catch (Exception e1) {
60: e1.printStackTrace();
61: }
62: }
63: }
64: super .addProperty(cell, key, value);
65: }
66:
67: public Collection findVertices(String query, Object parent)
68: throws SQLException {
69: return ((JGraphSQLBackend) getBackend()).findVertices(this ,
70: query, parent);
71: }
72:
73: public Collection findEdges(String query, Object parent,
74: Object source, Object target, boolean directed)
75: throws SQLException {
76: return ((JGraphSQLBackend) getBackend()).findEdges(this, query,
77: parent, source, target, directed);
78: }
79: }
|