remove some legacy and unused code

This commit is contained in:
Sergey Ignatov
2017-02-09 15:51:43 +03:00
parent 294bf505f8
commit a496bbb303
12 changed files with 0 additions and 2081 deletions
@@ -19,10 +19,6 @@
<implementation-class>com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl</implementation-class>
<loadForDefaultProject/>
</component>
<!-- <component>
<implementation-class>com.intellij.openapi.vcs.changes.dbCommitted.HistoryCacheManager</implementation-class>
<option name="workspace" value="true"/>
</component> -->
<component>
<implementation-class>com.intellij.openapi.vcs.changes.VcsEventWatcher</implementation-class>
</component>
@@ -1,134 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.ThrowableConsumer;
import com.intellij.util.ThrowableConvertor;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/9/12
* Time: 10:36 PM
*/
public class CacheJdbcConnection {
private final Object myLock;
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.dbCommitted.CacheJdbcConnection");
private Connection myConnection;
private final Map<String, PreparedStatement> myPreparedStatementsMap;
private final File myDbFile;
private final ThrowableConsumer<Connection, VcsException> myInitDbScript;
public CacheJdbcConnection(final File dbFile, final ThrowableConsumer<Connection, VcsException> initDbScript) {
myDbFile = dbFile;
myInitDbScript = initDbScript;
myLock = new Object();
myPreparedStatementsMap = new HashMap<>();
}
public void closeConnection() {
final HashMap<String, PreparedStatement> copyMap;
final Connection connection;
synchronized (myLock) {
copyMap = new HashMap<>(myPreparedStatementsMap);
connection = myConnection;
myConnection = null;
myPreparedStatementsMap.clear();
}
if (connection != null) {
for (PreparedStatement statement : copyMap.values()) {
try {
statement.close();
}
catch (SQLException e) {
LOG.info(e);
}
}
try {
connection.close();
}
catch (SQLException e) {
LOG.info(e);
}
}
}
public PreparedStatement getOrCreatePreparedStatement(@NotNull final String name, final ThrowableConvertor<Connection, PreparedStatement, SQLException> getter)
throws VcsException {
synchronized (myLock) {
getConnection();
final PreparedStatement statement = myPreparedStatementsMap.get(name);
if (statement != null) {
return statement;
}
final PreparedStatement newStatement;
try {
newStatement = getter.convert(myConnection);
}
catch (SQLException e) {
throw new VcsException(e);
}
myPreparedStatementsMap.put(name, newStatement);
return newStatement;
}
}
public Connection getConnection() throws VcsException {
synchronized (myLock) {
if (myConnection == null) {
myConnection = initConnection();
}
return myConnection;
}
}
private Connection initConnection() throws VcsException {
final boolean existed = myDbFile.exists();
try {
Class.forName("org.sqlite.JDBC");
final Connection connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s", myDbFile.getPath()));
if (! existed && myInitDbScript != null) {
// ok to run under lock => no read is possible until initialized
myInitDbScript.consume(connection);
}
connection.setAutoCommit(false);
return connection;
}
catch (final ClassNotFoundException | SQLException e) {
throw new VcsException(e);
}
}
public void commit() throws VcsException {
try {
getConnection().commit();
}
catch (SQLException e) {
throw new VcsException(e);
}
}
}
@@ -1,69 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.vcs.changes.Change;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/10/12
* Time: 5:24 PM
*/
public enum ChangeTypeEnum {
ADD(0),
DELETE(1),
MODIFY(2),
ADD_PLUS(3),
MOVE(4),
REPLACE(5);
private final int myCode;
private ChangeTypeEnum(int code) {
myCode = code;
}
public int getCode() {
return myCode;
}
public static ChangeTypeEnum getChangeType(final long type) {
final ChangeTypeEnum[] values = values();
for (ChangeTypeEnum value : values) {
if (value.getCode() == type) {
return value;
}
}
return null;
}
public static ChangeTypeEnum getChangeType(final Change change) {
if (change.getBeforeRevision() == null) {
return ADD;
}
if (change.getAfterRevision() == null) {
return DELETE;
}
if (change.isIsReplaced()) {
return REPLACE;
}
if (change.isMoved() || change.isRenamed()) {
return MOVE;
}
return MODIFY;
}
}
@@ -1,37 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project;
import java.io.File;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/8/12
* Time: 6:01 PM
*/
public class DbSettings {
// default; .idea/
public static File getDbFilePath(final Project project) {
final File vcs = new File(PathManager.getSystemPath(), "vcs");
File file = new File(vcs, "historyCache");
file.mkdirs();
return new File(file, project.getLocationHash());
}
}
@@ -1,181 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.BackgroundTaskQueue;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.committed.CachesHolder;
import com.intellij.openapi.vcs.changes.committed.RepositoryLocationCache;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.PairProcessor;
import com.intellij.util.SmartList;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/8/12
* Time: 7:01 PM
*/
public class HistoryCacheManager {
private final Project myProject;
private final BackgroundTaskQueue myQueue;
private RepositoryLocationCache myRepositoryLocationCache;
private CachesHolder myCachesHolder;
private final KnownRepositoryLocations myKnownRepositoryLocations;
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.dbCommitted.HistoryCacheManager");
private VcsSqliteLayer myDbUtil;
public HistoryCacheManager(Project project) {
myProject = project;
myQueue = new BackgroundTaskQueue(myProject, "VCS project history cache update");
myKnownRepositoryLocations = new KnownRepositoryLocations();
myRepositoryLocationCache = new RepositoryLocationCache(myProject);
myCachesHolder = new CachesHolder(myProject, myRepositoryLocationCache);
myDbUtil = new VcsSqliteLayer(myProject, myKnownRepositoryLocations); // does not create connection immediately
}
public void initIfNeeded() {
myQueue.run(new CreateInitDatabase());
}
public static List<AbstractVcs> getGoodActiveVcses(final Project project) {
final AbstractVcs[] abstractVcses = ProjectLevelVcsManager.getInstance(project).getAllActiveVcss();
final List<AbstractVcs> result = new SmartList<>();
for(AbstractVcs vcs: abstractVcses) {
if (vcs.getCommittedChangesProvider() instanceof CachingCommittedChangesProvider && VcsType.centralized.equals(vcs.getType())) {
result.add(vcs);
}
}
return result;
}
public void appendChanges(final AbstractVcs vcs, final String root, final List<CommittedChangeList> lists) {
myQueue.run(new AppendChanges(vcs, root, lists));
}
public List<CommittedChangeList> readListsByDates(final AbstractVcs vcs, final RepositoryLocation location,
final long lastTs, final long oldTs, final String subfolder) throws VcsException {
return myDbUtil.readLists(vcs, location, RevisionId.createTime(lastTs), RevisionId.createTime(oldTs), subfolder);
}
public List<CommittedChangeList> readLists(final AbstractVcs vcs, final RepositoryLocation location, final long lastRev, final long oldRev)
throws VcsException {
return myDbUtil.readLists(vcs, location, lastRev, oldRev);
}
public long getLastRevision(final AbstractVcs vcs, final RepositoryLocation location) {
return myDbUtil.getLastRevision(vcs, location2string(location)).getNumber();
}
private String location2string(RepositoryLocation location) {
return FileUtil.toSystemIndependentName(location.toPresentableString());
}
public long getFirstRevision(final AbstractVcs vcs, final RepositoryLocation location) {
return myDbUtil.getFirstRevision(vcs, location2string(location)).getNumber();
}
public PathState getPathState(final AbstractVcs vcs, final RepositoryLocation location, final String path) throws VcsException {
return myDbUtil.getPathState(vcs, location, path);
}
private class AppendChanges extends Task.Backgroundable {
private final List<CommittedChangeList> myLists;
private final String myRoot;
private final AbstractVcs myVcs;
private VcsException myException;
private AppendChanges(final AbstractVcs vcs, final String root, final List<CommittedChangeList> lists) {
super(HistoryCacheManager.this.myProject, "Append data to history caches", false);
myLists = lists;
myVcs = vcs;
myRoot = FileUtil.toSystemIndependentName(root);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
myDbUtil.appendLists(myVcs, myRoot, myLists);
}
catch (VcsException e) {
myException = e;
}
}
@Override
public void onSuccess() {
if (myException != null) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw new RuntimeException(myException);
}
VcsBalloonProblemNotifier.showOverChangesView(myProject, myException.getMessage(), MessageType.ERROR);
}
}
}
private class CreateInitDatabase extends Task.Backgroundable {
private VcsException myException;
public CreateInitDatabase() {
super(HistoryCacheManager.this.myProject, "Update VCS and roots data", false);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
//indicator.setText2("Checking and possibly creating database");
indicator.setText2("Updating VCS and roots");
final MultiMap<String, String> map = new MultiMap<>();
myCachesHolder.iterateAllRepositoryLocations(new PairProcessor<RepositoryLocation, AbstractVcs>() {
@Override
public boolean process(RepositoryLocation location, AbstractVcs vcs) {
map.putValue(vcs.getName(), location2string(location));
return true;
}
});
myDbUtil.checkVcsRootsAreTracked(map);
}
catch (VcsException e) {
LOG.info(e);
myException = e;
}
}
@Override
public void onSuccess() {
// todo track whether the db was initialized, if not - delete all other requests
if (myException != null) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw new RuntimeException(myException);
}
VcsBalloonProblemNotifier.showOverChangesView(myProject, myException.getMessage(), MessageType.ERROR);
}
}
}
}
@@ -1,145 +0,0 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.util.Couple;
import com.intellij.util.containers.MultiMap;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/9/12
* Time: 3:18 PM
*/
public class KnownRepositoryLocations {
private final static int ourMaxAuthorsCached = 400;
private final Map<String, Long> myJustVcs;
private final MultiMap<String, String> myMap;
private final Map<Couple<String>, Long> myLocations;
private final Map<Long, RevisionId> myLastRevision;
private final Map<Long, RevisionId> myFirstRevision;
private final Map<String, Long> myAuthors;
public KnownRepositoryLocations() {
myMap = MultiMap.createSet();
myLocations = new HashMap<>();
myLastRevision = new HashMap<>();
myFirstRevision = new HashMap<>();
myJustVcs = new HashMap<>();
myAuthors = new HashMap<>();
}
public Map<String, Long> filterKnownAuthors(final Set<String> names) {
if (names.isEmpty()) return Collections.emptyMap();
synchronized (myMap) {
final Map<String, Long> result = new HashMap<>();
for (Iterator<String> iterator = names.iterator(); iterator.hasNext(); ) {
final String name = iterator.next();
final Long pk = myAuthors.get(name);
if (pk != null) {
iterator.remove();
result.put(name, pk);
}
}
return result;
}
}
public void addKnownAuthor(final String name, final long pk) {
synchronized (myMap) {
if (myAuthors.size() > ourMaxAuthorsCached) {
// random?
final Iterator<Map.Entry<String, Long>> iterator = myAuthors.entrySet().iterator();
int cnt = 10;
while (iterator.hasNext() && cnt > 0) {
Map.Entry<String, Long> next = iterator.next();
iterator.remove();
-- cnt;
}
}
myAuthors.put(name, pk);
}
}
public boolean exists(final String key) {
synchronized (myMap) {
return myJustVcs.containsKey(key);
}
}
public long getVcsKey(final String key) {
synchronized (myMap) {
final Long aLong = myJustVcs.get(key);
assert aLong != null;
return aLong;
}
}
public boolean exists(final String key, final String path) {
synchronized (myMap) {
final Collection<String> strings = myMap.get(key);
return strings != null && strings.contains(path);
}
}
public void addVcs(final String key, final long id) {
synchronized (myMap) {
myJustVcs.put(key, id);
}
}
public long getLocationId(final String key, final String path) {
synchronized (myMap) {
final Long id = myLocations.get(Couple.of(key, path));
assert id != null;
return id;
}
}
public void add(final String key, final String path, final long id) {
synchronized (myMap) {
myMap.putValue(key, path);
myLocations.put(Couple.of(key, path), id);
}
}
public RevisionId getLastRevision(final Long rootId) {
synchronized (myMap) {
return myLastRevision.get(rootId);
}
}
public void setLastRevision(final Long rootId, final RevisionId number) {
synchronized (myMap) {
myLastRevision.put(rootId, number);
}
}
public RevisionId getFirstRevision(final Long rootId) {
synchronized (myMap) {
return myFirstRevision.get(rootId);
}
}
public void setFirstRevision(final Long rootId, final RevisionId number) {
synchronized (myMap) {
myFirstRevision.put(rootId, number);
}
}
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/11/12
* Time: 5:56 PM
*/
public class PathState {
private final long myLastRevision;
private final boolean myExistsInLastRevision;
// todo use it?
//private final long myPathId;
public PathState(long lastRevision, boolean existsInLastRevision) {
myLastRevision = lastRevision;
myExistsInLastRevision = existsInLastRevision;
}
public long getLastRevision() {
return myLastRevision;
}
public boolean isExistsInLastRevision() {
return myExistsInLastRevision;
}
}
@@ -1,59 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/18/12
* Time: 3:48 PM
*/
public class RevisionId {
public static final long ourFake = -1;
public static final RevisionId FAKE = new RevisionId(-1, -1);
private final long myNumber;
private final long myTime;
public static RevisionId createNumber(final long number) {
return new RevisionId(number, -1);
}
public static RevisionId createTime(final long time) {
return new RevisionId(-1, time);
}
public RevisionId(long number, long time) {
myNumber = number;
myTime = time;
}
public long getNumber() {
return myNumber;
}
public long getTime() {
return myTime;
}
public boolean isNumberFake() {
return ourFake == myNumber;
}
public boolean isFake() {
return ourFake == myNumber && ourFake == myTime;
}
}
@@ -1,153 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.ThrowableConvertor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/18/12
* Time: 5:30 PM
*/
public class SelectListsQueryHelper {
private final CacheJdbcConnection myConnection;
private final long myLast;
private final long myFirst;
private final Long myLocationId;
private final String mySubfolder;
private final boolean myNumberFake;
public SelectListsQueryHelper(final CacheJdbcConnection connection, RevisionId existingLast, RevisionId existingFirst, RevisionId last,
RevisionId first, final Long locationId, String subfolder) {
myConnection = connection;
myNumberFake = last.isNumberFake() && first.isNumberFake() && ! (last.isFake() && first.isFake());
myLast = operating(last, existingLast);
myFirst = operating(first, existingFirst);
myLocationId = locationId;
mySubfolder = subfolder;
}
private long operating(RevisionId last, RevisionId existing) {
assert ! existing.isFake();
if (myNumberFake) {
return last.isFake() ? existing.getTime() : last.getTime();
}
else {
// we allow only one bound to be specified
return last.isNumberFake() ? existing.getNumber() : last.getNumber();
}
}
public PreparedStatement createStatement() throws VcsException, SQLException {
if (myNumberFake) {
// by dates
if (StringUtil.isEmptyOrSpaces(mySubfolder)) {
// no subfolder constraint
return createDatesOnly();
} else {
return createDatesSubfolder();
}
} else {
// by numbers
if (StringUtil.isEmptyOrSpaces(mySubfolder)) {
// no subfolder constraint
return createNumbersOnly();
} else {
return createNumbersSubfolder();
}
}
}
private PreparedStatement createNumbersSubfolder() throws VcsException, SQLException {
final PreparedStatement impl =
createImpl(SqliteTables.PREPARED_NUMBERS_SUBFOLDER, " R." + SqliteTables.REVISION.NUMBER_INT + ">=? AND R." + SqliteTables.REVISION.NUMBER_INT + "<=? AND P." +
SqliteTables.PATHS.PATH + " LIKE ?");
impl.setLong(2, myFirst);
impl.setLong(3, myLast);
impl.setString(4, mySubfolder + "%");
return impl;
}
private PreparedStatement createNumbersOnly() throws VcsException, SQLException {
final PreparedStatement impl =
createImpl(SqliteTables.PREPARED_NUMBERS_ONLY, " R." + SqliteTables.REVISION.NUMBER_INT + ">=? AND R." + SqliteTables.REVISION.NUMBER_INT + "<=? ");
impl.setLong(2, myFirst);
impl.setLong(3, myLast);
return impl;
}
private PreparedStatement createDatesSubfolder() throws VcsException, SQLException {
final PreparedStatement impl =
createImpl(SqliteTables.PREPARED_DATES_SUBFOLDER, " R." + SqliteTables.REVISION.DATE + ">=? AND R." + SqliteTables.REVISION.DATE + "<=? AND P." +
SqliteTables.PATHS.PATH + " LIKE ?");
impl.setLong(2, myFirst);
impl.setLong(3, myLast);
impl.setString(4, mySubfolder + "%");
return impl;
}
private PreparedStatement createDatesOnly() throws VcsException, SQLException {
final PreparedStatement impl = createImpl(SqliteTables.PREPARED_DATES_ONLY, " R." + SqliteTables.REVISION.DATE + ">=? AND R." + SqliteTables.REVISION.DATE + "<=? ");
impl.setLong(2, myFirst);
impl.setLong(3, myLast);
return impl;
}
private PreparedStatement createImpl(final String queryName, final String whereClause) throws VcsException, SQLException {
final PreparedStatement statement = myConnection.getOrCreatePreparedStatement(queryName,
new ThrowableConvertor<Connection, PreparedStatement, SQLException>() {
@Override
public PreparedStatement convert(Connection connection)
throws SQLException {
return connection.prepareStatement("SELECT " +
SqliteTables.REVISION.RAW_DATA +
" , " + SqliteTables.REVISION.NUMBER_INT +
" FROM " +
SqliteTables.REVISION.TABLE_NAME +
" R INNER JOIN " +
SqliteTables.PATHS_2_REVS.TABLE_NAME +
" PR ON R." +
SqliteTables.REVISION.ID +
" = PR." +
SqliteTables.PATHS_2_REVS.REVISION_FK +
" , " +
SqliteTables.PATHS.TABLE_NAME +
" P ON PR." +
SqliteTables.PATHS_2_REVS.PATH_FK +
" = P." +
SqliteTables.PATHS.ID +
" WHERE R." +
SqliteTables.REVISION.ROOT_FK +
" = ? AND "
+
whereClause +
" ORDER BY " +
SqliteTables.REVISION.NUMBER_INT +
" DESC");
}
});
statement.setLong(1, myLocationId);
return statement;
}
}
@@ -1,177 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/8/12
* Time: 4:27 PM
*/
public interface SqliteTables {
String IDX_ROOT_URL = "IDX_ROOT_URL";
String IDX_AUTHOR_NAME = "IDX_AUTHOR_NAME";
String IDX_REVISION_DATE = "IDX_REVISION_DATE";
String IDX_REVISION_NUMBER_INT = "IDX_REVISION_NUMBER_INT";
String IDX_PATHS_PATH = "IDX_PATHS_PATH";
String PREPARED_INSERT_VCS = "PREPARED_INSERT_VCS";
String PREPARED_SELECT_VCS = "PREPARED_SELECT_VCS";
String PREPARED_SELECT_ROOTS = "PREPARED_SELECT_ROOTS";
String PREPARED_INSERT_ROOT = "PREPARED_INSERT_ROOT";
String PREPARED_SELECT_MAX_REVISION = "PREPARED_SELECT_MAX_REVISION";
String PREPARED_FILTER_KNOWN_AUTHORS = "PREPARED_FILTER_KNOWN_AUTHORS";
String PREPARED_ADD_AUTHOR = "PREPARED_ADD_AUTHOR";
String PREPARED_INSERT_REVISION = "PREPARED_INSERT_REVISION";
String PREPARED_READ_PATH = "PREPARED_READ_PATH";
String PREPARED_INSERT_PATH = "PREPARED_INSERT_PATH";
String PREPARED_INSERT_PATH_2_REVS = "PREPARED_INSERT_PATH_2_REVS";
String PREPARED_SELECT_REVISIONS = "PREPARED_SELECT_REVISIONS";
String PREPARED_SELECT_PATH_DATA = "PREPARED_SELECT_PATH_DATA";
String PREPARED_PATHS_2_REVS = "PREPARED_PATHS_2_REVS";
String PREPARED_SELECT_PATH_DATA_BATCH = "PREPARED_SELECT_PATH_DATA_BATCH";
String PREPARED_PATHS_2_REVS_BATCH = "PREPARED_PATHS_2_REVS_BATCH";
String PREPARED_INSERT_INCOMING = "PREPARED_INSERT_INCOMING";
String PREPARED_SELECT_INCOMING = "PREPARED_SELECT_INCOMING";
String PREPARED_SELECT_MIN_REVISION = "PREPARED_SELECT_MIN_REVISION";
String PREPARED_DATES_ONLY = "PREPARED_DATES_ONLY";
String PREPARED_NUMBERS_SUBFOLDER = "PREPARED_NUMBERS_SUBFOLDER";
String PREPARED_NUMBERS_ONLY = "PREPARED_NUMBERS_ONLY";
String PREPARED_DATES_SUBFOLDER = "PREPARED_DATES_SUBFOLDER";
abstract class BaseTable {
public final String ID;
public final String TABLE_NAME;
private final String myCreateTableStatement;
protected BaseTable(String TABLE_NAME, final String createTableStatement) {
myCreateTableStatement = createTableStatement;
this.ID = "ID";
this.TABLE_NAME = TABLE_NAME;
}
public String getCreateTableStatement() {
return myCreateTableStatement;
}
}
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
@interface Indexed {}
KnownVcs KNOWN_VCS = new KnownVcs();
Root ROOT = new Root();
Author AUTHOR = new Author();
Revision REVISION = new Revision();
Paths PATHS = new Paths();
Paths2Revs PATHS_2_REVS = new Paths2Revs();
IncomingPaths INCOMING_PATHS = new IncomingPaths();
class KnownVcs extends BaseTable {
public KnownVcs() {
super("VCS", "NAME TEXT NOT NULL");
}
public final String NAME = "NAME";
}
class Root extends BaseTable {
public Root() {
super("ROOT", "URL TEXT NOT NULL, VCS_FK INTEGER NOT NULL REFERENCES VCS(ID)");
}
@Indexed
public final String URL = "URL";
public final String VCS_FK = "VCS_FK";
}
class Author extends BaseTable {
public Author() {
super("AUTHOR", "NAME TEXT NOT NULL");
}
// todo index? can have in memory..
@Indexed
public final String NAME = "NAME";
}
class Revision extends BaseTable {
public Revision() {
super("REVISION", "ROOT_FK INTEGER NOT NULL REFERENCES ROOT(ID), " +
"AUTHOR_FK INTEGER NOT NULL REFERENCES AUTHOR(ID), " +
"DATE INTEGER NOT NULL, " +
"NUMBER_STR TEXT NOT NULL, " +
"NUMBER_INT INTEGER NOT NULL, " +
"COMMENT TEXT, COUNT INTEGER NOT NULL, RAW_DATA BLOB");
}
public final String ROOT_FK = "ROOT_FK";
public final String AUTHOR_FK = "AUTHOR_FK";
@Indexed
public final String DATE = "DATE";
public final String NUMBER_STR = "NUMBER_STR";
@Indexed
public final String NUMBER_INT = "NUMBER_INT";
public final String COMMENT = "COMMENT";
public final String COUNT = "COUNT";
public final String RAW_DATA = "RAW_DATA";
}
class Paths extends BaseTable {
public Paths() {
super("PATHS", "ROOT_FK INTEGER NOT NULL REFERENCES ROOT(ID), " +
"PATH TEXT NOT NULL");
}
public final String ROOT_FK = "ROOT_FK";
@Indexed
public final String PATH = "PATH";
}
class Paths2Revs extends BaseTable {
public Paths2Revs() {
super("PATHS_2_REVS", "PATH_FK INTEGER NOT NULL REFERENCES PATHS(ID), " +
"REVISION_FK INTEGER NOT NULL REFERENCES REVISION(ID), " +
"TYPE INTEGER NOT NULL, " +
"COPY_PATH_ID INTEGER REFERENCES PATHS(ID), " +
"VISIBLE INTEGER NOT NULL DEFAULT 1, " +
"DELETE_PATH_ID INTEGER REFERENCES PATHS(ID)");
}
public final String PATH_FK = "PATH_FK";
public final String REVISION_FK = "REVISION_FK";
public final String TYPE = "TYPE";
public final String COPY_PATH_ID = "COPY_PATH_ID";
public final String VISIBLE = "VISIBLE";
public final String DELETE_PATH_ID = "DELETE_PATH_ID";
}
class IncomingPaths extends BaseTable {
public IncomingPaths() {
super("INCOMING_PATHS", "PR_FK INTEGER NOT NULL REFERENCES PATHS_2_REVS (ID)");
}
public final String PR_FK = "";
}
//SqlJetTypeAffinity
}
@@ -1,51 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.dbCommitted;
import com.intellij.util.ThrowableRunnable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 10/8/12
* Time: 11:01 PM
*/
public class SqliteUtil {
public static void readSelectResults(final ResultSet set, final ThrowableRunnable<SQLException> onNextRow) throws SQLException {
//if (! set.first()) return;
while (! set.isAfterLast()) {
if (! set.next()) break;
onNextRow.run();
}
}
public static long insert(final PreparedStatement insert) throws SQLException {
final int num = insert.executeUpdate();
if (num > 0) {
final ResultSet keys = insert.getGeneratedKeys();
if (keys.next()) {
return keys.getLong(1);
} else {
assert false;
}
}
throw new SQLException("Didn't insert");
}
}