| 1 18 package jahiatemplates.org.jahia.portlets_api; 19 20 import java.sql.Connection ; 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Statement ; 24 25 import org.jahia.exceptions.JahiaException; 26 import org.jahia.utils.JahiaConsole; 27 28 29 public class PortletsDBManager { 30 31 private static PortletsDBManager theObject = null; 32 private DesktopObj theDesktop; 33 private PortletObj thePortlet; 34 private SkinObj theSkin; 35 private int thePortletsCount; 36 private int theDesktopsCount; 37 38 39 40 46 private PortletsDBManager() 47 { 48 JahiaConsole.println( "PortletsDBManager", "***** Starting the Portlets DataBase Manager *****" ); 49 } 51 52 58 public static synchronized PortletsDBManager getInstance() 59 { 60 if (theObject == null) { 61 theObject = new PortletsDBManager(); 62 } 63 return theObject; 64 } 66 67 73 public SkinObj load_portlet_skin(int theID) 74 throws JahiaException 75 { 76 Connection dbConn = null; 77 Statement stmt = null; 78 ResultSet rs = null; 79 80 try { 81 String sqlQuery = "SELECT * FROM jahiatemplates_portet_skin WHERE (skin_id=" + theID + ")"; 82 83 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection(); 84 stmt = dbConn.createStatement(); 85 rs = stmt.executeQuery( sqlQuery ); 86 theSkin = null; 87 while (rs.next()) { 88 theSkin = new SkinObj(rs.getInt("skin_id"), 89 rs.getString("skin_name"), 90 rs.getString("skin_url")); 91 } 92 } catch (SQLException se) { 93 theSkin = null; 94 String errorMsg = "Error in load_portlet_skin : " + se.getMessage(); 95 JahiaConsole.println( "JahiaDBManager", errorMsg + " -> BAILING OUT" ); 96 throw new JahiaException( "Cannot load portlet skin data from the database", 97 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY ); 98 } finally { 99 try { 100 101 if ( stmt != null ) stmt.close(); 102 } catch ( SQLException ex ) { 104 JahiaException je = new JahiaException( "Cannot free resources", 105 "load_portlet_skin : cannot free resources", 106 JahiaException.DATABASE_ERROR, JahiaException.WARNING_SEVERITY ); 107 } 108 } 109 return theSkin; 110 111 } 113 114 120 public SkinObj load_desktop_skin(int theID) 121 throws JahiaException 122 { 123 Connection dbConn = null; 124 Statement stmt = null; 125 ResultSet rs = null; 126 127 try { 128 String sqlQuery = "SELECT * FROM jahiatemplates_desktop_skin WHERE (skin_id=" + theID + ")"; 129 130 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection(); 131 stmt = dbConn.createStatement(); 132 rs = stmt.executeQuery( sqlQuery ); 133 theSkin = null; 134 while (rs.next()) { 135 theSkin = new SkinObj(rs.getInt("skin_id"), 136 rs.getString("skin_name"), 137 rs.getString("skin_url")); 138 } 139 } catch (SQLException se) { 140 theSkin = null; 141 String errorMsg = "Error in load_desktop_skin : " + se.getMessage(); 142 JahiaConsole.println( "JahiaDBManager", errorMsg + " -> BAILING OUT" ); 143 throw new JahiaException( "Cannot load desktop skin data from the database", 144 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY ); 145 } finally { 146 try { 147 148 if ( stmt != null ) stmt.close(); 149 } catch ( SQLException ex ) { 151 JahiaException je = new JahiaException( "Cannot free resources", 152 "load_desktop_skin : cannot free resources", 153 JahiaException.DATABASE_ERROR, JahiaException.WARNING_SEVERITY ); 154 } 155 } 156 return theSkin; 157 158 } 160 } 161 | Popular Tags |