01: package org.osbl.persistence.hibernate;
02:
03: import org.osbl.persistence.DeleteCommand;
04: import org.osbl.persistence.model.General;
05: import org.osbl.persistence.model.Concrete;
06: import org.osbl.ServiceProvider;
07: import org.osbl.plugin.*;
08: import org.hibernate.*;
09:
10: import java.util.*;
11:
12: public class HibernateDeleteGeneralCommand<T> extends DeleteCommand<T>
13: implements HibernateCommand {
14: SessionFactory sessionFactory;
15:
16: public void setSessionFactory(SessionFactory sessionFactory) {
17: this .sessionFactory = sessionFactory;
18: }
19:
20: public void execute() {
21: Session session = sessionFactory.getCurrentSession();
22:
23: General<?> general = (General<?>) object;
24:
25: PluginManager pluginManager = (PluginManager) ServiceProvider
26: .getInstance().getService("PluginManager");
27: ExtensionPoint extensionPoint = new ExtensionPoint(Hibernate
28: .getClass(general).getName()
29: + ".concrete", Concrete.class);
30: List<Extension> list = pluginManager
31: .getExtensions(extensionPoint);
32: List<String> qualified = qualified(general);
33:
34: for (Extension extension : list) {
35: Class concreteType = extension.getImplementation();
36: if (qualified.contains(concreteType.getSimpleName())) {
37: Object concrete = session.load(concreteType.getName(),
38: general.getId());
39: session.delete(concrete);
40: }
41: }
42:
43: session.delete(object);
44: }
45:
46: private List<String> qualified(General general) {
47: String qualifications = general.getQualifications();
48: if (qualifications == null)
49: qualifications = "";
50:
51: String[] strings = qualifications.split("\\|");
52: List<String> list = new ArrayList<String>(strings.length);
53: for (String string : strings) {
54: list.add(string);
55: }
56: if (list.size() > 1)
57: list.remove(0);
58:
59: return list;
60: }
61: }
|