forked from apache/shardingsphere
-
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.
- Loading branch information
1 parent
bff358a
commit 5d14141
Showing
8 changed files
with
263 additions
and
50 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...re/src/main/java/io/shardingjdbc/core/parsing/parser/context/condition/AndConditions.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,97 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingjdbc.core.parsing.parser.context.condition; | ||
|
||
import com.google.common.base.Objects; | ||
import com.google.common.base.Optional; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* And conditions. | ||
* | ||
* @author maxiaoguang | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
@ToString | ||
public class AndConditions { | ||
|
||
private final List<Condition> conditions = new LinkedList<>(); | ||
|
||
/** | ||
* Add condition. | ||
* | ||
* @param condition condition | ||
*/ | ||
public void add(final Condition condition) { | ||
conditions.add(condition); | ||
} | ||
|
||
/** | ||
* Find condition via column. | ||
* | ||
* @param column column | ||
* @return found condition | ||
*/ | ||
public Optional<Condition> find(final Column column) { | ||
Condition result = null; | ||
for (Condition each : conditions) { | ||
if (Objects.equal(each.getColumn(), column)) { | ||
result = each; | ||
} | ||
} | ||
return Optional.fromNullable(result); | ||
} | ||
|
||
/** | ||
* Get condition via index. | ||
* | ||
* @param index index of conditions | ||
* @return found condition | ||
*/ | ||
public Optional<Condition> get(int index) { | ||
Condition result = null; | ||
if (size() > index) { | ||
result = conditions.get(index); | ||
} | ||
return Optional.fromNullable(result); | ||
} | ||
|
||
/** | ||
* Adjust and conditions is empty or not. | ||
* | ||
* @return and conditions is empty or not | ||
*/ | ||
public boolean isEmpty() { | ||
return conditions.isEmpty(); | ||
} | ||
|
||
/** | ||
* Returns the number of conditions in this. | ||
* | ||
* @return the number of conditions in this | ||
*/ | ||
public int size() { | ||
return conditions.size(); | ||
} | ||
} |
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
103 changes: 103 additions & 0 deletions
103
...ore/src/main/java/io/shardingjdbc/core/parsing/parser/context/condition/OrConditions.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,103 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingjdbc.core.parsing.parser.context.condition; | ||
|
||
import com.google.common.base.Optional; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Or conditions. | ||
* | ||
* @author maxiaoguang | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
@ToString | ||
public class OrConditions { | ||
|
||
private final List<AndConditions> andConditions = new LinkedList<>(); | ||
|
||
/** | ||
* Add condition. | ||
* | ||
* @param condition condition | ||
*/ | ||
public void add(final Condition condition) { | ||
AndConditions firstAndConditions; | ||
if (isEmpty()) { | ||
firstAndConditions = new AndConditions(); | ||
andConditions.add(firstAndConditions); | ||
} else { | ||
firstAndConditions = andConditions.get(0); | ||
} | ||
firstAndConditions.add(condition); | ||
} | ||
|
||
/** | ||
* Find condition via column. | ||
* | ||
* @param column column | ||
* @param index index of and conditions | ||
* @return found condition | ||
*/ | ||
public Optional<Condition> find(final Column column, int index) { | ||
Optional<AndConditions> andConditions = get(index); | ||
if (andConditions.isPresent()) { | ||
return andConditions.get().find(column); | ||
} else { | ||
return Optional.fromNullable(null); | ||
} | ||
} | ||
|
||
/** | ||
* Get and conditions via index. | ||
* | ||
* @param index index of and conditions | ||
* @return found and conditions | ||
*/ | ||
public Optional<AndConditions> get(int index) { | ||
AndConditions result = null; | ||
if (size() > index) { | ||
result = andConditions.get(index); | ||
} | ||
return Optional.fromNullable(result); | ||
} | ||
|
||
/** | ||
* Adjust or conditions is empty or not. | ||
* | ||
* @return or conditions is empty or not | ||
*/ | ||
public boolean isEmpty() { | ||
return andConditions.isEmpty(); | ||
} | ||
|
||
/** | ||
* Returns the number of and conditions in this. | ||
* | ||
* @return the number of and conditions in this | ||
*/ | ||
public int size() { | ||
return andConditions.size(); | ||
} | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
...test/java/io/shardingjdbc/core/parsing/integrate/jaxb/condition/ExpectedOrConditions.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,41 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingjdbc.core.parsing.integrate.jaxb.condition; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Expected and conditions. | ||
* | ||
* @author maxiaoguang | ||
*/ | ||
@Getter | ||
@Setter | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public final class ExpectedOrConditions { | ||
|
||
@XmlElement(name = "and-conditions") | ||
private List<ExpectedAndConditions> andConditions = new LinkedList<>(); | ||
} |
Oops, something went wrong.