public void updateRefs ( boolean assetImport ) throws SQLException , IOException { List < AssetRef > refs = getCurrentRefs ( ) ; if ( refs == null || refs . isEmpty ( ) ) getOut ( ) . println ( "Skipping ASSET_REF table insert/update due to empty current assets" ) ; else { String select = "select name, ref from ASSET_REF where definition_id = ?" ; try ( Connection conn = getDbConnection ( ) ; PreparedStatement stmt = conn . prepareStatement ( select ) ) { for ( AssetRef ref : refs ) { stmt . setLong ( 1 , ref . getDefinitionId ( ) ) ; try ( ResultSet rs = stmt . executeQuery ( ) ) { // DO NOT update existing refs with newer commitID // Doing so can obliterate previous commitID from ASSET_REF table // which will prevent auto-import detection in cluster envs if ( ! rs . next ( ) ) { String insert = "insert into ASSET_REF (definition_id, name, ref) values (?, ?, ?)" ; try ( PreparedStatement insertStmt = conn . prepareStatement ( insert ) ) { insertStmt . setLong ( 1 , ref . getDefinitionId ( ) ) ; insertStmt . setString ( 2 , ref . getName ( ) ) ; insertStmt . setString ( 3 , ref . getRef ( ) ) ; insertStmt . executeUpdate ( ) ; if ( ! conn . getAutoCommit ( ) ) conn . commit ( ) ; } } } } if ( assetImport ) updateRefValue ( ) ; } } }
Update refs in db .