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.CompHelper; 25 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertyGetter; 26 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertySetter; 27 import org.apache.openoffice.comp.sdbc.dbtools.sdbcx.descriptors.SdbcxColumnDescriptor; 28 import org.apache.openoffice.comp.sdbc.dbtools.util.PropertyIds; 29 30 import com.sun.star.beans.PropertyAttribute; 31 import com.sun.star.beans.XPropertySet; 32 import com.sun.star.container.XNamed; 33 import com.sun.star.lang.XServiceInfo; 34 import com.sun.star.sdbc.ColumnValue; 35 import com.sun.star.sdbcx.XDataDescriptorFactory; 36 import com.sun.star.uno.Type; 37 38 public class OColumn extends ODescriptor implements XNamed, XDataDescriptorFactory, XServiceInfo { 39 40 private static final String[] services = { 41 "com.sun.star.sdbcx.Column" 42 }; 43 44 private String typeName = ""; 45 private String description = ""; 46 private String defaultValue = ""; 47 private int isNullable; 48 private int precision; 49 private int scale; 50 private int type; 51 private boolean isAutoIncrement; 52 private boolean isRowVersion; 53 private boolean isCurrency; 54 OColumn(final boolean isCaseSensitive)55 public OColumn(final boolean isCaseSensitive) { 56 super("", isCaseSensitive); 57 this.isNullable = ColumnValue.NULLABLE; 58 this.precision = 0; 59 this.scale = 0; 60 this.type = 0; 61 this.isAutoIncrement = false; 62 this.isRowVersion = false; 63 this.isCurrency = false; 64 registerProperties(); 65 } 66 OColumn( final String name, final String typeName, final String defaultValue, final String description, final int isNullable, final int precision, final int scale, final int type, final boolean isAutoIncrement, final boolean isRowVersion, final boolean isCurrency, final boolean isCaseSensitive)67 public OColumn( 68 final String name, 69 final String typeName, 70 final String defaultValue, 71 final String description, 72 final int isNullable, 73 final int precision, 74 final int scale, 75 final int type, 76 final boolean isAutoIncrement, 77 final boolean isRowVersion, 78 final boolean isCurrency, 79 final boolean isCaseSensitive) { 80 super(name, isCaseSensitive); 81 this.typeName = typeName; 82 this.description = description; 83 this.defaultValue = defaultValue; 84 this.isNullable = isNullable; 85 this.precision = precision; 86 this.scale = scale; 87 this.type = type; 88 this.isAutoIncrement = isAutoIncrement; 89 this.isRowVersion = isRowVersion; 90 this.isCurrency = isCurrency; 91 registerProperties(); 92 } 93 registerProperties()94 private void registerProperties() { 95 registerProperty(PropertyIds.TYPENAME.name, PropertyIds.TYPENAME.id, Type.STRING, PropertyAttribute.READONLY, 96 new PropertyGetter() { 97 @Override 98 public Object getValue() { 99 return typeName; 100 101 } 102 }, 103 new PropertySetter() { 104 @Override 105 public void setValue(Object value) { 106 typeName = (String) value; 107 } 108 }); 109 registerProperty(PropertyIds.DESCRIPTION.name, PropertyIds.DESCRIPTION.id, Type.STRING, PropertyAttribute.READONLY, 110 new PropertyGetter() { 111 @Override 112 public Object getValue() { 113 return description; 114 115 } 116 }, 117 new PropertySetter() { 118 @Override 119 public void setValue(Object value) { 120 description = (String) value; 121 } 122 }); 123 registerProperty(PropertyIds.DEFAULTVALUE.name, PropertyIds.DEFAULTVALUE.id, Type.STRING, PropertyAttribute.READONLY, 124 new PropertyGetter() { 125 @Override 126 public Object getValue() { 127 return defaultValue; 128 129 } 130 }, 131 new PropertySetter() { 132 @Override 133 public void setValue(Object value) { 134 defaultValue = (String) value; 135 } 136 }); 137 registerProperty(PropertyIds.PRECISION.name, PropertyIds.PRECISION.id, Type.LONG, PropertyAttribute.READONLY, 138 new PropertyGetter() { 139 @Override 140 public Object getValue() { 141 return precision; 142 143 } 144 }, 145 new PropertySetter() { 146 @Override 147 public void setValue(Object value) { 148 precision = (Integer) value; 149 } 150 }); 151 registerProperty(PropertyIds.TYPE.name, PropertyIds.TYPE.id, Type.LONG, PropertyAttribute.READONLY, 152 new PropertyGetter() { 153 @Override 154 public Object getValue() { 155 return type; 156 157 } 158 }, 159 new PropertySetter() { 160 @Override 161 public void setValue(Object value) { 162 type = (Integer) value; 163 } 164 }); 165 registerProperty(PropertyIds.SCALE.name, PropertyIds.SCALE.id, Type.LONG, PropertyAttribute.READONLY, 166 new PropertyGetter() { 167 @Override 168 public Object getValue() { 169 return scale; 170 171 } 172 }, 173 new PropertySetter() { 174 @Override 175 public void setValue(Object value) { 176 scale = (Integer) value; 177 } 178 }); 179 registerProperty(PropertyIds.ISNULLABLE.name, PropertyIds.ISNULLABLE.id, Type.LONG, PropertyAttribute.READONLY, 180 new PropertyGetter() { 181 @Override 182 public Object getValue() { 183 return isNullable; 184 185 } 186 }, 187 new PropertySetter() { 188 @Override 189 public void setValue(Object value) { 190 isNullable = (Integer) value; 191 } 192 }); 193 registerProperty(PropertyIds.ISAUTOINCREMENT.name, PropertyIds.ISAUTOINCREMENT.id, Type.BOOLEAN, PropertyAttribute.READONLY, 194 new PropertyGetter() { 195 @Override 196 public Object getValue() { 197 return isAutoIncrement; 198 199 } 200 }, 201 new PropertySetter() { 202 @Override 203 public void setValue(Object value) { 204 isAutoIncrement = (Boolean) value; 205 } 206 }); 207 registerProperty(PropertyIds.ISROWVERSION.name, PropertyIds.ISROWVERSION.id, Type.BOOLEAN, PropertyAttribute.READONLY, 208 new PropertyGetter() { 209 @Override 210 public Object getValue() { 211 return isRowVersion; 212 213 } 214 }, 215 new PropertySetter() { 216 @Override 217 public void setValue(Object value) { 218 isRowVersion = (Boolean) value; 219 } 220 }); 221 registerProperty(PropertyIds.ISCURRENCY.name, PropertyIds.ISCURRENCY.id, Type.BOOLEAN, PropertyAttribute.READONLY, 222 new PropertyGetter() { 223 @Override 224 public Object getValue() { 225 return isCurrency; 226 227 } 228 }, 229 new PropertySetter() { 230 @Override 231 public void setValue(Object value) { 232 isCurrency = (Boolean) value; 233 } 234 }); 235 } 236 237 // XComponent 238 239 @Override postDisposing()240 protected void postDisposing() { 241 super.postDisposing(); 242 } 243 244 // XServiceInfo 245 getImplementationName()246 public String getImplementationName() { 247 return getClass().getName(); 248 } 249 250 @Override getSupportedServiceNames()251 public String[] getSupportedServiceNames() { 252 return services.clone(); 253 } 254 255 @Override supportsService(String serviceName)256 public boolean supportsService(String serviceName) { 257 for (String service : getSupportedServiceNames()) { 258 if (service.equals(serviceName)) { 259 return true; 260 } 261 } 262 return false; 263 } 264 265 // XDataDescriptorFactory 266 267 @Override createDataDescriptor()268 public XPropertySet createDataDescriptor() { 269 SdbcxColumnDescriptor descriptor = new SdbcxColumnDescriptor(isCaseSensitive()); 270 synchronized (this) { 271 CompHelper.copyProperties(this, descriptor); 272 } 273 return descriptor; 274 } 275 } 276