1 21 package oracle.toplink.essentials.tools.schemaframework; 23 24 import java.io.*; 25 import oracle.toplink.essentials.internal.helper.*; 26 import oracle.toplink.essentials.exceptions.*; 27 import oracle.toplink.essentials.queryframework.*; 28 import oracle.toplink.essentials.internal.sessions.AbstractSession; 29 30 40 public abstract class DatabaseObjectDefinition implements Cloneable , Serializable { 41 public String name; 42 public String qualifier; 43 44 public DatabaseObjectDefinition() { 45 this.name = ""; 46 this.qualifier = ""; 47 } 48 49 53 public abstract Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException; 54 55 59 public abstract Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException; 60 61 64 public Object clone() { 65 try { 66 return super.clone(); 67 } catch (CloneNotSupportedException impossible) { 68 return null; 69 } 70 } 71 72 77 public void createObject(AbstractSession session, Writer schemaWriter) throws TopLinkException { 78 if (schemaWriter == null) { 79 this.createOnDatabase(session); 80 } else { 81 this.buildCreationWriter(session, schemaWriter); 82 } 83 } 84 85 89 public void createOnDatabase(AbstractSession session) throws TopLinkException { 90 session.executeNonSelectingCall(new SQLCall(buildCreationWriter(session, new StringWriter()).toString())); 91 } 92 93 97 public void dropFromDatabase(AbstractSession session) throws TopLinkException { 98 session.executeNonSelectingCall(new SQLCall(buildDeletionWriter(session, new StringWriter()).toString())); 99 } 100 101 106 public void dropObject(AbstractSession session, Writer schemaWriter) throws TopLinkException { 107 if (schemaWriter == null) { 108 this.dropFromDatabase(session); 109 } else { 110 buildDeletionWriter(session, schemaWriter); 111 } 112 } 113 114 119 public String getFullName() { 120 if (getQualifier().equals("")) { 121 return getName(); 122 } else { 123 return getQualifier() + "." + getName(); 124 } 125 } 126 127 132 public String getName() { 133 return name; 134 } 135 136 141 public String getQualifier() { 142 return qualifier; 143 } 144 145 150 public void setName(String name) { 151 this.name = name; 152 } 153 154 159 public void setQualifier(String qualifier) { 160 this.qualifier = qualifier; 161 } 162 163 public String toString() { 164 return Helper.getShortClassName(getClass()) + "(" + getFullName() + ")"; 165 } 166 } 167 | Popular Tags |