1 19 20 package org.netbeans.mdr.storagemodel; 21 22 import java.text.MessageFormat ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import org.netbeans.mdr.persistence.Storage; 26 import org.netbeans.mdr.persistence.Index; 27 import org.netbeans.mdr.persistence.StorageBadRequestException; 28 import org.netbeans.mdr.persistence.StorageException; 29 import org.netbeans.mdr.storagemodel.transientimpl.*; 30 import org.netbeans.mdr.util.IOUtils; 31 import org.netbeans.mdr.util.DebugException; 32 36 public class TransientStorableAssociation extends StorableAssociation implements Transient { 37 38 private static final String FORMAT = "{0}-{1}-{2}"; 40 41 42 private boolean uniqueA; 43 private boolean uniqueB; 44 45 private transient Index atIndex; 46 private transient Index btIndex; 47 48 49 public TransientStorableAssociation() { 50 } 51 52 68 public TransientStorableAssociation(MdrStorage mdrStorage, org.netbeans.mdr.persistence.MOFID immediatePackage, org.netbeans.mdr.persistence.MOFID meta, 69 String endA, org.netbeans.mdr.persistence.MOFID endAId, String endB, org.netbeans.mdr.persistence.MOFID endBId, Class typeA, Class typeB, 70 int minA, int maxA, int minB, int maxB, boolean orderedA, boolean orderedB, 71 boolean uniqueA, boolean uniqueB, boolean aggrA, boolean aggrB) throws StorageException { 72 super(mdrStorage, immediatePackage, meta, endA, endAId, endB, endBId, typeA, typeB, 73 minA, maxA, minB, maxB, orderedA, orderedB, uniqueA, uniqueB, aggrA, aggrB, false, false); 74 this.uniqueA = uniqueA; 75 this.uniqueB = uniqueB; 76 } 77 78 public void write(java.io.OutputStream outputStream) { 79 try { 80 IOUtils.writeBoolean (outputStream, this.uniqueA); 81 IOUtils.writeBoolean (outputStream, this.uniqueB); 82 } catch (java.io.IOException ioe) { 83 throw new DebugException (); 84 } 85 super.write(outputStream); 86 } 87 88 public void read(java.io.InputStream inputStream) { 89 try { 90 this.uniqueA = IOUtils.readBoolean (inputStream); 91 this.uniqueB = IOUtils.readBoolean (inputStream); 92 } catch (java.io.IOException ioe) { 93 throw new DebugException (); 94 } 95 super.read(inputStream); 96 } 97 98 106 protected Index createIndex(boolean multi, boolean ordered, boolean unique, int end) throws StorageException { 107 Index result = null; 108 String name = this.getIndexName (end); 109 if (multi) { 110 if (ordered) { 111 result = this.getMdrStorage().getTransientStorage().createMultivaluedOrderedIndex (name, Storage.EntryType.MOFID, Storage.EntryType.MOFID, unique); 112 } 113 else { 114 result = this.getMdrStorage().getTransientStorage().createMultivaluedIndex (name, Storage.EntryType.MOFID, Storage.EntryType.MOFID, unique); 115 } 116 } 117 else { 118 result = this.getMdrStorage().getTransientStorage().createSinglevaluedIndex (name, Storage.EntryType.MOFID, Storage.EntryType.MOFID); 119 } 120 121 if (end == 1) { 122 this.atIndex = result; 123 } 124 else { 125 this.btIndex = result; 126 } 127 return result; 128 } 129 130 131 133 protected Index findIndex(int end) throws StorageException { 134 if (end == 1) { 135 if (this.atIndex == null) { 136 String name = this.getIndexName (end); 137 this.atIndex = this.getMdrStorage ().getTransientStorage ().getIndex (name); 138 if (this.atIndex == null) { 140 this.atIndex = this.createIndex (this.isMultivaluedA (), this.isOrderedA (), this.isUniqueA (), end); 142 } 143 } 144 return this.atIndex; 145 } 146 else { 147 if (this.btIndex == null) { 148 String name = this.getIndexName (end); 149 this.btIndex = this.getMdrStorage ().getTransientStorage ().getIndex (name); 150 if (this.btIndex == null) { 152 this.btIndex = this.createIndex (this.isMultivaluedB (), this.isOrderedB (), this.isUniqueB (), end); 154 } 155 } 156 return this.btIndex; 157 } 158 } 159 160 161 protected void deleteIndex(String opkgId, String mofId, int end) throws StorageException { 162 String name = this.getIndexName (end); 163 this.getMdrStorage ().getTransientStorage ().dropIndex (name); 164 if (end == 1) 165 this.atIndex = null; 166 else 167 this.btIndex = null; 168 } 169 170 protected boolean isUniqueA() { 171 return this.uniqueA; 172 } 173 174 protected boolean isUniqueB() { 175 return this.uniqueB; 176 } 177 178 private String getIndexName (int end) { 179 return MessageFormat.format(FORMAT, new Object [] {this.getOutermostPackageId(), this.getMofId(), new Integer (end)}); 180 } 181 182 183 } 184 | Popular Tags |