File: JGraphSQLBusinessModel.java

package info (click to toggle)
libjgraph-java 5.12.4.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 7,884 kB
  • ctags: 7,321
  • sloc: java: 20,619; xml: 135; sh: 51; makefile: 10
file content (78 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * $Id: JGraphSQLBusinessModel.java,v 1.2 2005/08/09 08:40:47 david Exp $
 * 
 * Copyright (c) 2001-2005, Gaudenz Alder
 * 
 * See LICENSE file in distribution for licensing details of this source file
 */
package com.jgraph.example.adapter;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.jgraph.graph.AttributeMap;

/**
 * Allows to set the properties of user objects via the edit method's nested
 * argument. You must add (userObject, Map) pairs to the nested map for each
 * user object's new attributes.
 */
public class JGraphSQLBusinessModel extends JGraphAdapterModel {

	public JGraphSQLBusinessModel() {
		super();
	}

	/**
	 * @param roots
	 * @param attributes
	 */
	public JGraphSQLBusinessModel(List roots, AttributeMap attributes) {
		this(roots, attributes, null);
	}

	/**
	 * @param roots
	 * @param attributes
	 * @param backend
	 */
	public JGraphSQLBusinessModel(List roots, AttributeMap attributes,
			JGraphAdapterBackend backend) {
		super(roots, attributes, backend);
	}

	public void addProperty(Object cell, Object key, Object value) {
		if (key != null && value != null) {
			try {
				Object userObj = getValue(cell);
				if (userObj instanceof JGraphSQLEntity
						&& getBackend() instanceof JGraphSQLBackend) {
					((JGraphSQLBackend) getBackend()).propertyAdded(
							(JGraphSQLEntity) userObj, key, value);
					fireCommit();
				}
			} catch (Exception e) {
				e.printStackTrace();
				try {
					fireRollback();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		}
		super.addProperty(cell, key, value);
	}

	public Collection findVertices(String query, Object parent)
			throws SQLException {
		return ((JGraphSQLBackend) getBackend()).findVertices(this, query,
				parent);
	}

	public Collection findEdges(String query, Object parent, Object source,
			Object target, boolean directed) throws SQLException {
		return ((JGraphSQLBackend) getBackend()).findEdges(this, query, parent,
				source, target, directed);
	}
}