Order the primary key columns by the @Column.id()

Since 1.6 we created compound primary key indexes ordered by
depth-first traversal of the primary key using the alphabetical order
of fields. This created many compound primary key indexes with a
wrong column order which lead to poor performance in some Gerrit
database queries which relied on using a prefix of the primary key
index columns.

Up to and including 1.4 we use the depth first traversal of the
primary key, using field declaration order. This worked well with
Java 6 but had to be fixed when switching to Java 7 and a new ordering
was imposed (between 1.4 and 1.6).

To fix the issue of the column order order the primary key fields
by:
- depth first traversal
- @Column annotated fields before non-annotated
- @Column annotated fields ordered by the @Column.id()
- non-annotated fields ordered alphabetically

Change-Id: Icd5a644587c6af442172797e0a52a7eea4512e79
2 files changed