Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor internal dto methods to use accessors #3078

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,13 @@ public <T> Update<T> createUpdate(Class<T> beanType, String ormUpdate) {

@Override
public <T> DtoQuery<T> findDto(Class<T> dtoType, String sql) {
DtoBeanDescriptor<T> descriptor = dtoBeanManager.getDescriptor(dtoType);
DtoBeanDescriptor<T> descriptor = dtoBeanManager.descriptor(dtoType);
return new DefaultDtoQuery<>(this, descriptor, sql.trim());
}

@Override
public <T> DtoQuery<T> createNamedDtoQuery(Class<T> dtoType, String namedQuery) {
DtoBeanDescriptor<T> descriptor = dtoBeanManager.getDescriptor(dtoType);
DtoBeanDescriptor<T> descriptor = dtoBeanManager.descriptor(dtoType);
String sql = descriptor.getNamedRawSql(namedQuery);
if (sql == null) {
throw new PersistenceException("No named query called " + namedQuery + " for bean:" + dtoType.getName());
Expand All @@ -898,7 +898,7 @@ public <T> DtoQuery<T> createNamedDtoQuery(Class<T> dtoType, String namedQuery)

@Override
public <T> DtoQuery<T> findDto(Class<T> dtoType, SpiQuery<?> ormQuery) {
DtoBeanDescriptor<T> descriptor = dtoBeanManager.getDescriptor(dtoType);
DtoBeanDescriptor<T> descriptor = dtoBeanManager.descriptor(dtoType);
return new DefaultDtoQuery<>(this, descriptor, ormQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public final class DtoBeanDescriptor<T> {
this.namedQueries = namedQueries;
}

public Class<T> getType() {
public Class<T> type() {
return dtoType;
}

public DtoQueryPlan getQueryPlan(Object planKey) {
public DtoQueryPlan queryPlan(Object planKey) {
return plans.get(planKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public DtoBeanManager(TypeManager typeManager, Map<Class<?>, DtoNamedQueries> na
* Return the descriptor for the given DTO bean class.
*/
@SuppressWarnings("unchecked")
public <T> DtoBeanDescriptor<T> getDescriptor(Class<T> dtoType) {

public <T> DtoBeanDescriptor<T> descriptor(Class<T> dtoType) {
return descriptorMap.computeIfAbsent(dtoType, this::createDescriptor);
}

private <T> DtoBeanDescriptor createDescriptor(Class<T> dtoType) {

try {
DtoMeta meta = new DtoMetaBuilder(dtoType, typeManager).build();
return new DtoBeanDescriptor<>(dtoType, meta, namedQueries(dtoType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public DtoColumn(String label) {
this.label = label;
}

public String getLabel() {
public String label() {
return label;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public DtoMappingRequest(SpiDtoQuery query, String sql, DtoColumn[] columnMeta)
this.columnMeta = columnMeta;
}

public DtoColumn[] getColumnMeta() {
public DtoColumn[] columnMeta() {
return columnMeta;
}

public boolean isRelaxedMode() {
public boolean relaxedMode() {
return relaxedMode;
}

public String getLabel() {
public String label() {
return label;
}

public String getSql() {
public String sql() {
return sql;
}

Expand Down Expand Up @@ -70,10 +70,10 @@ DtoReadSet[] mapArgPlusSetters(DtoMeta meta, int firstOnes) {
}

private DtoReadSet mapColumn(int pos, DtoMeta meta) {
String label = columnMeta[pos].getLabel();
String label = columnMeta[pos].label();
DtoReadSet property = meta.findProperty(label);
if (property == null || property.isReadOnly()) {
if (isRelaxedMode()) {
if (relaxedMode()) {
property = DtoReadSetColumnSkip.INSTANCE;
} else {
throw new IllegalStateException(unableToMapColumnMessage(columnMeta[pos], meta));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class DtoMeta {
DtoMeta(Class<?> dtoType, Collection<DtoMetaConstructor> constructors, List<DtoMetaProperty> properties) {
this.dtoType = dtoType;
for (DtoMetaProperty property : properties) {
propMap.put(property.getName().toUpperCase(), property);
propMap.put(property.name().toUpperCase(), property);
}
int maxArg = 0;
DtoMetaConstructor defaultConstructor = null;
Expand All @@ -38,7 +38,7 @@ final class DtoMeta {
}

public DtoQueryPlan match(DtoMappingRequest request) {
DtoColumn[] cols = request.getColumnMeta();
DtoColumn[] cols = request.columnMeta();
int colLen = cols.length;
DtoMetaConstructor constructor = constructorMap.get(colLen);
if (constructor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static Class<?> propertyClass(Method method) {
return method.getParameterTypes()[0];
}

String getName() {
String name() {
return name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String planKey() {

@Override
public DtoQueryPlan getQueryPlan(Object planKey) {
return descriptor.getQueryPlan(planKey);
return descriptor.queryPlan(planKey);
}

@Override
Expand Down Expand Up @@ -206,7 +206,7 @@ public String toString() {

@Override
public Class<T> getType() {
return descriptor.getType();
return descriptor.type();
}

@Override
Expand Down