001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.objectmanager.data.db; 031 032import java.util.Vector; 033 034import org.kepler.objectmanager.cache.DataCacheObject; 035import org.kepler.objectmanager.data.DataObjectDescription; 036import org.kepler.objectmanager.data.text.TextComplexDataFormat; 037 038/** 039 * This object represents an TableEntity. A TableEntity stores information about 040 * a table of Attributes that is used in a Step in the pipeline. 041 */ 042public class Entity extends DataObjectDescription implements DSTableIFace { 043 /** static variable for ROWMAJOR tables **/ 044 public static String ROWMAJOR = "ROWMAJOR"; 045 /** static variable for COLUMNMAJOR tables **/ 046 public static String COLUMNMAJOR = "COLUMNMAJOR"; 047 public static String ZIP = "zip"; 048 public static String TAR = "application/x-tar"; 049 public static String GZIP = "gzip"; 050 051 /** static variable for table type **/ 052 public static final String TABLEENTITY = "TABLEENTITY"; 053 public static final String SPATIALRASTERENTITY = "SPATIALRASTERENTITY"; 054 public static final String SPATIALVECTORENTITY = "SPATIALVECTORENTITY"; 055 public static final String STOREDPROCEDUREENTITY = "STOREDPROCEDUREENTITY"; 056 public static final String VIEWENTITY = "VIEWENTITY"; 057 public static final String OTHERENTITY = "OTHERENTITY"; 058 059 private AttributeList attributeList = new AttributeList(); 060 private Boolean caseSensitive; 061 private String orientation; 062 private int numRecords = 0; 063 private int numHeaderLines = -1; 064 private int numFooterLines = -1; 065 private String delimiter = null; 066 private String recordDelimiter = null; 067 private boolean multiple = false; // if true, multiple inputs can be mapped 068 // to one table 069 070 private String fileName; // filename where TableEntity data is stored 071 private String url; // distribution url for this entity 072 private String DBtableName; // the unique table name will be stored in DB 073 private String compressionMethod = null; 074 private boolean isImageEntity = false; 075 private boolean hasGZipDataFile = false; 076 private boolean hasZipDataFile = false; 077 private boolean hasTarDataFile = false; 078 private DataCacheObject dataCacheObject = null; 079 private boolean simpleDelimited = true; 080 private TextComplexDataFormat[] dataFormatArray = null; 081 private String physicalLineDelimiter = null; 082 private boolean collapseDelimiter = false; 083 private boolean isDownloadble = true; 084 085 /** 086 * construct this object with some extra parameters 087 * 088 * @param name 089 * the name of the tableEntity 090 * @param description 091 * the description of the tableEntity 092 * @param caseSensitive 093 * indicates whether this tableEntity is caseSensitive or not. 094 * @param orientation 095 * indicates whether this tableEntity is column or row major 096 * @param numRecords 097 * the number of records in this tableEntity 098 */ 099 public Entity(String id, String name, String description, 100 Boolean caseSensitive, String orientation, int numRecords) { 101 this(id, name, description, null); 102 attributeList = new AttributeList(); 103 if (caseSensitive != null) { 104 this.caseSensitive = caseSensitive; 105 } 106 if (orientation != null) { 107 this.orientation = orientation; 108 } 109 this.numRecords = numRecords; 110 } 111 112 /** 113 * Construct a TableEntity, setting the list of attributes. 114 */ 115 public Entity(String id, String name, String description, 116 AttributeList attributeList) { 117 super(id, name, TABLEENTITY, description); 118 // attributeList = new AttributeList(); 119 fileName = ""; 120 this.attributeList = attributeList; 121 /* 122 * if (attributeList != null) { for (int i=0; i<attributeList.length; 123 * i++) { this.add(attributeList[i]); } } 124 */ 125 this.caseSensitive = false; 126 this.orientation = ""; 127 } 128 129 /** 130 * Add an Attribute to this table. 131 */ 132 public void add(Attribute a) { 133 this.attributeList.add(a); 134 135 // a.setParent(this); 136 } 137 138 /** 139 * Return the unit for this TableEntity 140 */ 141 public Attribute[] getAttributes() { 142 Vector attrVector = attributeList.getAttributes(); 143 Attribute[] atts = new Attribute[attrVector.size()]; 144 return (Attribute[]) attrVector.toArray(atts); 145 } 146 147 /** 148 * indicates whether the tableEntity is caseSensitive or not 149 */ 150 public Boolean getCaseSensitive() { 151 return caseSensitive; 152 } 153 154 /** 155 * gets the orientation of the table entity 156 */ 157 public String getOrientation() { 158 return orientation; 159 } 160 161 /** 162 * gets the number of records in the table entity 163 */ 164 public int getNumRecords() { 165 return numRecords; 166 } 167 168 /** 169 * sets the number of header lines in the entity 170 */ 171 public void setNumHeaderLines(int numHeaderLines) { 172 this.numHeaderLines = numHeaderLines; 173 } 174 175 /** 176 * set the number of footer lines in the entity 177 * 178 * @param numFooterLines 179 */ 180 public void setNumFooterLines(int numFooterLines) { 181 this.numFooterLines = numFooterLines; 182 } 183 184 /** 185 * get the number of header lines in the entity 186 */ 187 public int getNumHeaderLines() { 188 return this.numHeaderLines; 189 } 190 191 /** 192 * get the number of footer lines in the entity 193 * 194 * */ 195 public int getNumFooterLines() { 196 return this.numFooterLines; 197 } 198 199 /** 200 * set the delimiter used with this entity 201 */ 202 public void setDelimiter(String delim) { 203 this.delimiter = delim; 204 } 205 206 /** 207 * get the delimiter used with this entity 208 */ 209 public String getDelimiter() { 210 return this.delimiter; 211 } 212 213 /** 214 * set the record delimiter used with this entity 215 */ 216 public void setRecordDelimiter(String delim) { 217 this.recordDelimiter = delim; 218 } 219 220 /** 221 * get the recordDelimiter used with this entity 222 */ 223 public String getRecordDelimiter() { 224 return this.recordDelimiter; 225 } 226 227 public void setURL(String url) { 228 this.url = url; 229 } 230 231 public String getURL() { 232 return this.url; 233 } 234 235 public void setDBTableName(String DBtableName) { 236 this.DBtableName = DBtableName; 237 } 238 239 public String getDBTableName() { 240 return this.DBtableName; 241 } 242 243 /** 244 * Method to get if this entity can collapse consecutive delimiter 245 * 246 * */ 247 public boolean getCollapseDelimiter() { 248 return this.collapseDelimiter; 249 } 250 251 /** 252 * Method to set collapse delimiter 253 * 254 * @param collapseDelimiter 255 */ 256 public void setCollaplseDelimiter(boolean collapseDelimiter) { 257 this.collapseDelimiter = collapseDelimiter; 258 } 259 260 /* 261 * public String toString() { StringBuffer sb = new StringBuffer(); 262 * sb.append("name: ").append(name).append("\n"); 263 * sb.append("dataType: ").append(dataType).append("\n"); 264 * sb.append("description: ").append(description).append("\n"); 265 * sb.append("numRecords: ").append(numRecords).append("\n"); 266 * sb.append("caseSensitive: ").append(caseSensitive).append("\n"); 267 * sb.append("orientation: ").append(orientation).append("\n"); 268 * sb.append("numHeaderLines: ").append(numHeaderLines).append("\n"); 269 * sb.append("delimiter: ").append(delimiter).append("\n"); 270 * sb.append("attributes: {"); for(int i=0; i<attributes.size(); i++) { 271 * sb.append(((Attribute)attributes.elementAt(i)).toString()); } 272 * sb.append("\n}"); return sb.toString(); } 273 */ 274 275 /** 276 * Returns the fileName. 277 * 278 * @return String 279 */ 280 public String getFileName() { 281 return fileName; 282 } 283 284 /** 285 * Sets the fileName. 286 * 287 * @param fileName 288 * The fileName to set 289 */ 290 public void setFileName(String fileName) { 291 this.fileName = fileName; 292 } 293 294 /** 295 * Serialize the data item in XML format. 296 */ 297 public String toXml() { 298 StringBuffer x = new StringBuffer(); 299 x.append("<table-entity id=\""); 300 x.append(getId()); 301 x.append("\""); 302 if (multiple == true) { 303 x.append(" multiple=\"true\""); 304 } 305 x.append(">\n"); 306 appendElement(x, "entityName", getName()); 307 appendElement(x, "entityType", getDataType()); 308 appendElement(x, "entityDescription", getDefinition()); 309 Attribute[] atts = getAttributes(); 310 for (int i = 0; i < atts.length; i++) { 311 x.append(atts[i].toXml()); 312 } 313 x.append("</table-entity>\n"); 314 315 return x.toString(); 316 } 317 318 /** 319 * Sets the multiple to true. 320 */ 321 public void setMultiple() { 322 this.multiple = true; 323 } 324 325 /** 326 * Returns multiple. 327 * 328 * @return boolean 329 */ 330 public boolean isMultiple() { 331 return multiple; 332 } 333 334 // ----------------------------------------------------------------- 335 // -- DSTableIFace 336 // ----------------------------------------------------------------- 337 338 /** 339 * Returns the name of the table 340 * 341 * @return name as string 342 */ 343 // This is imlemented in the base class 344 // public String getName(); 345 /** 346 * Return the name for this data item. 347 */ 348 public String getMappedName() { 349 return this.DBtableName; 350 } 351 352 /** 353 * Returns a Vector of the fields in the table 354 * 355 * @return vector 356 */ 357 public Vector getFields() { 358 return attributeList.getAttributes(); 359 } 360 361 /** 362 * Returns a the Primary Key Definition for the table 363 * 364 * @return object 365 */ 366 public DSTableKeyIFace getPrimaryKey() { 367 return null; 368 } 369 370 /** 371 * Method to get compression method for distribution file 372 * 373 * @return String 374 */ 375 public String getCompressionMethod() { 376 return this.compressionMethod; 377 } 378 379 /** 380 * Method to set compression method for distribution file 381 * 382 * @param compressionMethod 383 * String 384 */ 385 public void setCompressionMethod(String compressionMethod) { 386 this.compressionMethod = compressionMethod; 387 } 388 389 /** 390 * If this entity for SpatialRaster or SpatialVector 391 * 392 * @return boolean 393 */ 394 public boolean getIsImageEntity() { 395 return this.isImageEntity; 396 } 397 398 /** 399 * Set if this is a Image entity 400 * 401 * @param isImageEntity 402 * boolean 403 */ 404 public void setIsImageEntity(boolean isImageEntity) { 405 this.isImageEntity = isImageEntity; 406 } 407 408 /** 409 * Method get if the data file is zip file 410 * 411 * @return boolean 412 */ 413 public boolean getHasZipDataFile() { 414 return this.hasZipDataFile; 415 } 416 417 /** 418 * Method to set if the data file is zip file 419 * 420 * @param isZipDataFile 421 * boolean 422 */ 423 public void setHasZipDataFile(boolean isZipDataFile) { 424 this.hasZipDataFile = isZipDataFile; 425 } 426 427 /** 428 * Method to get if the data file is gzip 429 * 430 * @return boolean 431 */ 432 public boolean getHasGZipDataFile() { 433 return this.hasGZipDataFile; 434 } 435 436 /** 437 * Method to set if the data file is gzip 438 * 439 * @param hasGZipDataFile 440 * boolean 441 */ 442 public void setHasGZipDataFile(boolean hasGZipDataFile) { 443 this.hasGZipDataFile = hasGZipDataFile; 444 } 445 446 /** 447 * Method to get if this has a tar data file 448 * 449 * @return boolean 450 */ 451 public boolean getHasTarDataFile() { 452 return this.hasTarDataFile; 453 } 454 455 /** 456 * Method to set if this has a tar data file 457 * 458 * @param hasTarDataFile 459 * boolean 460 */ 461 public void setHasTarDataFile(boolean hasTarDataFile) { 462 this.hasTarDataFile = hasTarDataFile; 463 } 464 465 /** 466 * Method to get data cache item associated with this entity 467 * 468 * @return DataCacheObject 469 */ 470 public DataCacheObject getDataCacheObject() { 471 return this.dataCacheObject; 472 } 473 474 /** 475 * Method to set a cache data item associate with this entity 476 * 477 * @param dataCacheObject 478 * DataCachObject 479 */ 480 public void setDataCacheObject(DataCacheObject dataCacheObject) { 481 this.dataCacheObject = dataCacheObject; 482 } 483 484 /** 485 * If data file in this entity is simple delimited 486 * 487 * @return Returns the simpleDelimited. 488 */ 489 public boolean isSimpleDelimited() { 490 return simpleDelimited; 491 } 492 493 /** 494 * @param simpleDelimited 495 * The simpleDelimited to set. 496 */ 497 public void setSimpleDelimited(boolean simpleDelimited) { 498 this.simpleDelimited = simpleDelimited; 499 } 500 501 /** 502 * Get the complex data format array 503 * 504 * @return Returns the dataFormatArray. 505 */ 506 public TextComplexDataFormat[] getDataFormatArray() { 507 return dataFormatArray; 508 } 509 510 /** 511 * Set DataFormatArray 512 * 513 * @param dataFormatArray 514 * The dataFormatArray to set. 515 */ 516 public void setDataFormatArray(TextComplexDataFormat[] dataFormatArray) { 517 this.dataFormatArray = dataFormatArray; 518 } 519 520 /** 521 * @return Returns the physicalLineDelimiter. 522 */ 523 public String getPhysicalLineDelimiter() { 524 return physicalLineDelimiter; 525 } 526 527 /** 528 * @param physicalLineDelimiter 529 * The physicalLineDelimiter to set. 530 */ 531 public void setPhysicalLineDelimiter(String physicalLineDelimiter) { 532 this.physicalLineDelimiter = physicalLineDelimiter; 533 } 534 535 /** 536 * Method to set attribute list 537 * 538 * @param list 539 */ 540 public void setAttributeList(AttributeList list) { 541 this.attributeList = list; 542 } 543 544 /** 545 * Return this entity is downloadable or not. If the value of function 546 * attribute in url is "information", this entity wouldn't be downloaded 547 * 548 * */ 549 public boolean isDownloadable() { 550 return isDownloadble; 551 } 552 553 /** 554 *Set this entity downloadable or not. f the value of function attribute in 555 * url is "information", this entity wouldn't be downloaded 556 * 557 * @param isDownloadable 558 */ 559 public void setDownloadable(boolean isDownloadable) { 560 this.isDownloadble = isDownloadable; 561 } 562 563}