-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#277] 添加mapping strategy映射策略选择支持column和property和column+property
- Loading branch information
Showing
25 changed files
with
292 additions
and
27 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
sql-core/src/main/java/com/easy/query/core/basic/entity/ColumnEntityMappingRule.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,26 @@ | ||
package com.easy.query.core.basic.entity; | ||
|
||
import com.easy.query.core.expression.parser.core.available.TableAvailable; | ||
import com.easy.query.core.expression.segment.SQLEntityAliasSegment; | ||
import com.easy.query.core.metadata.ColumnMetadata; | ||
import com.easy.query.core.metadata.EntityMetadata; | ||
import com.easy.query.core.util.EasyUtil; | ||
|
||
/** | ||
* create time 2025/1/6 19:49 | ||
* 文件说明 | ||
* | ||
* @author xuejiaming | ||
*/ | ||
public class ColumnEntityMappingRule implements EntityMappingRule{ | ||
@Override | ||
public ColumnMetadata getColumnMetadataBySourcColumnMetadata(EntityMetadata sourceEntityMetadata, ColumnMetadata sourceColumnMetadata, EntityMetadata targetEntityMetadata) { | ||
String sourceColumnName = sourceColumnMetadata.getName(); | ||
return targetEntityMetadata.getColumnMetadataOrNull(sourceColumnName); | ||
} | ||
|
||
@Override | ||
public String getAnonymousPropertyNameFromSQLSegment(SQLEntityAliasSegment sqlEntityAliasSegment, TableAvailable aliasTable) { | ||
return EasyUtil.getAnonymousPropertyNameByAlias(sqlEntityAliasSegment, aliasTable); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
sql-core/src/main/java/com/easy/query/core/basic/entity/EntityMappingRule.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,31 @@ | ||
package com.easy.query.core.basic.entity; | ||
|
||
import com.easy.query.core.expression.parser.core.available.TableAvailable; | ||
import com.easy.query.core.expression.segment.SQLEntityAliasSegment; | ||
import com.easy.query.core.metadata.ColumnMetadata; | ||
import com.easy.query.core.metadata.EntityMetadata; | ||
|
||
/** | ||
* create time 2025/1/6 17:18 | ||
* 文件说明 | ||
* | ||
* @author xuejiaming | ||
*/ | ||
public interface EntityMappingRule { | ||
/** | ||
* 获取class表别名属性 | ||
* @param sourceEntityMetadata | ||
* @param sourceColumnMetadata | ||
* @param targetEntityMetadata | ||
* @return | ||
*/ | ||
ColumnMetadata getColumnMetadataBySourcColumnMetadata(EntityMetadata sourceEntityMetadata, ColumnMetadata sourceColumnMetadata, EntityMetadata targetEntityMetadata); | ||
|
||
/** | ||
* 获取别名表达式表属性名 | ||
* @param sqlEntityAliasSegment | ||
* @param aliasTable | ||
* @return | ||
*/ | ||
String getAnonymousPropertyNameFromSQLSegment(SQLEntityAliasSegment sqlEntityAliasSegment, TableAvailable aliasTable); | ||
} |
30 changes: 30 additions & 0 deletions
30
sql-core/src/main/java/com/easy/query/core/basic/entity/PropertyEntityMappingRule.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,30 @@ | ||
package com.easy.query.core.basic.entity; | ||
|
||
import com.easy.query.core.expression.parser.core.available.TableAvailable; | ||
import com.easy.query.core.expression.segment.SQLEntityAliasSegment; | ||
import com.easy.query.core.metadata.ColumnMetadata; | ||
import com.easy.query.core.metadata.EntityMetadata; | ||
import com.easy.query.core.util.EasyUtil; | ||
|
||
/** | ||
* create time 2025/1/6 19:49 | ||
* 文件说明 | ||
* | ||
* @author xuejiaming | ||
*/ | ||
public class PropertyEntityMappingRule implements EntityMappingRule{ | ||
@Override | ||
public ColumnMetadata getColumnMetadataBySourcColumnMetadata(EntityMetadata sourceEntityMetadata, ColumnMetadata sourceColumnMetadata, EntityMetadata targetEntityMetadata) { | ||
|
||
ColumnMetadata columnMetadata = targetEntityMetadata.getProperty2ColumnMap().get(sourceColumnMetadata.getPropertyName()); | ||
if (columnMetadata != null && !columnMetadata.isValueObject()) { | ||
return columnMetadata; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getAnonymousPropertyNameFromSQLSegment(SQLEntityAliasSegment sqlEntityAliasSegment, TableAvailable aliasTable) { | ||
return EasyUtil.getAnonymousPropertyNameByProperty(sqlEntityAliasSegment, aliasTable); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...src/main/java/com/easy/query/core/basic/entity/TryColumnAndPropertyEntityMappingRule.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 com.easy.query.core.basic.entity; | ||
|
||
import com.easy.query.core.expression.parser.core.available.TableAvailable; | ||
import com.easy.query.core.expression.segment.SQLEntityAliasSegment; | ||
import com.easy.query.core.metadata.ColumnMetadata; | ||
import com.easy.query.core.metadata.EntityMetadata; | ||
import com.easy.query.core.util.EasyUtil; | ||
|
||
/** | ||
* create time 2025/1/6 17:21 | ||
* 文件说明 | ||
* | ||
* @author xuejiaming | ||
*/ | ||
public class TryColumnAndPropertyEntityMappingRule implements EntityMappingRule { | ||
@Override | ||
public ColumnMetadata getColumnMetadataBySourcColumnMetadata(EntityMetadata sourceEntityMetadata, ColumnMetadata sourceColumnMetadata, EntityMetadata targetEntityMetadata) { | ||
String sourceColumnName = sourceColumnMetadata.getName(); | ||
ColumnMetadata targetColumnMetadata = targetEntityMetadata.getColumnMetadataOrNull(sourceColumnName); | ||
if (targetColumnMetadata == null) { | ||
ColumnMetadata columnMetadata = targetEntityMetadata.getProperty2ColumnMap().get(sourceColumnMetadata.getPropertyName()); | ||
if (columnMetadata != null && !columnMetadata.isValueObject()) { | ||
targetColumnMetadata = columnMetadata; | ||
} | ||
} | ||
return targetColumnMetadata; | ||
} | ||
|
||
@Override | ||
public String getAnonymousPropertyNameFromSQLSegment(SQLEntityAliasSegment sqlEntityAliasSegment, TableAvailable aliasTable) { | ||
String propertyName = EasyUtil.getAnonymousPropertyNameByAlias(sqlEntityAliasSegment, aliasTable); | ||
if (propertyName == null) { | ||
return EasyUtil.getAnonymousPropertyNameByProperty(sqlEntityAliasSegment, aliasTable); | ||
} | ||
return propertyName; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
sql-core/src/main/java/com/easy/query/core/enums/EntityMappingStrategyEnum.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,13 @@ | ||
package com.easy.query.core.enums; | ||
|
||
/** | ||
* create time 2025/1/6 19:51 | ||
* 对象映射策略 | ||
* | ||
* @author xuejiaming | ||
*/ | ||
public enum EntityMappingStrategyEnum { | ||
COLUMN_ONLY, | ||
PROPERTY_ONLY, | ||
COLUMN_AND_PROPERTY; | ||
} |
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.