1 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 ; 42 import java.sql.PreparedStatement ; 43 import java.sql.ResultSet ; 44 import java.sql.SQLException ; 45 import java.util.ArrayList ; 46 import java.util.List ; 47 48 56 public class CmsVfsDriver extends org.opencms.db.mysql.CmsVfsDriver { 57 58 61 public List readResourcesWithProperty(CmsDbContext dbc, int projectId, CmsUUID propertyDef, String path) 62 throws CmsDataAccessException { 63 64 List resources = new ArrayList (); 65 ResultSet res = null; 66 PreparedStatement stmt = null; 67 Connection 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 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 94 public List readResourcesWithProperty( 95 CmsDbContext dbc, 96 int projectId, 97 CmsUUID propertyDef, 98 String path, 99 String value) throws CmsDataAccessException { 100 101 List resources = new ArrayList (); 102 ResultSet res = null; 103 PreparedStatement stmt = null; 104 Connection 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 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 |