-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved: Refactoring ‘EntityCondition’ - Remove EntityConditionBase …
…class (OFBIZ-10691) This is removing an abuse of inheritance for code reuse which was· breaking Liskov substitution principle. This has been achieved with the following changes: * The ‘Serializable’ interface which was implemented by ‘EntityConditionBase’ is now implemented directly by the· ‘EntityCondition’, ‘EntityConditionValue’, and ‘EntityOperator’ classes. * ‘emptyList’ and ‘_emptyMap’ useless static members has been removed and ‘emptyAliases’ has been move down to the ‘EntityConditionValue’ subclass. * The ‘castBoolean’ method has been removed due to the automatic boxing/unboxing of boolean and Boolean values which make it useless. * ‘equals’ and ‘hashCode’ pseudo abstract methods (meaning methods throwing an unsupported operation exception) has been moved down to the ‘EntityCondition’ and ‘EntityConditionValue’ sub classes. ‘Objects#equals’ and ‘Objects#hashCode’ standard methods has been used in the EntityCondition class hierarchy instead. * The ‘getColName’ methods has been moved down to the· ‘EntityConditionValue’ class which is the unique class using those methods. * The remaining static methods ‘getField’ and ‘addValue’ has been moved to a new ‘EntityConditionUtils’ class. The unused override of ‘addValue’ has been removed which allowed us to make this method static. Thanks Mathieu for the contribution git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1850372 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
12 changed files
with
146 additions
and
156 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
127 changes: 0 additions & 127 deletions
127
framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityConditionBase.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityConditionUtils.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,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.ofbiz.entity.condition; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ofbiz.entity.jdbc.SqlJdbcUtil; | ||
import org.apache.ofbiz.entity.model.ModelEntity; | ||
import org.apache.ofbiz.entity.model.ModelField; | ||
|
||
/** | ||
* Auxiliary methods used by condition expressions. | ||
*/ | ||
final class EntityConditionUtils { | ||
|
||
/** | ||
* Calls {@link ModelEntity#getField(String)} if the entity model is not null. | ||
* | ||
* @param modelEntity the entity model to query | ||
* @param fieldName the name of the field to get from {@code ModelEntity} | ||
* @return the field corresponding to {@code fieldName} in {@code ModelEntity} | ||
*/ | ||
static ModelField getField(ModelEntity modelEntity, String fieldName) { | ||
return (modelEntity == null) ? null : modelEntity.getField(fieldName); | ||
} | ||
|
||
/** | ||
* Calls {@link SqlJdbcUtil#addValue(StringBuilder, ModelField, Object, List)} | ||
* if the condition parameters are not null. | ||
* | ||
* @param buffer the buffer that will receive the SQL dump | ||
* @param field the field to dump | ||
* @param value the value to dump | ||
* @param params the condition parameters | ||
*/ | ||
static void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) { | ||
SqlJdbcUtil.addValue(buffer, params == null ? null : field, value, params); | ||
} | ||
} |
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
Oops, something went wrong.