[#2321] Implement various Key.toString() methods

This commit is contained in:
Lukas Eder 2013-03-08 13:59:19 +01:00
parent f11aef3c4a
commit 6b215bbb31
2 changed files with 55 additions and 0 deletions

View File

@ -194,4 +194,37 @@ class ReferenceImpl<R extends Record, O extends Record> extends AbstractKey<R> i
throw new DetachedException("Supply at least one attachable record");
}
}
// -------------------------------------------------------------------------
// XXX: Object API
// -------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FOREIGN KEY (");
String s1 = "";
for (Field<?> field : getFields()) {
sb.append(s1);
sb.append(field);
s1 = ", ";
}
sb.append(") REFERENCES ");
sb.append(key.getTable());
sb.append("(");
String s2 = "";
for (Field<?> field : getFields()) {
sb.append(s2);
sb.append(field);
s2 = ", ";
}
sb.append(")");
return sb.toString();
}
}

View File

@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Record;
import org.jooq.Table;
@ -67,4 +68,25 @@ class UniqueKeyImpl<R extends Record> extends AbstractKey<R> implements UniqueKe
public final List<ForeignKey<?, R>> getReferences() {
return Collections.unmodifiableList(references);
}
// -------------------------------------------------------------------------
// XXX: Object API
// -------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("UNIQUE KEY (");
String s1 = "";
for (Field<?> field : getFields()) {
sb.append(s1);
sb.append(field);
s1 = ", ";
}
sb.append(")");
return sb.toString();
}
}