1 56 57 package org.objectstyle.cayenne.map; 58 59 import org.objectstyle.cayenne.util.XMLEncoder; 60 61 69 70 public class DbKeyGenerator extends MapObject { 71 public static final String ORACLE_TYPE = "ORACLE"; 72 public static final String NAMED_SEQUENCE_TABLE_TYPE = "NAMED_SEQUENCE_TABLE"; 73 74 private String generatorType; 75 private Integer keyCacheSize; 76 private String generatorName; 77 78 public DbKeyGenerator() { 79 } 80 81 86 public void encodeAsXML(XMLEncoder encoder) { 87 88 String type = getGeneratorType(); 89 if (type == null) { 90 return; 91 } 92 93 encoder.println("<db-key-generator>"); 94 encoder.indent(1); 95 96 encoder.print("<db-generator-type>"); 97 encoder.print(type); 98 encoder.println("</db-generator-type>"); 99 100 String name = getGeneratorName(); 101 if (name != null) { 102 encoder.print("<db-generator-name>"); 103 encoder.print(name); 104 encoder.println("</db-generator-name>"); 105 } 106 107 Integer cacheSize = getKeyCacheSize(); 108 if (cacheSize != null) { 109 encoder.print("<db-key-cache-size>"); 110 encoder.print(String.valueOf(cacheSize)); 111 encoder.println("</db-key-cache-size>"); 112 } 113 114 encoder.indent(-1); 115 encoder.println("</db-key-generator>"); 116 } 117 118 public DbEntity getDbEntity() { 119 return (DbEntity) getParent(); 120 } 121 122 public void setDbEntity(DbEntity entity) { 123 setParent(entity); 124 } 125 126 public void setGeneratorType(String generatorType) { 127 this.generatorType = generatorType; 128 if (this.generatorType != null) { 129 this.generatorType = this.generatorType.trim().toUpperCase(); 130 if (!(ORACLE_TYPE.equals(this.generatorType) 131 || NAMED_SEQUENCE_TABLE_TYPE.equals(this.generatorType))) 132 this.generatorType = null; 133 } 134 } 135 136 public String getGeneratorType() { 137 return generatorType; 138 } 139 140 public void setKeyCacheSize(Integer keyCacheSize) { 141 this.keyCacheSize = keyCacheSize; 142 if (this.keyCacheSize != null && this.keyCacheSize.intValue() < 1) { 143 this.keyCacheSize = null; 144 } 145 } 146 147 public Integer getKeyCacheSize() { 148 return keyCacheSize; 149 } 150 151 public void setGeneratorName(String generatorName) { 152 this.generatorName = generatorName; 153 if (this.generatorName != null) { 154 this.generatorName = this.generatorName.trim(); 155 if (this.generatorName.length() == 0) 156 this.generatorName = null; 157 } 158 } 159 160 public String getGeneratorName() { 161 return generatorName; 162 } 163 164 public String toString() { 165 return "{Type=" 166 + generatorType 167 + ", Name=" 168 + generatorName 169 + ", Cache=" 170 + keyCacheSize 171 + "}"; 172 } 173 } | Popular Tags |