Source Code Cross Referenced for BugAttachment.java in  » Groupware » hipergate » com » knowgate » projtrack » 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 » Groupware » hipergate » com.knowgate.projtrack 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          Copyright (C) 2003-2006  Know Gate S.L. All rights reserved.
003:                                   C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005:          Redistribution and use in source and binary forms, with or without
006:          modification, are permitted provided that the following conditions
007:          are met:
008:
009:          1. Redistributions of source code must retain the above copyright
010:             notice, this list of conditions and the following disclaimer.
011:
012:          2. The end-user documentation included with the redistribution,
013:             if any, must include the following acknowledgment:
014:             "This product includes software parts from hipergate
015:             (http://www.hipergate.org/)."
016:             Alternately, this acknowledgment may appear in the software itself,
017:             if and wherever such third-party acknowledgments normally appear.
018:
019:          3. The name hipergate must not be used to endorse or promote products
020:             derived from this software without prior written permission.
021:             Products derived from this software may not be called hipergate,
022:             nor may hipergate appear in their name, without prior written
023:             permission.
024:
025:          This library is distributed in the hope that it will be useful,
026:          but WITHOUT ANY WARRANTY; without even the implied warranty of
027:          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029:          You should have received a copy of hipergate License with this code;
030:          if not, visit http://www.hipergate.org or mail to info@hipergate.org
031:         */
032:
033:        package com.knowgate.projtrack;
034:
035:        import java.io.File;
036:        import java.io.FileInputStream;
037:        import java.io.FileNotFoundException;
038:        import java.io.IOException;
039:
040:        import java.sql.SQLException;
041:        import java.sql.PreparedStatement;
042:        import java.sql.ResultSet;
043:
044:        import com.knowgate.jdc.JDCConnection;
045:        import com.knowgate.debug.DebugFile;
046:        import com.knowgate.dataobjs.DB;
047:
048:        /**
049:         * <p>Bug Attachment</p>
050:         * This class represents objects stored as blobs at k_bugs_attach table
051:         * @author Sergio Montoro Ten
052:         * @version 3.0
053:         */
054:        public class BugAttachment {
055:
056:            private int iSize;
057:            private String sFileName;
058:            private String sBugId;
059:
060:            // ---------------------------------------------------------------------------
061:
062:            public BugAttachment() {
063:                iSize = 0;
064:                sFileName = sBugId = null;
065:            }
066:
067:            // ---------------------------------------------------------------------------
068:
069:            public BugAttachment(String sIdBug, String sNameFile, int iSizeFile) {
070:                iSize = iSizeFile;
071:                sBugId = sIdBug;
072:                sFileName = sNameFile;
073:            }
074:
075:            // ---------------------------------------------------------------------------
076:
077:            public int size() {
078:                return iSize;
079:            }
080:
081:            // ---------------------------------------------------------------------------
082:
083:            public String fileName() {
084:                return sFileName;
085:            }
086:
087:            // ---------------------------------------------------------------------------
088:
089:            public String bugId() {
090:                return sBugId;
091:            }
092:
093:            // ---------------------------------------------------------------------------
094:
095:            public byte[] getBytes(JDCConnection oConn) throws SQLException,
096:                    IOException {
097:                byte[] aBytes;
098:                PreparedStatement oStmt = oConn.prepareStatement("SELECT "
099:                        + DB.len_file + "," + DB.bin_file + " FROM "
100:                        + DB.k_bugs_attach + " WHERE " + DB.gu_bug + "=? AND "
101:                        + DB.tx_file + "=?", ResultSet.TYPE_FORWARD_ONLY,
102:                        ResultSet.CONCUR_READ_ONLY);
103:                oStmt.setString(1, sBugId);
104:                oStmt.setString(2, sFileName);
105:                ResultSet oRSet = oStmt.executeQuery();
106:                if (oRSet.next()) {
107:                    aBytes = new byte[oRSet.getInt(1)];
108:                    oRSet.getBinaryStream(2).read(aBytes);
109:                } else {
110:                    aBytes = null;
111:                }
112:                oRSet.close();
113:                oStmt.close();
114:                return aBytes;
115:            } // getBytes
116:
117:            // ---------------------------------------------------------------------------
118:
119:            /**
120:             * Remove attachment from k_bugs_attach table
121:             * @param oConn JDCConnection
122:             * @throws SQLException
123:             */
124:            public void delete(JDCConnection oConn) throws SQLException {
125:                BugAttachment.delete(oConn, sBugId, sFileName);
126:            }
127:
128:            // ---------------------------------------------------------------------------
129:
130:            /**
131:             * Remove attachment from k_bugs_attach table
132:             * @param oConn JDCConnection
133:             * @param sBugId String
134:             * @param sFileName String
135:             * @throws SQLException
136:             */
137:            public static void delete(JDCConnection oConn, String sBugId,
138:                    String sFileName) throws SQLException {
139:
140:                if (DebugFile.trace) {
141:                    DebugFile.writeln("Begin Bug.delete([JDCConnection],"
142:                            + sBugId + "," + sFileName + ")");
143:                    DebugFile.incIdent();
144:                }
145:                PreparedStatement oDlte = oConn.prepareStatement("DELETE FROM "
146:                        + DB.k_bugs_attach + " WHERE " + DB.gu_bug + "=? AND "
147:                        + DB.tx_file + "=?");
148:                oDlte.setString(1, sBugId);
149:                oDlte.setString(2, sFileName);
150:                oDlte.executeUpdate();
151:                oDlte.close();
152:
153:                if (DebugFile.trace) {
154:                    DebugFile.decIdent();
155:                    DebugFile.writeln("End Bug.delete()");
156:                }
157:            } // delete
158:
159:            // ---------------------------------------------------------------------------
160:
161:            /**
162:             * Insert attachment into k_bugs_attach table
163:             * @param oConn JDCConnection
164:             * @param sBugId String GUID of Bug to which attachment belongs
165:             * @param sFilePath String Full path to local file
166:             * @throws SQLException
167:             * @throws FileNotFoundException
168:             * @throws IOException
169:             * @throws NullPointerException
170:             */
171:            public static void createFromFile(JDCConnection oConn,
172:                    String sBugId, String sFilePath) throws SQLException,
173:                    FileNotFoundException, IOException, NullPointerException {
174:
175:                if (DebugFile.trace) {
176:                    DebugFile
177:                            .writeln("Begin BugAttachment.createFromFile([JDCConnection],"
178:                                    + sBugId + "," + sFilePath + ")");
179:                    DebugFile.incIdent();
180:                }
181:
182:                File oFile = new File(sFilePath);
183:
184:                if (oFile == null) {
185:                    if (DebugFile.trace)
186:                        DebugFile.decIdent();
187:                    throw new FileNotFoundException(sFilePath);
188:                }
189:                if (!oFile.exists()) {
190:                    if (DebugFile.trace)
191:                        DebugFile.decIdent();
192:                    throw new FileNotFoundException(sFilePath);
193:                }
194:
195:                PreparedStatement oStmt = oConn.prepareStatement("INSERT INTO "
196:                        + DB.k_bugs_attach + "(" + DB.gu_bug + "," + DB.tx_file
197:                        + "," + DB.len_file + "," + DB.bin_file
198:                        + ") VALUES (?,?,?,?)");
199:
200:                int iFileLen = new Long(oFile.length()).intValue();
201:
202:                FileInputStream oFileStream = new FileInputStream(oFile);
203:                oStmt.setString(1, sBugId);
204:                oStmt.setString(2, oFile.getName());
205:                oStmt.setInt(3, iFileLen);
206:                oStmt.setBinaryStream(4, oFileStream, iFileLen);
207:                oStmt.executeUpdate();
208:                oStmt.close();
209:                oFileStream.close();
210:                oFileStream = null;
211:
212:                if (DebugFile.trace) {
213:                    DebugFile.decIdent();
214:                    DebugFile.writeln("End BugAttachment.createFromFile()");
215:                }
216:            } // createFromFile
217:
218:            // **********************************************************
219:            // Constantes Publicas
220:
221:            public static final short ClassId = 84;
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.