/build.properties/src/com/framedobjects/dashwell/db/DbSchema.java

http://mobiledatanow.googlecode.com/ · Java · 62 lines · 47 code · 9 blank · 6 comment · 11 complexity · a36b9b89de4307c753f7c13e224a2e61 MD5 · raw file

  1. package com.framedobjects.dashwell.db;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.Iterator;
  5. import java.util.TreeMap;
  6. import com.framedobjects.dashwell.db.meta.MetaField;
  7. import com.framedobjects.dashwell.db.meta.MetaRelation;
  8. import com.framedobjects.dashwell.db.meta.MetaTable;
  9. /**
  10. * This class is used to interact directly with the existing database schema.
  11. *
  12. * @author Jens Richnow
  13. *
  14. */
  15. public abstract class DbSchema {
  16. DbConnection dbConn = null;
  17. ArrayList<MetaTable> tables = null;
  18. TreeMap tablesAndFields = null;
  19. TreeMap relations = new TreeMap();
  20. public abstract ArrayList<MetaTable> getTables();
  21. public ArrayList<MetaField> getFieldsForTable(String tableName) {
  22. ArrayList<MetaField> fields = null;
  23. if (tableName != null) {
  24. fields = (ArrayList) tablesAndFields.get(tableName);
  25. }
  26. return fields;
  27. }
  28. public ArrayList<MetaRelation> getRelations() {
  29. ArrayList<MetaRelation> rels = new ArrayList<MetaRelation>();
  30. Collection coll = relations.values();
  31. Iterator iter = coll.iterator();
  32. while (iter.hasNext()) {
  33. rels.add((MetaRelation)iter.next());
  34. }
  35. return rels;
  36. }
  37. public void addRelation(MetaRelation relation) {
  38. if (relation != null
  39. && !this.relations.containsKey(relation.getQualifiedName())) {
  40. this.relations.put(relation.getQualifiedName(), relation);
  41. }
  42. }
  43. public void removeRelation(MetaRelation relation) {
  44. if (relation != null) {
  45. this.removeRelationByName(relation.getQualifiedName());
  46. }
  47. }
  48. public void removeRelationByName(String qualifiedName) {
  49. if (qualifiedName != null && this.relations.containsKey(qualifiedName)) {
  50. this.relations.remove(qualifiedName);
  51. }
  52. }
  53. }