Source Code Cross Referenced for HistorySupport.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » history » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » XPlanner 0.7b7 » com.technoetic.xplanner.history 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.technoetic.xplanner.history;
002:
003:        import java.util.Date;
004:        import java.util.List;
005:
006:        import net.sf.hibernate.Hibernate;
007:        import net.sf.hibernate.HibernateException;
008:        import net.sf.hibernate.Session;
009:        import org.apache.commons.beanutils.PropertyUtils;
010:        import org.apache.commons.lang.StringUtils;
011:        import org.apache.log4j.Logger;
012:
013:        import com.technoetic.xplanner.db.hibernate.ThreadSession;
014:        import com.technoetic.xplanner.domain.DomainMetaDataRepository;
015:        import com.technoetic.xplanner.domain.DomainObject;
016:
017:        public class HistorySupport {
018:            private static Logger log = Logger.getLogger(HistorySupport.class);
019:            private static long FIFTEEN_MINUTES = 3600000 * 15;
020:
021:            //DEBT should be spring loaded (metadatarepository should be passed in and we should not have private methods
022:            private static void saveEvent(Session session, Class objectClass,
023:                    int containerOid, int oid, String action,
024:                    String description, int personId, Date when) {
025:                try {
026:                    HistoricalEvent historicalEvent = new HistoricalEvent(
027:                            containerOid, oid,
028:                            DomainMetaDataRepository.getInstance()
029:                                    .classToTypeName(objectClass), action,
030:                            description, personId, when);
031:                    if (!isEventThrottled(session, historicalEvent)) {
032:                        session.save(historicalEvent);
033:                    }
034:                    if (action.equals(HistoricalEvent.DELETED)) {
035:                        // Set name in event descriptions for deleted objects
036:                        List events = getEvents(oid);
037:                        for (int i = 0; i < events.size(); i++) {
038:                            HistoricalEvent event = (HistoricalEvent) events
039:                                    .get(i);
040:                            if (StringUtils.isEmpty(event.getDescription())) {
041:                                event.setDescription(description);
042:                            }
043:                        }
044:                    }
045:                } catch (HibernateException e) {
046:                    log.error("history error", e);
047:                }
048:            }
049:
050:            private static boolean isEventThrottled(Session session,
051:                    HistoricalEvent event) throws HibernateException {
052:                if (event.getAction().equals(HistoricalEvent.UPDATED)) {
053:                    HistoricalEvent previousEvent = (HistoricalEvent) session
054:                            .createQuery(
055:                                    "from event in "
056:                                            + HistoricalEvent.class
057:                                            + " where event.targetObjectId = :oid and event.action = :action order by event.when desc")
058:                            .setInteger("oid", event.getTargetObjectId())
059:                            .setString("action", HistoricalEvent.UPDATED)
060:                            .setMaxResults(1).uniqueResult();
061:                    return previousEvent != null
062:                            && (event.getWhen().getTime() - previousEvent
063:                                    .getWhen().getTime()) < FIFTEEN_MINUTES;
064:                } else {
065:                    return false;
066:                }
067:            }
068:
069:            public static void saveEvent(Session session, DomainObject object,
070:                    String action, String description, int personId, Date when) {
071:                try {
072:                    Integer id = (Integer) PropertyUtils.getProperty(object,
073:                            "id");
074:                    saveEvent(session, object.getClass(),
075:                            DomainMetaDataRepository.getInstance().getParentId(
076:                                    object), id.intValue(), action,
077:                            description, personId, when);
078:                } catch (Exception e) {
079:                    log.error("history error", e);
080:                }
081:            }
082:
083:            public static List getEvents(int oid) throws HibernateException {
084:                //TODO externalize these queries into mapping file
085:                return ThreadSession
086:                        .get()
087:                        .find(
088:                                "from event in "
089:                                        + HistoricalEvent.class
090:                                        + " where event.targetObjectId = ? order by event.when desc",
091:                                new Integer(oid), Hibernate.INTEGER);
092:            }
093:
094:            public static List getContainerEvents(int oid) throws Exception {
095:                return ThreadSession.get().find(
096:                        "from event in " + HistoricalEvent.class
097:                                + " where event.containerId = ? "
098:                                + " and event.action in ('"
099:                                + HistoricalEvent.CREATED + "','"
100:                                + HistoricalEvent.DELETED
101:                                + "') order by event.when desc",
102:                        new Integer(oid), Hibernate.INTEGER);
103:            }
104:
105:            public static Object getHistoricalObject(HistoricalEvent event)
106:                    throws HibernateException {
107:                if (event.getAction().equals(HistoricalEvent.DELETED)) {
108:                    return null;
109:                }
110:                return DomainMetaDataRepository.getInstance().getObject(
111:                        event.getObjectType(), event.getTargetObjectId());
112:            }
113:
114:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.