-
Notifications
You must be signed in to change notification settings - Fork 165
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
Showing
9 changed files
with
170 additions
and
58 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
hsweb-easy-orm-core/src/main/java/org/hswebframework/ezorm/core/Extensible.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,37 @@ | ||
package org.hswebframework.ezorm.core; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* 可扩展的对象,用于动态拓展实体字段属性 | ||
* | ||
* @author zhouhao | ||
* @since 4.1.3 | ||
*/ | ||
public interface Extensible { | ||
|
||
/** | ||
* 获取所有扩展属性 | ||
* @return 扩展属性 | ||
*/ | ||
@JsonAnySetter | ||
Map<String, Object> getExtensions(); | ||
|
||
/** | ||
* 获取扩展属性 | ||
* @param property 属性名 | ||
* @return 属性值 | ||
*/ | ||
Object getExtension(String property); | ||
|
||
/** | ||
* 设置扩展属性 | ||
* @param property 属性名 | ||
* @param value 属性值 | ||
*/ | ||
@JsonAnySetter | ||
void setExtension(String property, Object value); | ||
|
||
} |
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
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
35 changes: 35 additions & 0 deletions
35
hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/utils/PropertyUtils.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,35 @@ | ||
package org.hswebframework.ezorm.rdb.utils; | ||
|
||
import org.hswebframework.ezorm.core.Extensible; | ||
import org.hswebframework.ezorm.core.GlobalConfig; | ||
import org.hswebframework.ezorm.core.ObjectPropertyOperator; | ||
import org.hswebframework.ezorm.rdb.mapping.EntityColumnMapping; | ||
import org.hswebframework.ezorm.rdb.mapping.EntityPropertyDescriptor; | ||
|
||
import java.util.Optional; | ||
|
||
public class PropertyUtils { | ||
|
||
public static Optional<Object> getProperty(Object entity, String property, EntityColumnMapping mapping) { | ||
ObjectPropertyOperator opt = GlobalConfig.getPropertyOperator(); | ||
if (entity instanceof Extensible && isExtensibleColumn(property, mapping)) { | ||
return Optional.ofNullable(((Extensible) entity).getExtension(property)); | ||
} | ||
return opt.getProperty(entity, property); | ||
} | ||
|
||
public static boolean isExtensibleColumn(String property, EntityColumnMapping mapping) { | ||
return mapping | ||
.getColumnByProperty(property) | ||
.map(c -> !c.getFeature(EntityPropertyDescriptor.ID).isPresent()) | ||
.orElse(true); | ||
} | ||
|
||
public static void setProperty(Object entity, String property, Object value, EntityColumnMapping mapping) { | ||
if (entity instanceof Extensible && isExtensibleColumn(property, mapping)) { | ||
((Extensible) entity).setExtension(property, value); | ||
} else { | ||
GlobalConfig.getPropertyOperator().setProperty(entity, property, value); | ||
} | ||
} | ||
} |
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.