org.zodiac.fastorm.rdb.mapping.DSLUpdate Maven / Gradle / Ivy
The newest version!
package org.zodiac.fastorm.rdb.mapping;
import java.util.Arrays;
import java.util.function.Supplier;
import org.zodiac.fastorm.core.Conditional;
import org.zodiac.fastorm.core.MethodReferenceColumn;
import org.zodiac.fastorm.core.StaticMethodReferenceColumn;
import org.zodiac.fastorm.core.param.QueryParam;
/**
* DSL dynamically updates conditions.
*
* @param Entity type.
* @param The type that implements this interface.
*/
public interface DSLUpdate> extends Conditional {
/**
* Specify the attributes(columns) that only need to be updated.
*
* @param properties List of attributes.
* @return This.
*/
ME includes(String... properties);
/**
* Specify attributes(columns) that are not updated.
*
* @param properties List of attributes.
* @return This.
*/
ME excludes(String... properties);
/**
* Using a {@code getter static} method reference to specify the properties(columns) that need to be updated, this method may be warned by the IDE.
*
* createUpdate()
* .set(user)
* .includes(User::getName,User::getState)
* .where(User::getId,id)
* .execute();
*
*
* @param columns Static method references.
* @return This.
*/
@SuppressWarnings("all")
default ME includes(StaticMethodReferenceColumn... columns) {
return includes(Arrays.stream(columns)
.map(StaticMethodReferenceColumn::getColumn)
.toArray(String[]::new));
}
/**
* Using a {@code getter static} method reference to specify properties(columns) that do not need to be updated may be warned by the IDE.
*
* createUpdate()
* .set(user)
* .excludes(User::getName,User::getState)
* .where(User::getId,id)
* .execute();
*
*
* @param columns Static method references.
* @return This.
*/
@SuppressWarnings("all")
default ME excludes(StaticMethodReferenceColumn... columns) {
return excludes(Arrays.stream(columns)
.map(StaticMethodReferenceColumn::getColumn)
.toArray(String[]::new));
}
/**
* Using a {@code getter} method reference to specify the properties(columns) that need to be updated, this method may be warned by the IDE.
*
* createUpdate()
* .set(user)
* .includes(user::getName,user::getState)
* .where(User::getId,id)
* .execute();
*
*
* @param columns Static method references.
* @return This.
*/
@SuppressWarnings("all")
default ME includes(MethodReferenceColumn... columns) {
return includes(Arrays.stream(columns)
.map(MethodReferenceColumn::getColumn)
.toArray(String[]::new));
}
/**
* Using {@code getter} method references to specify properties(columns) that do not need to be updated may be warned by the IDE.
*
* createUpdate()
* .set(user)
* .excludes(user::getName,user::getState)
* .where(User::getId,id)
* .execute();
*
*
* @param columns Static method references.
* @return This.
*/
@SuppressWarnings("all")
default ME excludes(MethodReferenceColumn... columns) {
return excludes(Arrays.stream(columns)
.map(MethodReferenceColumn::getColumn)
.toArray(String[]::new));
}
/**
* Updated by entity class, null
properties are ignored.
*
* @param entity The entity object.
* @return This.
*/
ME set(E entity);
/**
* Set the property(column) value.
*
* @param column Attribute or column name.
* @param value Value.
* @return This.
*/
ME set(String column, Object value);
/**
* Set the value of the property(column) to null
.
*
* @param column Attribute or column name.
* @return This.
*/
ME setNull(String column);
/**
* Use {@code getter} method references to set property value.
*
* //The corresponding SQL is "update table set name = ? where id = ?".
* createUpdate()
* .set(user::getName)
* .where(user::getId)
* .execute();
*
*
* @param Date type.
* @param columnAndValue Method reference.
* @return This.
*/
default ME set(MethodReferenceColumn columnAndValue) {
return set(columnAndValue.getColumn(), columnAndValue.get());
}
/**
* Use {@code getter static} method references to set property values.
*
*
* createUpdate()
* .set(User::getName,name)
* .where(User::getId,id)
* .execute();
*
*
* @param column Static method reference.
* @param value Value
* @return This.
*/
default ME set(StaticMethodReferenceColumn column, Object value) {
return set(column.getColumn(), value);
}
/**
* Use a {@code getter static} method reference to set the {@code null} value.
*
* createUpdate()
* .setNull(User::getName)
* .where(User::getId,id)
* .execute();
*
*
* @param column Column.
* @return This.
*/
default ME setNull(StaticMethodReferenceColumn column) {
return setNull(column.getColumn());
}
/**
* Use the {@code getter} method reference to set the {@code null} value
*
* createUpdate()
* .setNull(user::getName)
* .where(User::getId,id)
* .execute();
*
*
* @param column Column.
* @return This.
*/
default ME setNull(MethodReferenceColumn column) {
return setNull(column.getColumn());
}
/**
* Convert the update condition to a query condition, which is usually used to query the data that may be updated based on the update.
*
* @return Dynamic query condition.
*/
QueryParam toQueryParam();
/**
* Convert the update condition to a query condition, which is usually used to query the data that may be updated based on the update.
*
* @param The query condition type.
* @param template Supplier template for conversion.
* @return Dynamic query condition.
*/
T toQueryParam(Supplier template);
}