18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2008, 2013 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2008, 2014 , Oracle and/or its affiliates. All rights reserved.
22
22
*/
23
23
24
24
package org .opensolaris .opengrok .history ;
@@ -103,6 +103,9 @@ class JDBCHistoryCache implements HistoryCache {
103
103
private static final PreparedQuery GET_LAST_MODIFIED_TIMES =
104
104
new PreparedQuery (getQuery ("getLastModifiedTimes" ));
105
105
106
+ private static final PreparedQuery GET_FILEMOVES_COUNT =
107
+ new PreparedQuery (getQuery ("getFilemovesCount" ));
108
+
106
109
/**
107
110
* The number of times to retry an operation that failed in a way that
108
111
* indicates that it may succeed if it's tried again.
@@ -516,6 +519,8 @@ private static String truncate(String str, int length) {
516
519
*/
517
520
private static final PreparedQuery GET_FILE_HISTORY =
518
521
new PreparedQuery (getQuery ("getFileHistory" ));
522
+ private static final PreparedQuery GET_FILE_HISTORY_FOLDED =
523
+ new PreparedQuery (getQuery ("getFileHistoryFolded" ));
519
524
520
525
/**
521
526
* Statement that gets the history for all files matching a pattern in the
@@ -550,6 +555,31 @@ public History get(File file, Repository repository, boolean withFiles)
550
555
}
551
556
}
552
557
558
+ /**
559
+ * Get the number of rows in the FILEMOVES table. This is used as a
560
+ * workaround/optimization since JavaDB cannot currently handle the
561
+ * GET_FILE_HISTORY very well.
562
+ * @return number of rows in the FILEMOVES table
563
+ * @throws SQLException
564
+ */
565
+ private int getFilemovesCount () throws SQLException {
566
+ final ConnectionResource conn ;
567
+ conn = connectionManager .getConnectionResource ();
568
+
569
+ try {
570
+ final PreparedStatement cntPS = conn .getStatement (GET_FILEMOVES_COUNT );
571
+ try (ResultSet rs = cntPS .executeQuery ()) {
572
+ if (rs .next ()) {
573
+ return rs .getInt (1 );
574
+ }
575
+ }
576
+ } finally {
577
+ connectionManager .releaseConnection (conn );
578
+ }
579
+
580
+ return -1 ;
581
+ }
582
+
553
583
/**
554
584
* Helper for {@link #get(File, Repository)}.
555
585
*/
@@ -561,6 +591,8 @@ private History getHistory(
561
591
final ArrayList <HistoryEntry > entries = new ArrayList <HistoryEntry >();
562
592
final ConnectionResource conn =
563
593
connectionManager .getConnectionResource ();
594
+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
595
+
564
596
try {
565
597
final PreparedStatement ps ;
566
598
if (file .isDirectory ()) {
@@ -569,7 +601,8 @@ private History getHistory(
569
601
ps .setString (2 , filePath );
570
602
} else {
571
603
// Fetch history for a single file only.
572
- ps = conn .getStatement (GET_FILE_HISTORY );
604
+ ps = conn .getStatement (env .RenamedFilesEnabled () && (getFilemovesCount () > 0 ) ?
605
+ GET_FILE_HISTORY : GET_FILE_HISTORY_FOLDED );
573
606
ps .setString (2 , getParentPath (filePath ));
574
607
ps .setString (3 , getBaseName (filePath ));
575
608
}
@@ -609,7 +642,6 @@ private History getHistory(
609
642
History history = new History ();
610
643
history .setHistoryEntries (entries );
611
644
612
- RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
613
645
if (env .isTagsEnabled () && repository .hasFileBasedTags ()) {
614
646
repository .assignTagsInHistory (history );
615
647
}
0 commit comments