001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.plugins.dbcleaner.runner;
021
022 import org.apache.commons.lang.builder.ToStringBuilder;
023 import org.sonar.api.database.model.Snapshot;
024 import org.sonar.api.resources.Project;
025 import org.sonar.plugins.dbcleaner.api.PurgeContext;
026
027 public final class DefaultPurgeContext implements org.sonar.api.batch.PurgeContext, PurgeContext {
028
029 private Project project;
030 private Integer currentSid;
031 private Integer previousSid;
032
033 public DefaultPurgeContext(Project project, Snapshot currentSnapshot) {
034 this(project, currentSnapshot, null);
035 }
036
037 public DefaultPurgeContext(Project project, Snapshot currentSnapshot, Snapshot previousSnapshot) {
038 this.project = project;
039 if (currentSnapshot != null) {
040 currentSid = currentSnapshot.getId();
041 }
042 if (previousSnapshot != null) {
043 previousSid = previousSnapshot.getId();
044 }
045 }
046
047 public DefaultPurgeContext setLastSnapshotId(Integer previousSid) {
048 this.previousSid = previousSid;
049 return this;
050 }
051
052 public Integer getSnapshotId() {
053 return currentSid;
054 }
055
056 public Integer getPreviousSnapshotId() {
057 return previousSid;
058 }
059
060 public Project getProject() {
061 return project;
062 }
063
064 /**
065 * @deprecated
066 */
067 @Deprecated
068 public Integer getLastSnapshotId() {
069 return currentSid;
070 }
071
072 @Override
073 public String toString() {
074 return new ToStringBuilder(this)
075 .append("currentSid", currentSid)
076 .append("previousSid", previousSid)
077 .toString();
078 }
079 }