win.doyto.query.service.AspectDataAccess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doyto-query-web Show documentation
Show all versions of doyto-query-web Show documentation
The web layer integrate with Spring Web
// Generated by delombok at Wed Nov 06 09:48:14 UTC 2024
/*
* Copyright © 2019-2024 Forb Yuan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package win.doyto.query.service;
import org.springframework.transaction.support.TransactionOperations;
import win.doyto.query.core.DataAccess;
import win.doyto.query.core.DoytoQuery;
import win.doyto.query.core.IdWrapper;
import win.doyto.query.entity.EntityAspect;
import win.doyto.query.entity.Persistable;
import java.io.Serializable;
import java.util.List;
/**
* AspectDataAccess
*
* @author f0rb on 2023/6/16
* @since 1.0.2
*/
@SuppressWarnings({"DataFlowIssue", "java:S2259"})
public class AspectDataAccess, I extends Serializable, Q extends DoytoQuery> implements DataAccess {
private final DataAccess delegate;
private final List> entityAspects;
private final TransactionOperations transactionOperations;
@Override
public void create(E e) {
transactionOperations.execute(s -> {
delegate.create(e);
entityAspects.forEach(entityAspect -> entityAspect.afterCreate(e));
return null;
});
}
@Override
public int update(E e) {
return transactionOperations.execute(s -> {
E origin = delegate.get(e.toIdWrapper());
if (origin == null) {
return 0;
}
delegate.update(e);
E current = delegate.get(e.toIdWrapper());
entityAspects.forEach(entityAspect -> entityAspect.afterUpdate(origin, current));
return 1;
});
}
@Override
public int patch(E e) {
return transactionOperations.execute(s -> {
E origin = delegate.get(e.toIdWrapper());
if (origin == null) {
return 0;
}
delegate.patch(e);
E current = delegate.get(e.toIdWrapper());
entityAspects.forEach(entityAspect -> entityAspect.afterUpdate(origin, current));
return 1;
});
}
@Override
public int delete(IdWrapper w) {
return transactionOperations.execute(s -> {
E e = delegate.get(w);
if (e == null) {
return 0;
}
int deleted = delegate.delete(w);
entityAspects.forEach(entityAspect -> entityAspect.afterDelete(e));
return deleted;
});
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AspectDataAccess(final DataAccess delegate, final List> entityAspects, final TransactionOperations transactionOperations) {
this.delegate = delegate;
this.entityAspects = entityAspects;
this.transactionOperations = transactionOperations;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.util.List query(final Q query) {
return this.delegate.query(query);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public long count(final Q query) {
return this.delegate.count(query);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public win.doyto.query.core.PageList page(final Q query) {
return this.delegate.page(query);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.util.List queryColumns(final Q q, final java.lang.Class clazz, final java.lang.String... columns) {
return this.delegate.queryColumns(q, clazz, columns);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public E get(final I id) {
return this.delegate.get(id);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public E get(final win.doyto.query.core.IdWrapper w) {
return this.delegate.get(w);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int delete(final I id) {
return this.delegate.delete(id);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int delete(final Q query) {
return this.delegate.delete(query);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int batchInsert(final java.lang.Iterable entities, final java.lang.String... columns) {
return this.delegate.batchInsert(entities, columns);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int patch(final E e, final Q q) {
return this.delegate.patch(e, q);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.util.List queryIds(final Q query) {
return this.delegate.queryIds(query);
}
}