Rename @Index(columns) to @Index(fields) and do the proper translation to column name during table creation / migration.
This commit is contained in:
@@ -548,10 +548,6 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
ctx.invoke(new Modifier() {
|
ctx.invoke(new Modifier() {
|
||||||
public int invoke (Connection conn, DatabaseLiaison liaison) throws SQLException {
|
public int invoke (Connection conn, DatabaseLiaison liaison) throws SQLException {
|
||||||
// create the table
|
// create the table
|
||||||
String[] columns = new String[_columnFields.length];
|
|
||||||
for (int ii = 0; ii < columns.length; ii ++) {
|
|
||||||
columns[ii] = _fields.get(_columnFields[ii]).getColumnName();
|
|
||||||
}
|
|
||||||
String[] primaryKeyColumns = null;
|
String[] primaryKeyColumns = null;
|
||||||
if (_pkColumns != null) {
|
if (_pkColumns != null) {
|
||||||
primaryKeyColumns = new String[_pkColumns.size()];
|
primaryKeyColumns = new String[_pkColumns.size()];
|
||||||
@@ -559,18 +555,23 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
primaryKeyColumns[ii] = _pkColumns.get(ii).getColumnName();
|
primaryKeyColumns[ii] = _pkColumns.get(ii).getColumnName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
liaison.createTableIfMissing(conn, getTableName(), columns, fDeclarations,
|
liaison.createTableIfMissing(
|
||||||
uniqueConCols, primaryKeyColumns);
|
conn, getTableName(), fieldsToColumns(_columnFields),
|
||||||
|
fDeclarations, uniqueConCols, primaryKeyColumns);
|
||||||
|
|
||||||
// add its indexen
|
// add its indexen
|
||||||
for (Index idx : indexen) {
|
for (Index idx : indexen) {
|
||||||
liaison.addIndexToTable(
|
liaison.addIndexToTable(
|
||||||
conn, getTableName(), idx.columns(),
|
conn, getTableName(), fieldsToColumns(idx.fields()),
|
||||||
getTableName() + "_" + idx.name(), idx.unique());
|
getTableName() + "_" + idx.name(), idx.unique());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// its key generator
|
||||||
if (_keyGenerator != null) {
|
if (_keyGenerator != null) {
|
||||||
_keyGenerator.init(conn, liaison);
|
_keyGenerator.init(conn, liaison);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// and its full text search indexes
|
||||||
for (FullTextIndex fti : _fullTextIndexes.values()) {
|
for (FullTextIndex fti : _fullTextIndexes.values()) {
|
||||||
builder.addFullTextSearch(conn, DepotMarshaller.this, fti);
|
builder.addFullTextSearch(conn, DepotMarshaller.this, fti);
|
||||||
}
|
}
|
||||||
@@ -702,7 +703,8 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
ctx.invoke(new Modifier() {
|
ctx.invoke(new Modifier() {
|
||||||
public int invoke (Connection conn, DatabaseLiaison liaison) throws SQLException {
|
public int invoke (Connection conn, DatabaseLiaison liaison) throws SQLException {
|
||||||
liaison.addIndexToTable(
|
liaison.addIndexToTable(
|
||||||
conn, getTableName(), index.columns(), ixName, index.unique());
|
conn, getTableName(), fieldsToColumns(index.fields()),
|
||||||
|
ixName, index.unique());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -764,6 +766,21 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// translate an array of field names to an array of column names
|
||||||
|
protected String[] fieldsToColumns (String[] fields)
|
||||||
|
{
|
||||||
|
String[] columns = new String[fields.length];
|
||||||
|
for (int ii = 0; ii < columns.length; ii ++) {
|
||||||
|
FieldMarshaller<?> fm = _fields.get(fields[ii]);
|
||||||
|
if (fm == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Unknown field on record [field=" + fields[ii] + ", pClass=" + _pclass + "]");
|
||||||
|
}
|
||||||
|
columns[ii] = fm.getColumnName();
|
||||||
|
}
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that there are no database columns for which we no longer have Java fields.
|
* Checks that there are no database columns for which we no longer have Java fields.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ public @interface Index
|
|||||||
/** Does this index enforce a uniqueness constraint? */
|
/** Does this index enforce a uniqueness constraint? */
|
||||||
boolean unique () default false;
|
boolean unique () default false;
|
||||||
|
|
||||||
/** Defines the columns on which the index operates. */
|
/** Defines the fields on which the index operates. */
|
||||||
String[] columns () default {};
|
String[] fields () default {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user