View Javadoc
1 package com.bonevich.erj.db; 2 3 import com.bonevich.erj.model.*; 4 5 import java.util.Iterator; 6 7 /*** 8 * ClassDescription 9 * 10 * @author jbonevic 11 * @version $Id: OracleGenerator.html,v 1.1 2009/03/07 17:55:45 jbonevic Exp $ 12 */ 13 public class OracleGenerator extends AbstractDdlGenerator 14 { 15 private StringBuffer _buf; 16 17 /*** 18 * Constructor for PsotgresqlGenerator. 19 */ 20 public OracleGenerator() 21 { 22 super(); 23 } 24 25 /*** 26 * @see com.bonevich.erj.db.IDdlGenerator#cloneWithNewName(String) 27 */ 28 public IDdlGenerator cloneWithNewName(String name) 29 { 30 return cloneWithNewName(name, new OracleGenerator()); 31 } 32 33 /*** 34 * @see com.bonevich.erj.db.IDdlGenerator#generate(Schema) 35 */ 36 public String generate(Schema model) 37 { 38 _buf = new StringBuffer(); 39 40 if (isOptionSet("drop_tables")) 41 { 42 Iterator dtables = model.getRelationIterator(); 43 while (dtables.hasNext()) 44 { 45 addDropTableStatement((Relation) dtables.next()); 46 } 47 } 48 49 if (isOptionSet("create_tables")) 50 { 51 Iterator ctables = model.getRelationIterator(); 52 while (ctables.hasNext()) 53 { 54 addCreateTableStatement((Relation) ctables.next()); 55 } 56 } 57 58 return _buf.toString(); 59 } 60 61 /*** 62 * 63 */ 64 private void addCreateTableStatement(Relation relation) 65 { 66 //_buf.append(); 67 _buf.append(CREATE_TABLE); 68 _buf.append(WHITE_SPACE); 69 _buf.append(relation.getIdentifier()); 70 _buf.append(WHITE_SPACE); 71 _buf.append(OPEN_PAREN); 72 _buf.append(NEW_LINE); 73 74 Iterator itr = relation.getAttributeIterator(); 75 while (itr.hasNext()) 76 { 77 addColumnFragment((Attribute) itr.next()); 78 } 79 80 _buf.append(CLOSE_PAREN); 81 _buf.append(SEMI_COLON); 82 _buf.append(NEW_LINE); 83 _buf.append(NEW_LINE); 84 } 85 86 /*** 87 * 88 */ 89 private void addColumnFragment(Attribute attr) 90 { 91 _buf.append(TAB); 92 _buf.append(attr.getIdentifier()); 93 _buf.append(WHITE_SPACE); 94 AttributeType type = attr.getType(); 95 _buf.append(type.getName()); 96 if (type instanceof DataType && ((DataType)type).takesDescriptor()) 97 { 98 _buf.append(OPEN_PAREN); 99 _buf.append(((DataType)type).getDescriptor()); 100 _buf.append(CLOSE_PAREN); 101 } 102 _buf.append(WHITE_SPACE); 103 _buf.append(attr.getConstraint().toString()); 104 _buf.append(COMMA); 105 _buf.append(NEW_LINE); 106 } 107 108 /*** 109 * 110 */ 111 private void addIndexFragment(KeyConstraint key) 112 { 113 } 114 115 /*** 116 * 117 */ 118 private void addConstraintFragment(AttributeConstraint constraint) 119 { 120 } 121 122 /*** 123 * 124 */ 125 private void addCreateIndexStatement(KeyConstraint key) 126 { 127 } 128 129 /*** 130 * 131 */ 132 private void addDropTableStatement(Relation relation) 133 { 134 _buf.append(DROP_TABLE); 135 _buf.append(WHITE_SPACE); 136 _buf.append(relation.getIdentifier()); 137 _buf.append(SEMI_COLON); 138 _buf.append(NEW_LINE); 139 _buf.append(NEW_LINE); 140 } 141 142 }

This page was automatically generated by Maven