1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.comp.sdbc.dbtools.sdbcx; 23 24 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertyGetter; 25 import org.apache.openoffice.comp.sdbc.dbtools.util.PropertyIds; 26 27 import com.sun.star.beans.PropertyAttribute; 28 import com.sun.star.container.XIndexAccess; 29 import com.sun.star.container.XNameAccess; 30 import com.sun.star.container.XNamed; 31 import com.sun.star.lang.XServiceInfo; 32 import com.sun.star.sdbc.XConnection; 33 import com.sun.star.sdbcx.XAlterTable; 34 import com.sun.star.sdbcx.XColumnsSupplier; 35 import com.sun.star.sdbcx.XDataDescriptorFactory; 36 import com.sun.star.sdbcx.XIndexesSupplier; 37 import com.sun.star.sdbcx.XKeysSupplier; 38 import com.sun.star.sdbcx.XRename; 39 import com.sun.star.uno.Type; 40 41 public abstract class OTable extends ODescriptor 42 implements XColumnsSupplier, XKeysSupplier, XNamed, XServiceInfo, XDataDescriptorFactory, 43 XIndexesSupplier, XRename, XAlterTable { 44 45 private static String[] services = { 46 "com.sun.star.sdbcx.Table" 47 }; 48 49 private XConnection connection; 50 protected String catalogName; 51 protected String schemaName; 52 protected String description = ""; 53 protected String type = ""; 54 55 protected OContainer keys; 56 protected OContainer columns; 57 protected OContainer indexes; 58 protected OContainer tables; 59 OTable(String name, boolean isCaseSensitive, XConnection connection, OContainer tables)60 protected OTable(String name, boolean isCaseSensitive, XConnection connection, OContainer tables) { 61 super(name, isCaseSensitive); 62 this.tables = tables; 63 this.connection = connection; 64 registerProperties(); 65 } 66 registerProperties()67 private void registerProperties() { 68 registerProperty(PropertyIds.CATALOGNAME.name, PropertyIds.CATALOGNAME.id, Type.STRING, PropertyAttribute.READONLY, 69 new PropertyGetter() { 70 @Override 71 public Object getValue() { 72 return catalogName; 73 74 } 75 }, null); 76 registerProperty(PropertyIds.SCHEMANAME.name, PropertyIds.SCHEMANAME.id, Type.STRING, PropertyAttribute.READONLY, 77 new PropertyGetter() { 78 @Override 79 public Object getValue() { 80 return schemaName; 81 82 } 83 }, null); 84 registerProperty(PropertyIds.DESCRIPTION.name, PropertyIds.DESCRIPTION.id, Type.STRING, PropertyAttribute.READONLY, 85 new PropertyGetter() { 86 @Override 87 public Object getValue() { 88 return description; 89 90 } 91 }, null); 92 registerProperty(PropertyIds.TYPE.name, PropertyIds.TYPE.id, Type.STRING, PropertyAttribute.READONLY, 93 new PropertyGetter() { 94 @Override 95 public Object getValue() { 96 return type; 97 98 } 99 }, null); 100 } 101 102 @Override postDisposing()103 protected void postDisposing() { 104 super.postDisposing(); 105 if (keys != null) { 106 keys.dispose(); 107 } 108 if (columns != null) { 109 columns.dispose(); 110 } 111 if (indexes != null) { 112 indexes.dispose(); 113 } 114 tables = null; 115 } 116 117 // XServiceInfo 118 119 @Override getImplementationName()120 public String getImplementationName() { 121 return getClass().getName(); 122 } 123 124 @Override getSupportedServiceNames()125 public String[] getSupportedServiceNames() { 126 return services.clone(); 127 } 128 129 @Override supportsService(String serviceName)130 public boolean supportsService(String serviceName) { 131 for (String service : getSupportedServiceNames()) { 132 if (serviceName.equals(service)) { 133 return true; 134 } 135 } 136 return false; 137 } 138 139 // XColumnsSupplier 140 141 @Override getColumns()142 public synchronized XNameAccess getColumns() { 143 if (columns == null) { 144 columns = refreshColumns(); 145 } 146 return columns; 147 } 148 149 @Override getIndexes()150 public synchronized XNameAccess getIndexes() { 151 checkDisposed(); 152 if (indexes == null) { 153 indexes = refreshIndexes(); 154 } 155 return indexes; 156 } 157 158 @Override getKeys()159 public synchronized XIndexAccess getKeys() { 160 checkDisposed(); 161 if (keys == null) { 162 keys = refreshKeys(); 163 } 164 return keys; 165 } 166 getConnection()167 public XConnection getConnection() { 168 return connection; 169 } 170 getTypeCreatePattern()171 public String getTypeCreatePattern() { 172 return ""; 173 } 174 refreshColumns()175 protected abstract OContainer refreshColumns(); refreshIndexes()176 protected abstract OContainer refreshIndexes(); refreshKeys()177 protected abstract OContainer refreshKeys(); 178 } 179