remove Setter class

This commit is contained in:
Albert Shift 2015-03-27 11:39:19 -07:00
parent 3a2daf2722
commit 64d2d6fdd9
6 changed files with 12 additions and 49 deletions

View file

@ -15,16 +15,16 @@
*/
package casser;
import com.datastax.driver.core.Cluster;
import casser.core.Casser;
import casser.core.CasserSession;
import casser.core.Filter;
import casser.core.Prepared;
import casser.core.CasserSession;
import casser.core.operation.SelectOperation;
import casser.core.tuple.Tuple1;
import casser.core.tuple.Tuple2;
import com.datastax.driver.core.Cluster;
public class Example {
static final User _user = Casser.dsl(User.class);
@ -54,7 +54,7 @@ public class Example {
User user = session.select(_user::getName, _user::getAge).where(_user::getId, "==", 100L).map(Example::mapUser).sync().findFirst().get();
session.update(_user::setAge, 10).where(_user::getId, "==", 100L).async();
session.update(_user::getAge, 10).where(_user::getId, "==", 100L).async();
session.delete(User.class).where(_user::getId, "==", 100L).async();

View file

@ -19,7 +19,6 @@ import java.io.Closeable;
import java.util.Objects;
import java.util.concurrent.Executor;
import casser.core.dsl.Setter;
import casser.core.operation.CountOperation;
import casser.core.operation.DeleteOperation;
import casser.core.operation.SelectOperation;
@ -228,11 +227,11 @@ public class CasserSession extends AbstractSessionOperations implements Closeabl
return new CountOperation(this, entity);
}
public <V> UpdateOperation update(Setter<V> setter, V v) {
Objects.requireNonNull(setter, "field is empty");
public <V> UpdateOperation update(Getter<V> getter, V v) {
Objects.requireNonNull(getter, "field is empty");
Objects.requireNonNull(v, "value is empty");
CasserMappingProperty p = MappingUtil.resolveMappingProperty(setter);
CasserMappingProperty p = MappingUtil.resolveMappingProperty(getter);
return new UpdateOperation(this, p, v);
}

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 2015 Noorq, Inc.
*
* 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 casser.core.dsl;
public interface Setter<V> {
void set(V val);
}

View file

@ -20,7 +20,7 @@ import java.util.Objects;
import casser.core.AbstractSessionOperations;
import casser.core.Filter;
import casser.core.dsl.Setter;
import casser.core.Getter;
import casser.mapping.CasserMappingEntity;
import casser.mapping.CasserMappingProperty;
import casser.mapping.MappingUtil;
@ -57,11 +57,11 @@ public final class UpdateOperation extends AbstractFilterOperation<ResultSet, Up
this.vals[other.vals.length] = v;
}
public <V> UpdateOperation set(Setter<V> setter, V v) {
Objects.requireNonNull(setter, "field is empty");
public <V> UpdateOperation set(Getter<V> getter, V v) {
Objects.requireNonNull(getter, "field is empty");
Objects.requireNonNull(v, "value is empty");
CasserMappingProperty p = MappingUtil.resolveMappingProperty(setter);
CasserMappingProperty p = MappingUtil.resolveMappingProperty(getter);
return new UpdateOperation(this, p, v);
}

View file

@ -19,7 +19,6 @@ import java.lang.reflect.Method;
import casser.core.Casser;
import casser.core.Getter;
import casser.core.dsl.Setter;
import casser.mapping.convert.UDTValueWritable;
import casser.support.CasserMappingException;
import casser.support.DslPropertyException;
@ -203,18 +202,5 @@ public final class MappingUtil {
}
public static CasserMappingProperty resolveMappingProperty(
Setter<?> setter) {
try {
setter.set(null);
throw new CasserMappingException(
"setter must reference to a dsl object " + setter);
} catch (DslPropertyException e) {
return (CasserMappingProperty) e.getProperty();
}
}
}

View file

@ -48,7 +48,7 @@ public class SimpleUserTest extends AbstractEmbeddedCassandraTest {
session.upsert(alex).sync();
session.update(user::setName, "albert").set(user::setAge, 35)
session.update(user::getName, "albert").set(user::getAge, 35)
.where(user::getId, "==", 123L).sync();
long cnt = session.count(user).where(user::getId, "==", 123L).sync();