1 package olr.om; 2 3 import java.util.Date; 4 import java.util.List; 5 6 import org.apache.torque.util.Criteria; 7 8 /*** 9 * The skeleton for this class was autogenerated by Torque on: 10 * 11 * [Wed Jun 16 21:12:50 CEST 2004] 12 * 13 * You should add additional methods to this class to meet the 14 * application requirements. This class will only be generated as 15 * long as it does not already exist in the output directory. 16 */ 17 public class RdfNamespacePeer 18 extends olr.om.BaseRdfNamespacePeer 19 { 20 static void delete(int id) throws Exception 21 { 22 final int[] ids = {id}; 23 delete(ids); 24 } 25 26 static void delete(int[] ids) 27 throws Exception 28 { 29 if(ids.length == 0) return; 30 31 final StringBuffer resourceSubQuery = new StringBuffer(RdfNamespacePeer.ID).append(" NOT IN ") 32 .append("(SELECT DISTINCT ").append(RdfResourcePeer.NS) 33 .append(" FROM ").append(RdfResourcePeer.TABLE_NAME) 34 .append(")"); 35 36 final StringBuffer schemaSubQuery = new StringBuffer(RdfNamespacePeer.ID).append(" NOT IN ") 37 .append("(SELECT DISTINCT ").append(RdfSchemaPeer.NS_ID) 38 .append(" FROM ").append(RdfSchemaPeer.TABLE_NAME) 39 .append(")"); 40 41 final StringBuffer query = new StringBuffer("DELETE FROM ").append(RdfNamespacePeer.TABLE_NAME) 42 .append(" WHERE ID IN ").append(DBUtils.idsToInList(ids)) 43 .append(" AND ").append(resourceSubQuery) 44 .append(" AND ").append(schemaSubQuery); 45 46 RdfNamespacePeer.executeStatement(query.toString(), OmContext.getConnection()); 47 } 48 49 public static RdfNamespace selectElseInsert(String namespace) 50 throws Exception 51 { 52 final RdfNamespace ns = new RdfNamespace(namespace); 53 return selectElseInsert(ns); 54 } 55 56 private static RdfNamespace selectElseInsert(RdfNamespace namespace) 57 throws Exception 58 { 59 RdfNamespace ns = select(namespace); 60 61 if(ns != null) return ns; 62 63 namespace.setModified(new Date()); 64 namespace.setRdfUser(OmContext.getUser()); 65 namespace.save(OmContext.getConnection()); 66 return namespace; 67 } 68 69 private static RdfNamespace select(RdfNamespace namespace) 70 throws Exception 71 { 72 final Criteria criteria = new Criteria(); 73 criteria.add(RdfNamespacePeer.NS_NAME, namespace.getNsName()); 74 final List namespaces = RdfNamespacePeer.doSelect(criteria, OmContext.getConnection()); 75 76 if(namespaces.size() == 1) 77 return (RdfNamespace)namespaces.get(0); 78 return null; 79 } 80 }