2323import org .labkey .api .audit .query .DefaultAuditTypeTable ;
2424import org .labkey .api .collections .CaseInsensitiveHashMap ;
2525import org .labkey .api .data .AbstractTableInfo ;
26- import org .labkey .api .data .ColumnInfo ;
2726import org .labkey .api .data .Container ;
2827import org .labkey .api .data .ContainerFilter ;
2928import org .labkey .api .data .ContainerManager ;
3029import org .labkey .api .data .DbSchema ;
3130import org .labkey .api .data .DbSchemaType ;
3231import org .labkey .api .data .DbScope ;
3332import org .labkey .api .data .MutableColumnInfo ;
34- import org .labkey .api .data .PropertyStorageSpec ;
3533import org .labkey .api .data .SQLFragment ;
36- import org .labkey .api .data .SchemaTableInfo ;
3734import org .labkey .api .data .SqlExecutor ;
38- import org .labkey .api .data .TableChange ;
3935import org .labkey .api .data .TableInfo ;
4036import org .labkey .api .dataiterator .DataIterator ;
4137import org .labkey .api .dataiterator .ExistingRecordDataIterator ;
4440import org .labkey .api .exp .api .ExperimentService ;
4541import org .labkey .api .exp .api .StorageProvisioner ;
4642import org .labkey .api .exp .property .Domain ;
47- import org .labkey .api .exp .property .DomainKind ;
4843import org .labkey .api .exp .property .DomainProperty ;
4944import org .labkey .api .exp .property .PropertyService ;
5045import org .labkey .api .gwt .client .DefaultValueType ;
5550import org .labkey .api .security .User ;
5651import org .labkey .api .util .DateUtil ;
5752import org .labkey .api .util .PageFlowUtil ;
58- import org .labkey .api .util .Pair ;
5953import org .labkey .api .view .ActionURL ;
6054
6155import java .sql .Time ;
6256import java .util .Collection ;
6357import java .util .Collections ;
6458import java .util .Date ;
65- import java .util .HashSet ;
6659import java .util .LinkedHashMap ;
6760import java .util .LinkedHashSet ;
6861import java .util .List ;
@@ -90,18 +83,17 @@ public abstract class AbstractAuditTypeProvider implements AuditTypeProvider
9083 public static final String COLUMN_NAME_TRANSACTION_ID = "TransactionID" ;
9184 public static final String COLUMN_NAME_DATA_CHANGES = "DataChanges" ;
9285
93- final AbstractAuditDomainKind _domainKind ;
94-
86+ private final AbstractAuditDomainKind _domainKind ;
9587
88+ @ Deprecated // Call the other constructor and stop overriding getDomainKind()
9689 public AbstractAuditTypeProvider ()
9790 {
9891 this (null );
9992 }
10093
10194 public AbstractAuditTypeProvider (@ NotNull AbstractAuditDomainKind domainKind )
10295 {
103- // TODO : consolidate domain kind initialization to either this constructor or to override
104- // getDomainKind.
96+ // TODO: consolidate domain kind initialization to this constructor and stop overriding getDomainKind()
10597 _domainKind = domainKind ;
10698 // Register the DomainKind
10799 PropertyService .get ().registerDomainKind (getDomainKind ());
@@ -115,10 +107,18 @@ protected AbstractAuditDomainKind getDomainKind()
115107 return _domainKind ;
116108 }
117109
110+ // Expose the domain kind to AbstractAuditDomainKind$TestCase without touching every subclass
111+ public AbstractAuditDomainKind getAuditDomainKind ()
112+ {
113+ return getDomainKind ();
114+ }
115+
118116 @ Override
119- public void initializeProvider (User user )
117+ public final void initializeProvider (User user )
120118 {
121119 AbstractAuditDomainKind domainKind = getDomainKind ();
120+ domainKind .validate ();
121+
122122 Domain domain = getDomain (true );
123123
124124 // if the domain doesn't exist, create it
@@ -145,52 +145,6 @@ public void initializeProvider(User user)
145145 ensureProperties (user , domain );
146146 }
147147
148- private void updateIndices (Domain domain , AbstractAuditDomainKind domainKind )
149- {
150- if (domain .getStorageTableName () == null )
151- return ;
152-
153- // Issue 50059, acquiring the schema table info this way ensures that the domain fields are properly fixed up. See ProvisionedSchemaOptions.
154- SchemaTableInfo schemaTableInfo = StorageProvisioner .get ().getSchemaTableInfo (domain );
155- if (schemaTableInfo != null )
156- {
157- Map <String , Pair <TableInfo .IndexType , List <ColumnInfo >>> existingIndices = schemaTableInfo .getAllIndices ();
158- Set <PropertyStorageSpec .Index > newIndices = new HashSet <>(domainKind .getPropertyIndices (domain ));
159- Set <String > toRemove = new HashSet <>();
160- for (String name : existingIndices .keySet ())
161- {
162- if (existingIndices .get (name ).first == TableInfo .IndexType .Primary )
163- continue ;
164- Pair <TableInfo .IndexType , List <ColumnInfo >> columnIndex = existingIndices .get (name );
165- String [] columnNames = new String [columnIndex .second .size ()];
166- for (int i = 0 ; i < columnIndex .second .size (); i ++)
167- {
168- columnNames [i ] = columnIndex .second .get (i ).getColumnName ();
169- }
170- PropertyStorageSpec .Index existingIndex = new PropertyStorageSpec .Index (columnIndex .first == TableInfo .IndexType .Unique , columnNames );
171- boolean foundIt = false ;
172- for (PropertyStorageSpec .Index propertyIndex : newIndices )
173- {
174- if (PropertyStorageSpec .Index .isSameIndex (propertyIndex , existingIndex ))
175- {
176- foundIt = true ;
177- newIndices .remove (propertyIndex );
178- break ;
179- }
180- }
181-
182- if (!foundIt )
183- toRemove .add (name );
184- }
185-
186- if (!toRemove .isEmpty ())
187- StorageProvisioner .get ().dropTableIndices (domain , toRemove );
188- if (!newIndices .isEmpty ())
189- StorageProvisioner .get ().addTableIndices (domain , newIndices , TableChange .IndexSizeMode .Normal );
190- }
191- }
192-
193-
194148 // NOTE: Changing the name of an existing PropertyDescriptor will lose data!
195149 private void ensureProperties (User user , Domain domain )
196150 {
@@ -254,7 +208,11 @@ private void ensureProperties(User user, Domain domain)
254208 domain .save (user );
255209 }
256210
257- updateIndices (domain , domainKind );
211+ assert domain .getStorageTableName () != null ;
212+ assert domain .getDomainKind () != null ;
213+ assert domain .getDomainKind ().getClass ().equals (domainKind .getClass ());
214+
215+ StorageProvisioner .get ().ensureTableIndices (domain );
258216 transaction .commit ();
259217 }
260218 catch (ChangePropertyDescriptorException e )
@@ -301,7 +259,7 @@ public final Domain getDomain()
301259 @ Override
302260 public final Domain getDomain (boolean forUpdate )
303261 {
304- DomainKind domainKind = getDomainKind ();
262+ AbstractAuditDomainKind domainKind = getDomainKind ();
305263
306264 String domainURI = domainKind .generateDomainURI (QUERY_SCHEMA_NAME , getEventName (), getDomainContainer (), null );
307265
0 commit comments