1 23 24 package org.objectweb.jorm.mapper.fos.lib; 25 26 import org.objectweb.jorm.api.PException; 27 import org.objectweb.jorm.lib.AbstractPMapcluster; 28 import org.objectweb.perseus.fos.api.FosAccess; 29 import org.objectweb.perseus.fos.api.FosException; 30 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 33 34 39 public class FosPMapCluster extends AbstractPMapcluster { 40 private ArrayList directories; 41 private FosPMappingStructuresManager manager; 42 43 48 FosPMapCluster(String jcname, FosPMappingStructuresManager man) { 49 super(); 50 jcNames.add(jcname); 51 directories = new ArrayList (1); 52 manager = man; 53 } 54 55 61 FosPMapCluster(String jcname, String basedir, FosPMappingStructuresManager man) { 62 this(jcname, man); 63 directories.add(basedir); 64 } 65 66 70 void addClass(String jcname) { 71 addDependency(jcname); 72 } 73 74 81 void addDirName(String dirname) throws PException { 82 String curd = null; 83 Iterator it = directories.iterator(); 84 while (it.hasNext()) { 85 curd = (String ) it.next(); 86 if (curd.equals(dirname)) { 87 break; 88 } 89 curd = null; 90 } 91 if (curd == null) { 92 directories.add(dirname); 94 } 95 } 96 97 104 boolean containDirectory(String dirname) throws PException { 105 String curd = null; 106 Iterator it = directories.iterator(); 107 while (it.hasNext()) { 108 curd = (String ) it.next(); 109 if ((dirname.length() >= curd.length()) && curd.equals(dirname.substring(0, curd.length()))) { 110 return true; 111 } 112 if ((dirname.length() < curd.length()) && dirname.equals(curd.substring(0, dirname.length()))) { 113 return true; 114 } 115 curd = null; 116 } 117 return false; 118 } 119 120 125 void merge(FosPMapCluster cl) { 126 jcNames.addAll(cl.jcNames); 127 directories.addAll(cl.directories); 128 } 129 130 132 138 public void createMappingStructures(boolean force) throws PException { 139 if (structuresActive) { 140 throw new PException("Cannot change mapping structures while they are under use"); 141 } 142 } 143 144 150 public void deleteData() throws PException { 151 Object conn = manager.getConnection(); 152 String curd = null; 153 try { 154 Iterator it = directories.iterator(); 155 while (it.hasNext()) { 156 curd = (String ) it.next(); 157 if (((FosAccess) conn).existDir(curd)) { 158 Iterator it2 = ((FosAccess) conn).scan(curd); 159 while (it2.hasNext()) { 160 String oid = (String ) it2.next(); 161 ((FosAccess) conn).delete(curd, oid); 162 } 163 } 164 } 165 } catch (FosException e) { 166 throw new PException(e, "PB while deteling data from FOS directory " + curd); 167 } finally { 168 manager.closeConnection(conn); 169 } 170 } 171 172 179 public void deleteMappingStructures() throws PException { 180 if (structuresActive) { 181 throw new PException("Cannot change mapping structures while they are under use"); 182 } 183 Object conn = manager.getConnection(); 184 String curd = null; 185 try { 186 Iterator it = directories.iterator(); 187 while (it.hasNext()) { 188 curd = (String ) it.next(); 189 if (((FosAccess) conn).existDir(curd)) { 190 ((FosAccess) conn).deleteDir(curd); 191 } 192 } 193 } catch (FosException e) { 194 throw new PException(e, "PB while deteling FOS directory " + curd); 195 } finally { 196 manager.closeConnection(conn); 197 } 198 } 199 } 200 | Popular Tags |