KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > db > mysql3 > CmsVfsDriver


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/mysql3/CmsVfsDriver.java,v $
3  * Date : $Date: 2005/06/24 16:27:52 $
4  * Version: $Revision: 1.1 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.db.mysql3;
33
34 import org.opencms.db.CmsDbContext;
35 import org.opencms.db.CmsDbSqlException;
36 import org.opencms.db.generic.Messages;
37 import org.opencms.file.CmsDataAccessException;
38 import org.opencms.file.CmsResource;
39 import org.opencms.util.CmsUUID;
40
41 import java.sql.Connection JavaDoc;
42 import java.sql.PreparedStatement JavaDoc;
43 import java.sql.ResultSet JavaDoc;
44 import java.sql.SQLException JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.List JavaDoc;
47
48 /**
49  * MySQL3 implementation of the VFS driver methods.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.1 $
54  * @since 6.0.0
55  */

56 public class CmsVfsDriver extends org.opencms.db.mysql.CmsVfsDriver {
57
58     /**
59      * @see org.opencms.db.I_CmsVfsDriver#readResourcesWithProperty(org.opencms.db.CmsDbContext, int, org.opencms.util.CmsUUID, String)
60      */

61     public List JavaDoc readResourcesWithProperty(CmsDbContext dbc, int projectId, CmsUUID propertyDef, String JavaDoc path)
62     throws CmsDataAccessException {
63
64         List JavaDoc resources = new ArrayList JavaDoc();
65         ResultSet JavaDoc res = null;
66         PreparedStatement JavaDoc stmt = null;
67         Connection JavaDoc conn = null;
68
69         try {
70             conn = m_sqlManager.getConnection(dbc, projectId);
71             stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF");
72             stmt.setString(1, propertyDef.toString());
73             stmt.setString(2, path + "%");
74             res = stmt.executeQuery();
75
76             while (res.next()) {
77                 CmsResource resource = createResource(res, projectId);
78                 resources.add(resource);
79             }
80         } catch (SQLException JavaDoc e) {
81             throw new CmsDbSqlException(Messages.get().container(
82                 Messages.ERR_GENERIC_SQL_1,
83                 CmsDbSqlException.getErrorQuery(stmt)), e);
84         } finally {
85             m_sqlManager.closeAll(dbc, conn, stmt, res);
86         }
87
88         return resources;
89     }
90
91     /**
92      * @see org.opencms.db.I_CmsVfsDriver#readResourcesWithProperty(org.opencms.db.CmsDbContext, int, org.opencms.util.CmsUUID, String, String)
93      */

94     public List JavaDoc readResourcesWithProperty(
95         CmsDbContext dbc,
96         int projectId,
97         CmsUUID propertyDef,
98         String JavaDoc path,
99         String JavaDoc value) throws CmsDataAccessException {
100
101         List JavaDoc resources = new ArrayList JavaDoc();
102         ResultSet JavaDoc res = null;
103         PreparedStatement JavaDoc stmt = null;
104         Connection JavaDoc conn = null;
105
106         try {
107             conn = m_sqlManager.getConnection(dbc, projectId);
108             stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF_VALUE");
109             stmt.setString(1, propertyDef.toString());
110             stmt.setString(2, path + "%");
111             stmt.setString(3, "%" + value + "%");
112             res = stmt.executeQuery();
113
114             while (res.next()) {
115                 CmsResource resource = createResource(res, projectId);
116                 resources.add(resource);
117             }
118         } catch (SQLException JavaDoc e) {
119             throw new CmsDbSqlException(Messages.get().container(
120                 Messages.ERR_GENERIC_SQL_1,
121                 CmsDbSqlException.getErrorQuery(stmt)), e);
122         } finally {
123             m_sqlManager.closeAll(dbc, conn, stmt, res);
124         }
125
126         return resources;
127     }
128
129 }
Popular Tags