1 21 22 package org.apache.derby.iapi.services.property; 23 24 import org.apache.derby.iapi.reference.Attribute; 25 import org.apache.derby.iapi.reference.Property; 26 import org.apache.derby.iapi.reference.SQLState; 27 28 import org.apache.derby.iapi.services.property.PropertyUtil; 29 import org.apache.derby.iapi.error.StandardException; 30 import org.apache.derby.iapi.services.daemon.Serviceable; 31 import org.apache.derby.iapi.services.property.PropertySetCallback; 32 import org.apache.derby.iapi.store.access.TransactionController; 33 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 34 import java.io.Serializable ; 35 import java.util.Dictionary ; 36 import java.util.Enumeration ; 37 import java.util.Properties ; 38 import java.util.Vector ; 39 40 public class PropertyValidation implements PropertyFactory 41 { 42 private Vector notifyOnSet; 43 44 45 public PropertyValidation() 46 { 47 48 } 49 50 public Serializable doValidateApplyAndMap(TransactionController tc, 51 String key, Serializable value, 52 Dictionary d, boolean dbOnlyProperty) 53 throws StandardException 54 { 55 Serializable mappedValue = null; 56 if (notifyOnSet != null) { 57 synchronized (this) { 58 59 for (int i = 0; i < notifyOnSet.size() ; i++) { 60 PropertySetCallback psc = (PropertySetCallback) notifyOnSet.elementAt(i); 61 if (!psc.validate(key, value, d)) 62 continue; 63 64 72 if (!dbOnlyProperty && key.startsWith("derby.")) { 73 if (PropertyUtil.whereSet(key, d) == PropertyUtil.SET_IN_JVM) 74 continue; 75 } 76 77 Serviceable s; 78 if ((s = psc.apply(key,value,d)) != null) 79 ((TransactionManager) tc).addPostCommitWork(s); 80 if (mappedValue == null) 81 mappedValue = psc.map(key, value, d); 82 } 83 } 84 } 85 return mappedValue; 86 } 87 95 public Serializable doMap(String key, 96 Serializable value, 97 Dictionary set) 98 throws StandardException 99 { 100 Serializable mappedValue = null; 101 if (notifyOnSet != null) { 102 for (int i = 0; i < notifyOnSet.size() && mappedValue == null; i++) { 103 PropertySetCallback psc = (PropertySetCallback) notifyOnSet.elementAt(i); 104 mappedValue = psc.map(key, value, set); 105 } 106 } 107 108 if (mappedValue == null) 109 return value; 110 else 111 return mappedValue; 112 } 113 114 public void validateSingleProperty(String key, 115 Serializable value, 116 Dictionary set) 117 throws StandardException 118 { 119 if (key.equals(Attribute.LOG_DEVICE)) 121 { 122 throw StandardException.newException( 123 SQLState.RAWSTORE_CANNOT_CHANGE_LOGDEVICE); 124 } 125 126 if (notifyOnSet != null) { 127 for (int i = 0; i < notifyOnSet.size(); i++) { 128 PropertySetCallback psc = (PropertySetCallback) notifyOnSet.elementAt(i); 129 psc.validate(key, value, set); 130 } 131 } 132 } 133 134 public synchronized void addPropertySetNotification(PropertySetCallback who){ 135 136 if (notifyOnSet == null) 137 notifyOnSet = new Vector (1,1); 138 notifyOnSet.addElement(who); 139 140 } 141 142 public synchronized void verifyPropertySet(Properties p,Properties ignore) 143 throws StandardException 144 { 145 for (Enumeration e = p.propertyNames(); e.hasMoreElements();) 146 { 147 String pn = (String )e.nextElement(); 148 if (ignore.getProperty(pn) != null) continue; 151 Serializable pv = p.getProperty(pn); 152 validateSingleProperty(pn,pv,p); 153 } 154 } 155 } 156 157 158 159 | Popular Tags |