Source Code Cross Referenced for FileSystemImpl.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » file » 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.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.technoetic.xplanner.file;
002:
003:        import com.technoetic.xplanner.db.hibernate.ThreadSession;
004:        import net.sf.hibernate.Hibernate;
005:        import net.sf.hibernate.HibernateException;
006:        import net.sf.hibernate.Session;
007:        import net.sf.hibernate.lob.BlobImpl;
008:
009:        import java.io.InputStream;
010:        import java.util.List;
011:
012:        // Repository for files and directories
013:        public class FileSystemImpl implements  FileSystem {
014:            public Directory getRootDirectory() throws HibernateException {
015:                Session session = ThreadSession.get();
016:                List dirs = session.createQuery(
017:                        "from dir in " + Directory.class
018:                                + " where dir.parent is null").setMaxResults(1)
019:                        .list();
020:                if (dirs.iterator().hasNext()) {
021:                    return (Directory) dirs.iterator().next();
022:                } else {
023:                    Directory root = new Directory();
024:                    root.setName("");
025:                    session.save(root);
026:                    session.flush();
027:                    session.refresh(root);
028:                    return root;
029:                }
030:            }
031:
032:            public Directory getDirectory(Session session, int directoryId)
033:                    throws HibernateException {
034:                return (Directory) session.load(Directory.class, new Integer(
035:                        directoryId));
036:            }
037:
038:            public Directory getDirectory(String path)
039:                    throws HibernateException {
040:                String[] pathElements = path.split("/");
041:                Directory dir = getRootDirectory();
042:                Session session = ThreadSession.get();
043:                for (int i = 1; i < pathElements.length; i++) {
044:                    List subdirectory = session
045:                            .createQuery(
046:                                    "from dir in "
047:                                            + Directory.class
048:                                            + " where dir.parent = :parent and dir.name = :name")
049:                            .setParameter("parent", dir,
050:                                    Hibernate.entity(Directory.class))
051:                            .setParameter("name", pathElements[i])
052:                            .setMaxResults(1).list();
053:                    if (subdirectory.size() > 0) {
054:                        dir = (Directory) subdirectory.get(0);
055:                    } else {
056:                        dir = createDirectory(session, dir, pathElements[i]);
057:                    }
058:                }
059:                return dir;
060:            }
061:
062:            public File createFile(Directory directory, String name,
063:                    String contentType, long size, InputStream data)
064:                    throws HibernateException {
065:                File file = new File();
066:                file.setName(name);
067:                file.setContentType(contentType);
068:                file.setFileSize(size);
069:                if (data != null) {
070:                    file.setData(new BlobImpl(data, (int) size));
071:                }
072:                ThreadSession.get().save(file);
073:                directory.getFiles().add(file);
074:                return file;
075:            }
076:
077:            public File createFile(Session session, int directoryId,
078:                    String name, String contentType, long size, InputStream data)
079:                    throws HibernateException {
080:                Directory directory = (Directory) session.load(Directory.class,
081:                        new Integer(directoryId));
082:                return createFile(directory, name, contentType, size, data);
083:            }
084:
085:            public File getFile(Session session, int fileId)
086:                    throws HibernateException {
087:                return (File) session.load(File.class, new Integer(fileId));
088:            }
089:
090:            public void deleteFile(Session session, int fileId)
091:                    throws HibernateException {
092:                session.delete("from file in " + File.class + " where id = ?",
093:                        new Integer(fileId), Hibernate.INTEGER);
094:            }
095:
096:            public Directory createDirectory(Session session,
097:                    int parentDirectoryId, String name)
098:                    throws HibernateException {
099:                Directory parent = getDirectory(session, parentDirectoryId);
100:                return createDirectory(session, parent, name);
101:            }
102:
103:            public Directory createDirectory(Session session, Directory parent,
104:                    String name) throws HibernateException {
105:                Directory subdirectory = new Directory();
106:                subdirectory.setName(name);
107:                session.save(subdirectory);
108:                session.flush();
109:                session.refresh(subdirectory);
110:                parent.getSubdirectories().add(subdirectory);
111:                return subdirectory;
112:            }
113:
114:            public void deleteDirectory(Session session, int directoryId)
115:                    throws HibernateException {
116:                session.delete("from dir in " + Directory.class
117:                        + " where id = ?", new Integer(directoryId),
118:                        Hibernate.INTEGER);
119:            }
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.