01: package org.contineo.core.dbinit;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Collections;
06: import java.util.Comparator;
07: import java.util.List;
08:
09: import org.contineo.util.PluginRegistry;
10: import org.contineo.util.dbinit.DBInit;
11: import org.java.plugin.registry.Extension;
12:
13: /**
14: * Database initialization manager
15: *
16: * @author Marco Meschieri
17: * @version $Id:$
18: * @since 3.0
19: */
20: public class PluginDbInit extends DBInit {
21:
22: /**
23: * Intitialises the database using sql92.sql from the core plugin and
24: * appending all other extensions connected to the 'DbInit' extension point.
25: */
26: public void init() {
27: // Acquire the 'DbInit' extensions of the core plugin
28: PluginRegistry registry = PluginRegistry.getInstance();
29: Collection<Extension> exts = registry.getExtensions(
30: "contineo-core", "DbInit");
31:
32: // Sort the extensions according to ascending position
33: List<Extension> sortedExts = new ArrayList<Extension>();
34: for (Extension extension : exts) {
35: sortedExts.add(extension);
36: }
37: Collections.sort(sortedExts, new Comparator<Extension>() {
38: public int compare(Extension e1, Extension e2) {
39: int position1 = e1.getParameter("position")
40: .valueAsNumber().intValue();
41: int position2 = e2.getParameter("position")
42: .valueAsNumber().intValue();
43: if (position1 < position2)
44: return -1;
45: else if (position1 > position2)
46: return 1;
47: else
48: return 0;
49: }
50: });
51:
52: // Acquire the ordered list of sql files
53: getSqlList().clear();
54: getSqlList().add("org/contineo/core/contineo-core.sql");
55: for (Extension ext : sortedExts) {
56: getSqlList().add(
57: ext.getParameter("sqlFile").valueAsString());
58: }
59: execute();
60: }
61: }
|