1 21 22 package org.apache.derby.iapi.db; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.error.PublicAPI; 26 27 import org.apache.derby.iapi.sql.Activation; 28 import org.apache.derby.iapi.sql.conn.Authorizer; 29 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 30 import org.apache.derby.iapi.sql.conn.ConnectionUtil; 31 32 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 34 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 35 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 37 38 import org.apache.derby.iapi.store.access.ConglomerateController; 39 import org.apache.derby.iapi.store.access.TransactionController; 40 41 import org.apache.derby.iapi.services.property.PropertyUtil; 42 import org.apache.derby.iapi.reference.SQLState; 43 44 import java.util.Properties ; 45 import java.sql.SQLException ; 46 47 56 public final class PropertyInfo 57 { 58 59 69 public static Properties getTableProperties(String schemaName, String tableName) 70 throws SQLException 71 { 72 return PropertyInfo.getConglomerateProperties( schemaName, tableName, false ); 73 } 74 75 85 public static Properties getIndexProperties(String schemaName, String indexName) 86 throws SQLException 87 { 88 return PropertyInfo.getConglomerateProperties( schemaName, indexName, true ); 89 } 90 91 100 public static String getDatabaseProperty(String key) throws SQLException { 101 LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); 102 103 try { 104 return PropertyUtil.getDatabaseProperty(lcc.getTransactionExecute(), key); 105 } catch (StandardException se) { 106 throw PublicAPI.wrapStandardException(se); 107 } 108 } 109 110 118 public static void setDatabaseProperty(String key, String value) throws SQLException 119 { 120 LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); 121 122 try { 123 Authorizer a = lcc.getAuthorizer(); 124 a.authorize((Activation) null, Authorizer.PROPERTY_WRITE_OP); 125 126 TransactionController tc = lcc.getTransactionExecute(); 128 129 tc.setProperty(key, value, false); 130 } catch (StandardException se) { 131 throw PublicAPI.wrapStandardException(se); 132 } 133 } 134 135 138 private PropertyInfo() {} 139 140 141 147 157 private static Properties getConglomerateProperties( String schemaName, String conglomerateName, boolean isIndex ) 158 throws SQLException 159 { 160 long conglomerateNumber; 161 162 LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); 164 165 TransactionController tc = lcc.getTransactionExecute(); 167 168 try { 169 170 DataDictionary dd = lcc.getDataDictionary(); 172 173 174 SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true); 176 if ( !isIndex) 177 { 178 TableDescriptor td = dd.getTableDescriptor(conglomerateName, sd); 180 181 if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) { return new Properties (); } 183 184 conglomerateNumber = td.getHeapConglomerateId(); 185 } 186 else 187 { 188 ConglomerateDescriptor cd = dd.getConglomerateDescriptor(conglomerateName, sd, false); 190 191 if (cd == null) { return new Properties (); } 193 194 conglomerateNumber = cd.getConglomerateNumber(); 195 } 196 197 ConglomerateController cc = tc.openConglomerate( 198 conglomerateNumber, 199 false, 200 0, 201 TransactionController.MODE_RECORD, 202 TransactionController.ISOLATION_SERIALIZABLE); 203 204 Properties properties = tc.getUserCreateConglomPropList(); 205 cc.getTableProperties( properties ); 206 207 cc.close(); 208 return properties; 209 210 } catch (StandardException se) { 211 throw PublicAPI.wrapStandardException(se); 212 } 213 214 } 215 } 216 | Popular Tags |