Merge lp:~mmcm/akiban-client-tools/generated-always into lp:~akiban-technologies/akiban-client-tools/trunk

Proposed by Mike McMahon
Status: Merged
Approved by: Nathan Williams
Approved revision: 23
Merged at revision: 23
Proposed branch: lp:~mmcm/akiban-client-tools/generated-always
Merge into: lp:~akiban-technologies/akiban-client-tools/trunk
Diff against target: 49 lines (+22/-3)
1 file modified
src/main/java/com/akiban/client/dump/DumpClient.java (+22/-3)
To merge this branch: bzr merge lp:~mmcm/akiban-client-tools/generated-always
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Review via email: mp+158462@code.launchpad.net

Description of the change

Change how GENERATED ALWAYS gets dumped with data.

GENERATED BY DEFAULT is reasonable: it just puts the current sequence state (presumably after all the data) into the initial definition.

GENERATED ALWAYS needs to arrange for the actual values to get loaded and only then so something similar, via ALTER TABLE ALTER COLUMN.

A test can be added once the server stops ignoring the auto-increment clause in the alter.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

Looks good.

Will add a story for test.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main/java/com/akiban/client/dump/DumpClient.java'
2--- src/main/java/com/akiban/client/dump/DumpClient.java 2013-02-19 01:29:11 +0000
3+++ src/main/java/com/akiban/client/dump/DumpClient.java 2013-04-11 19:46:30 +0000
4@@ -37,6 +37,7 @@
5 private Map<String,Map<String,Table>> schemas = new TreeMap<String,Map<String,Table>>();
6 private Map<String, Map<String,Sequence>> sequences = new TreeMap<String,Map<String, Sequence>>();
7 private Map<String,Map<String,View>> views = new TreeMap<String,Map<String, View>>();
8+ private Queue<String> afterDataStatements = new ArrayDeque<String>();
9 private int insertMaxRowCount = DEFAULT_INSERT_MAX_ROW_COUNT;
10 private String defaultSchema = null;
11 private Writer output;
12@@ -464,6 +465,13 @@
13 }
14 if (dumpData) {
15 dumpData(table);
16+ if (!afterDataStatements.isEmpty()) {
17+ String stmt;
18+ while ((stmt = afterDataStatements.poll()) != null) {
19+ output.write(stmt);
20+ }
21+ output.write(NL);
22+ }
23 }
24 }
25
26@@ -557,9 +565,20 @@
27 String sequenceSchema = rs.getString(9);
28 String sequenceName = rs.getString(10);
29 Sequence seq = sequences.get(sequenceSchema).get(sequenceName);
30- sql.append(" GENERATED ").append(identityGenerate);
31- sql.append(" AS IDENTITY (START WITH ").append(seq.startWith);
32- sql.append(", INCREMENT BY ").append(seq.incrementBy).append (")");
33+ String generated = " GENERATED " + identityGenerate +
34+ " AS IDENTITY (START WITH " + seq.startWith +
35+ ", INCREMENT BY " + seq.incrementBy + ")";
36+ if (dumpData && "ALWAYS".equals(identityGenerate)) {
37+ StringBuilder sql2 = new StringBuilder("ALTER TABLE ");
38+ qualifiedName(table, sql2);
39+ sql2.append(" ALTER COLUMN ");
40+ identifier(column, sql2, false);
41+ sql2.append(" SET").append(generated).append(";").append(NL);
42+ afterDataStatements.add(sql2.toString());
43+ }
44+ else {
45+ sql.append(generated);
46+ }
47 }
48
49 if (pkey != null) {

Subscribers

People subscribed via source and target branches