forked from mongeez/mongeez
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ChangeSetValidator to detect duplicate ids
- Loading branch information
Showing
8 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/org/mongeez/validation/ChangeSetsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.mongeez.validation; | ||
|
||
import java.util.List; | ||
|
||
|
||
import org.mongeez.commands.ChangeSet; | ||
|
||
public interface ChangeSetsValidator { | ||
public void validate(List<ChangeSet> changeSets) throws ValidationException; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/mongeez/validation/DefaultChangeSetsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.mongeez.validation; | ||
|
||
import java.util.List; | ||
|
||
import org.mongeez.commands.ChangeSet; | ||
|
||
public class DefaultChangeSetsValidator implements ChangeSetsValidator { | ||
|
||
@Override | ||
public void validate(List<ChangeSet> changesets) throws ValidationException { | ||
changeSetIdsNotUnique(changesets); | ||
} | ||
|
||
private void changeSetIdsNotUnique(List<ChangeSet> changeSets) { | ||
for (int i = 0; i < changeSets.size() / 2; i++) { | ||
ChangeSet changeSetI = changeSets.get(i); | ||
String changeSetIId = changeSetI.getChangeId(); | ||
|
||
for (int j = i + 1; j < changeSets.size(); j++) { | ||
ChangeSet changeSetJ = changeSets.get(j); | ||
String changeSetJId = changeSetJ.getChangeId(); | ||
|
||
if (changeSetIId.equals(changeSetJId)) { | ||
throw new ValidationException("ChangeSetId " + changeSetIId + " is not unique."); | ||
} | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/mongeez/validation/ValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.mongeez.validation; | ||
|
||
public class ValidationException extends RuntimeException { | ||
|
||
public ValidationException() { | ||
super(); | ||
} | ||
|
||
public ValidationException(String message, Throwable cause) { | ||
super(message); | ||
} | ||
|
||
public ValidationException(String message) { | ||
super(message); | ||
} | ||
|
||
public ValidationException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
~ Copyright 2011 SecondMarket Labs, LLC. | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<mongoChangeLog> | ||
<changeSet changeId="ChangeSet-1" author="d0x"> | ||
<script> | ||
db.organization.findOne(); | ||
</script> | ||
</changeSet> | ||
<changeSet changeId="ChangeSet-1" author="d0x"> | ||
<script> | ||
db.organization.findOne(); | ||
</script> | ||
</changeSet> | ||
</mongoChangeLog> |
15 changes: 15 additions & 0 deletions
15
src/test/resources/mongeez_fail_on_duplicate_changeset_ids.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- | ||
~ Copyright 2011 SecondMarket Labs, LLC. | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<changeFiles> | ||
<file path="failing_changeset_on_duplicate_ids.xml"/> | ||
</changeFiles> |