com.sap.cds.ql.impl.DeleteBuilder Maven / Gradle / Ivy
/**************************************************************************
* (C) 2019-2023 SAP SE or an SAP affiliate company. All rights reserved. *
**************************************************************************/
package com.sap.cds.ql.impl;
import static com.sap.cds.impl.builder.model.StructuredTypeImpl.structuredType;
import static com.sap.cds.impl.builder.model.StructuredTypeRefImpl.typeRef;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.sap.cds.impl.builder.model.StructuredTypeProxy;
import com.sap.cds.impl.builder.model.StructuredTypeRefImpl;
import com.sap.cds.impl.parser.token.Jsonizer;
import com.sap.cds.ql.Delete;
import com.sap.cds.ql.StructuredType;
import com.sap.cds.ql.cqn.CqnDelete;
import com.sap.cds.ql.cqn.CqnStructuredTypeRef;
import com.sap.cds.ql.cqn.Modifier;
public class DeleteBuilder> extends FilterableStatementBuilder>
implements Delete {
private final T entity;
private DeleteBuilder(T entity) {
this.entity = entity;
}
public static > DeleteBuilder from(T entity) {
return new DeleteBuilder<>(entity);
}
public static > DeleteBuilder from(Class entity) {
return from(StructuredTypeProxy.create(entity));
}
public static DeleteBuilder> from(CqnStructuredTypeRef ref) {
return from(structuredType(ref));
}
public static DeleteBuilder> from(String entityName) {
return from(typeRef(entityName));
}
public static DeleteBuilder> copy(CqnDelete delete) {
return copy(delete, ExpressionVisitor.COPY);
}
public static DeleteBuilder> copy(CqnDelete delete, Modifier modifier) {
CqnStructuredTypeRef ref = ExpressionVisitor.copy(delete.ref(), modifier);
DeleteBuilder> copy = from(ref);
copy.where = modifier.where(ExpressionVisitor.copy(delete.where(), modifier));
copy.hints(delete.hints());
return copy;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static DeleteBuilder copyShallow(CqnDelete statement) {
DeleteBuilder> original = (DeleteBuilder>) statement;
DeleteBuilder> copy = new DeleteBuilder<>(original.entity);
copy.hints.putAll(original.hints);
copy.where = original.where;
return copy;
}
@Override
public String toJson() {
Jsonizer cqn = Jsonizer.object("from", ref());
where().ifPresent(w -> {
ArrayNode whereArr = cqn.array("where");
w.tokens().forEach(whereArr::addPOJO);
});
return Jsonizer.object("DELETE", cqn).toJson();
}
public CqnDelete build() {
return this;
}
@Override
public CqnStructuredTypeRef ref() {
return StructuredTypeRefImpl.typeRef(entity);
}
@Override
@SuppressWarnings("unchecked")
T getType() {
return (T) entity.getType();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy