Skip to content
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ https://www.seguetech.com/transferring-dynamic-query-batch-job-smartclient/
https://www.seguetech.com/transferring-a-dynamic-query-to-a-batch-job-in-smartclient-part-2/

https://www.seguetech.com/handle-data-treegrid/


https://isomorphic.atlassian.net/wiki/spaces/Main/pages/524566/Getting+Started

7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions smartclient-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<!-- <optional>true</optional>-->
</dependency>


<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.srg.smartclient.isomorphic.DSField;
import org.srg.smartclient.isomorphic.DSRequest;
import org.srg.smartclient.isomorphic.DSResponse;
import org.srg.smartclient.isomorphic.DataSource;
import org.srg.smartclient.isomorphic.*;

import java.util.*;

public abstract class AbstractDSHandler extends RelationSupport implements DSHandler {
public abstract class AbstractDSHandler extends SmartClientRelationSupport implements DSHandler {
private static Logger logger = LoggerFactory.getLogger(AbstractDSHandler.class);

private final IDSRegistry dsRegistry;
private final DataSource datasource;
private transient Map<String, DSField> fieldMap;
private transient Map<DSRequest.OperationType, List<OperationBinding>> bindingsMap;

public AbstractDSHandler(IDSRegistry dsRegistry, DataSource datasource) {
this.dsRegistry = dsRegistry;
Expand All @@ -35,6 +33,31 @@ protected Map<String, DSField> getFieldMap() {
return fieldMap;
}

protected Map<DSRequest.OperationType, List<OperationBinding>> getBindingsMap() {
if (bindingsMap == null) {

if (dataSource().getOperationBindings() == null) {
bindingsMap = Map.of();
} else {
final Map<DSRequest.OperationType, List<OperationBinding>> m = new LinkedHashMap<>();

for (OperationBinding b : dataSource().getOperationBindings()) {
List<OperationBinding> bindings = m.get(b.getOperationType());
if (bindings == null) {
bindings = new LinkedList<>();
m.put(b.getOperationType(), bindings);
}

bindings.add(b);
}

bindingsMap = Collections.unmodifiableMap(m);
}
}

return bindingsMap;
}

protected DSField getField(String fieldName) {
return getFieldMap().get(fieldName);
}
Expand Down Expand Up @@ -101,11 +124,15 @@ protected DataSource getDataSourceById(String dsId) {
}

protected ImportFromRelation describeImportFrom(DSField importFromField) {
return RelationSupport.describeImportFrom(dsId -> this.getDataSourceHandlerById(dsId), this.getDataSource(), importFromField);
return SmartClientRelationSupport.describeImportFrom(dsId -> this.getDataSourceHandlerById(dsId), this.getDataSource(), importFromField);
}

protected ForeignKeyRelation describeForeignKey(DSField foreignKeyField) {
return RelationSupport.describeForeignKey(dsId -> this.getDataSourceHandlerById(dsId), this.getDataSource(), foreignKeyField);
return SmartClientRelationSupport.describeForeignKey(dsId -> this.getDataSourceHandlerById(dsId), this.getDataSource(), foreignKeyField);
}

protected ForeignRelation describeForeignRelation(String relation) {
return SmartClientRelationSupport.describeForeignRelation( dsId -> this.getDataSourceHandlerById(dsId), relation);
}

protected ForeignRelation determineEffectiveField(DSField dsf) {
Expand All @@ -123,4 +150,32 @@ protected ForeignRelation determineEffectiveField(DSField dsf) {

return new ForeignRelation(effectiveDS.getId(), effectiveDS, effectiveField.getName(), effectiveField);
}

public OperationBinding getEffectiveOperationBinding(DSRequest.OperationType operationType) {
final Map<DSRequest.OperationType, List<OperationBinding>> bm = getBindingsMap();

if (bm == null) {
return null;
}

final List<OperationBinding> bindings = bm.get(operationType);

if (bindings == null || bindings.isEmpty()) {
return null;
}

final OperationBinding b;
if (bindings.size() >1) {
throw new IllegalStateException("Data source '%s': multiple bindings have not been supported yet, operation type '%s'."
.formatted(
dataSource().getId(),
operationType
)
);
} else {
b = bindings.get(0);
}

return b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*
* @author srg
*/
abstract class DSDeclarationBuilder {
public abstract class DSDeclarationBuilder {

private DSDeclarationBuilder() {}

private static final Logger logger = LoggerFactory.getLogger(DSDeclarationBuilder.class);

private static class BuilderContext extends RelationSupport {
private static class BuilderContext extends SmartClientRelationSupport {
private String dsName;
private int qntGeneratedFields;
private StringBuilder builder;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void write_if_notBlank(String str, String fmt, Object... args) {
// }

public ForeignKeyRelation describeForeignKey(DSField foreignKeyField) {
return RelationSupport.describeForeignKey(this.dsRegistry, this.dataSource, foreignKeyField);
return SmartClientRelationSupport.describeForeignKey(this.dsRegistry, this.dataSource, foreignKeyField);
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ protected static void buildField(BuilderContext ctx, DSField f) throws ClassNotF
// https://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/JpaHibernateRelations.html


final RelationSupport.ForeignKeyRelation foreignKeyRelation = ctx.describeForeignKey(f);
final SmartClientRelationSupport.ForeignKeyRelation foreignKeyRelation = ctx.describeForeignKey(f);
ctx.write("\t\t\t,type:\"%s\"\n",
foreignKeyRelation.foreign().dataSourceId());

Expand Down
Loading