@ Override public void initialize ( ) { if ( databaseConnection == null ) { return ; // Supposedly we initialized already. } if ( LOG . isDebugging ( ) ) { LOG . debugFine ( "Loading data from database connection." ) ; } MultipleObjectsBundle bundle = databaseConnection . loadData ( ) ; // Run at most once. databaseConnection = null ; // Find DBIDs for bundle { DBIDs bids = bundle . getDBIDs ( ) ; if ( bids instanceof ArrayStaticDBIDs ) { this . ids = ( ArrayStaticDBIDs ) bids ; } else if ( bids == null ) { this . ids = DBIDUtil . generateStaticDBIDRange ( bundle . dataLength ( ) ) ; } else { this . ids = ( ArrayStaticDBIDs ) DBIDUtil . makeUnmodifiable ( DBIDUtil . ensureArray ( bids ) ) ; } } // Replace id representation (it would be nicer if we would not need // DBIDView at all) this . idrep = new DBIDView ( this . ids ) ; relations . add ( this . idrep ) ; getHierarchy ( ) . add ( this , idrep ) ; DBIDArrayIter it = this . ids . iter ( ) ; int numrel = bundle . metaLength ( ) ; for ( int i = 0 ; i < numrel ; i ++ ) { SimpleTypeInformation < ? > meta = bundle . meta ( i ) ; @ SuppressWarnings ( "unchecked" ) SimpleTypeInformation < Object > ometa = ( SimpleTypeInformation < Object > ) meta ; WritableDataStore < Object > store = DataStoreUtil . makeStorage ( ids , DataStoreFactory . HINT_DB , ometa . getRestrictionClass ( ) ) ; for ( it . seek ( 0 ) ; it . valid ( ) ; it . advance ( ) ) { store . put ( it , bundle . data ( it . getOffset ( ) , i ) ) ; } Relation < ? > relation = new MaterializedRelation <> ( ometa , ids , null , store ) ; relations . add ( relation ) ; getHierarchy ( ) . add ( this , relation ) ; // Try to add indexes where appropriate for ( IndexFactory < ? > factory : indexFactories ) { if ( factory . getInputTypeRestriction ( ) . isAssignableFromType ( ometa ) ) { @ SuppressWarnings ( "unchecked" ) final IndexFactory < Object > ofact = ( IndexFactory < Object > ) factory ; @ SuppressWarnings ( "unchecked" ) final Relation < Object > orep = ( Relation < Object > ) relation ; final Index index = ofact . instantiate ( orep ) ; Duration duration = LOG . isStatistics ( ) ? LOG . newDuration ( index . getClass ( ) . getName ( ) + ".construction" ) . begin ( ) : null ; index . initialize ( ) ; if ( duration != null ) { LOG . statistics ( duration . end ( ) ) ; } getHierarchy ( ) . add ( relation , index ) ; } } } // fire insertion event eventManager . fireObjectsInserted ( ids ) ; }
Initialize the database by getting the initial data from the database connection .