Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/DbSchemaManager.java
DbSchemaManager.java | ||
---|---|---|
44 | 44 |
import java.sql.SQLException; |
45 | 45 |
import java.sql.Statement; |
46 | 46 |
|
47 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
|
|
47 |
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException;
|
|
48 | 48 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
49 | 49 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
50 | 50 |
import com.iver.cit.gvsig.fmap.drivers.XTypes; |
51 | 51 |
|
52 | 52 |
public class DbSchemaManager implements IDbSchemaManager { |
53 |
|
|
53 |
|
|
54 | 54 |
private Connection conn = null; |
55 |
|
|
55 |
|
|
56 | 56 |
public DbSchemaManager(Connection conn) |
57 | 57 |
{ |
58 | 58 |
this.conn = conn; |
... | ... | |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
public void createSchema(ITableDefinition dbLayerDef) |
66 |
throws EditionException { |
|
66 |
throws SchemaEditionException {
|
|
67 | 67 |
String sqlCreate = "CREATE TABLE " + dbLayerDef.getName() |
68 | 68 |
+ " ( "; |
69 | 69 |
int j=0; |
... | ... | |
71 | 71 |
for (int i = 0; i < fieldsDescr.length; i++) { |
72 | 72 |
int fieldType = fieldsDescr[i].getFieldType(); |
73 | 73 |
String strType = XTypes.fieldTypeToString(fieldType); |
74 |
|
|
74 |
|
|
75 | 75 |
if (j == 0) |
76 | 76 |
sqlCreate = sqlCreate + fieldsDescr[i].getFieldName() + " " + strType; |
77 | 77 |
else |
... | ... | |
80 | 80 |
j++; |
81 | 81 |
} |
82 | 82 |
sqlCreate = sqlCreate + ");"; |
83 |
|
|
83 |
|
|
84 | 84 |
try { |
85 | 85 |
Statement st = conn.createStatement(); |
86 | 86 |
st.execute(sqlCreate); |
87 | 87 |
} catch (SQLException e) { |
88 |
e.printStackTrace(); |
|
89 |
throw new EditionException(e); |
|
88 |
throw new SchemaEditionException(dbLayerDef.getName(),e); |
|
90 | 89 |
} |
91 | 90 |
|
92 | 91 |
} |
93 | 92 |
|
94 |
public void removeSchema(String name) throws EditionException { |
|
93 |
public void removeSchema(String name) throws SchemaEditionException {
|
|
95 | 94 |
String sqlDrop = "DROP TABLE " + name; |
96 | 95 |
try { |
97 | 96 |
Statement st = conn.createStatement(); |
98 | 97 |
st.execute(sqlDrop); |
99 | 98 |
} catch (SQLException e) { |
100 |
e.printStackTrace(); |
|
101 |
throw new EditionException(e); |
|
99 |
throw new SchemaEditionException(name,e); |
|
102 | 100 |
} |
103 | 101 |
|
104 | 102 |
} |
105 | 103 |
|
106 |
public void renameSchema(String antName, String newName) throws EditionException { |
|
104 |
public void renameSchema(String antName, String newName) throws SchemaEditionException {
|
|
107 | 105 |
String sqlAlter = "ALTER TABLE " + antName + " RENAME TO " + newName; |
108 | 106 |
try { |
109 | 107 |
Statement st = conn.createStatement(); |
110 | 108 |
st.execute(sqlAlter); |
111 | 109 |
} catch (SQLException e) { |
112 |
e.printStackTrace(); |
|
113 |
throw new EditionException(e); |
|
110 |
throw new SchemaEditionException(antName,e); |
|
114 | 111 |
} |
115 |
|
|
116 | 112 |
|
113 |
|
|
117 | 114 |
} |
118 | 115 |
|
119 | 116 |
} |
Also available in: Unified diff