1 32 33 package com.knowgate.hipergate; 34 35 import com.knowgate.debug.DebugFile; 36 import com.knowgate.jdc.JDCConnection; 37 import com.knowgate.acl.ACL; 38 import com.knowgate.acl.ACLDomain; 39 import com.knowgate.dataobjs.DB; 40 import com.knowgate.dataobjs.DBBind; 41 import com.knowgate.dataobjs.DBPersist; 42 import com.knowgate.misc.Gadgets; 43 44 import java.sql.SQLException ; 45 import java.sql.Statement ; 46 47 import java.io.IOException ; 48 49 53 54 public class Shop extends DBPersist { 55 public Shop() { 56 super(DB.k_shops, "Shop"); 57 } 58 59 public Shop(JDCConnection oConn, String sShopId) throws SQLException { 60 super(DB.k_shops, "Shop"); 61 62 load (oConn, new Object []{sShopId}); 63 } 64 65 67 72 public boolean delete(JDCConnection oConn) throws SQLException { 73 74 Statement oStmt; 75 String sRootCat; 76 boolean bRetVal; 77 String sSQL; 78 79 if (DebugFile.trace) { 80 DebugFile.writeln("Begin Shop.delete([Connection], " + getStringNull(DB.gu_root_cat, "null") + ")"); 81 DebugFile.incIdent(); 82 } 83 84 oStmt = oConn.createStatement(); 85 86 if (DBBind.exists(oConn, DB.k_returned_invoices, "U")) { 87 sSQL = "DELETE FROM " + DB.k_invoice_lines + " WHERE " + DB.gu_invoice + " IN (SELECT "+DB.gu_returned+" FROM " + DB.k_returned_invoices + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "')"; 88 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 89 oStmt.executeUpdate(sSQL); 90 sSQL = "DELETE FROM " + DB.k_returned_invoices + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "'"; 91 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 92 oStmt.executeUpdate(sSQL); 93 } 94 95 if (DBBind.exists(oConn, DB.k_invoices, "U")) { 96 sSQL = "DELETE FROM " + DB.k_invoice_lines + " WHERE " + DB.gu_invoice + " IN (SELECT "+DB.gu_invoice+" FROM " + DB.k_invoices + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "')"; 97 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 98 oStmt.executeUpdate(sSQL); 99 sSQL = "DELETE FROM " + DB.k_invoices + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "'"; 100 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 101 oStmt.executeUpdate(sSQL); 102 } 103 104 sSQL = "DELETE FROM " + DB.k_order_lines + " WHERE " + DB.gu_order + " IN (SELECT "+DB.gu_order+" FROM " + DB.k_orders + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "')"; 105 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 106 oStmt.executeUpdate(sSQL); 107 108 sSQL = "DELETE FROM " + DB.k_orders + " WHERE " + DB.gu_shop + "='" + getString(DB.gu_shop) + "'"; 109 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 110 oStmt.executeUpdate(sSQL); 111 112 oStmt.close(); 113 114 sRootCat = getString(DB.gu_root_cat); 115 116 bRetVal = super.delete(oConn); 117 118 if (bRetVal) 119 try { 120 bRetVal = Category.delete(oConn, sRootCat); 121 } catch (IOException ioe) { 122 bRetVal = false; 123 throw new SQLException ("IOException " + ioe.getMessage()); 124 } 125 if (DebugFile.trace) { 126 DebugFile.writeln("End Shop.delete() : " + String.valueOf(bRetVal)); 127 DebugFile.incIdent(); 128 } 129 130 return bRetVal; 131 } 132 133 135 public boolean store(JDCConnection oConn) throws SQLException { 136 137 if (!AllVals.containsKey(DB.gu_shop)) 138 put(DB.gu_shop, Gadgets.generateUUID()); 139 140 if (!AllVals.containsKey(DB.bo_active)) 141 put(DB.bo_active, (short)1); 142 143 return super.store(oConn); 144 } 146 148 public boolean store(JDCConnection oConn, String sParentCategoryId) throws SQLException { 149 boolean bRetVal; 150 Category oRootCat; 151 ACLDomain oDomain; 152 153 if (DebugFile.trace) { 154 DebugFile.writeln("Begin Shop.store([Connection], " + sParentCategoryId + ")"); 155 DebugFile.incIdent(); 156 } 157 158 if (sParentCategoryId==null) 159 throw new java.lang.IllegalArgumentException ("Parent category Identifier cannot be null"); 160 161 if (sParentCategoryId.length()==0) 162 throw new java.lang.IllegalArgumentException ("Parent category Identifier cannot be empty"); 163 164 if (!AllVals.containsKey(DB.gu_shop)) 165 put(DB.gu_shop, Gadgets.generateUUID()); 166 167 if (!AllVals.containsKey(DB.bo_active)) 168 put(DB.bo_active, (short)1); 169 170 if (!AllVals.containsKey(DB.gu_root_cat)) { 171 if (DebugFile.trace) DebugFile.writeln("creating shops category for domain " + String.valueOf(getInt(DB.id_domain))); 172 173 oDomain = new ACLDomain(oConn, getInt(DB.id_domain)); 174 oRootCat = new Category(Category.store(oConn, null, sParentCategoryId, Category.makeName(oConn, getString(DB.nm_shop)), getShort(DB.bo_active), (short)0, oDomain.getString(DB.gu_owner), null, null)); 175 oRootCat.setUserPermissions(oConn, oDomain.getString(DB.gu_owner), ACL.PERMISSION_FULL_CONTROL, (short)0, (short)0); 176 oRootCat.setGroupPermissions(oConn, oDomain.getString(DB.gu_admins), ACL.PERMISSION_FULL_CONTROL, (short)0, (short)0); 177 178 if (sAuditUsr.length()>0 && !sAuditUsr.equals(oDomain.getString(DB.gu_owner))) { 179 oRootCat.setUserPermissions(oConn, sAuditUsr, ACL.PERMISSION_MODIFY, (short)0, (short)0); 180 } 181 182 put(DB.gu_root_cat, oRootCat.getString(DB.gu_category)); 183 } 184 else { 185 oRootCat = new Category(getString(DB.gu_root_cat)); 186 if (!oRootCat.isChildOf(oConn, sParentCategoryId)); 187 throw new IllegalArgumentException ("Root Category is not a child of specified Parent Category"); 188 } 189 190 if (DebugFile.trace) { 191 DebugFile.decIdent(); 192 DebugFile.writeln("End Shop.store()"); 193 } 194 195 return super.store(oConn); 196 } 198 200 public void expandCategories(JDCConnection oConn) throws SQLException { 201 Category oRootCat = new Category(DB.gu_root_cat); 202 oRootCat.expand(oConn); 203 } 205 208 public static final short ClassId = 40; 209 210 } 211 | Popular Tags |