#250 - Add example for Cassandra User-defined type usage.
This commit is contained in:
committed by
Oliver Gierke
parent
d9f77903ef
commit
54ab8178b7
@@ -48,8 +48,8 @@ public interface BasicUserRepository extends CrudRepository<User, Long> {
|
||||
|
||||
/**
|
||||
* Derived query method using SASI (SSTable Attached Secondary Index) features through the {@code LIKE} keyword. This
|
||||
* query corresponds with {@code SELECT * FROM users WHERE uname LIKE '?0%'}. {@link User#username} is not part of the
|
||||
* primary so it requires a secondary index.
|
||||
* query corresponds with {@code SELECT * FROM users WHERE lname LIKE '?0'}. {@link User#lastname} is not part of the
|
||||
* primary key so it requires a secondary index.
|
||||
*
|
||||
* @param lastnamePrefix
|
||||
* @return
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 example.springdata.cassandra.udt;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.UserDefinedType;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@UserDefinedType
|
||||
@AllArgsConstructor
|
||||
public class Address {
|
||||
|
||||
String street, zip, city;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 example.springdata.cassandra.udt;
|
||||
|
||||
import com.datastax.driver.core.DataType.Name;
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.CassandraType;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@Table
|
||||
public class Person {
|
||||
|
||||
@Id int id;
|
||||
|
||||
String firstname, lastname;
|
||||
Address current;
|
||||
List<Address> previous;
|
||||
|
||||
@CassandraType(type = Name.UDT, userTypeName = "address")
|
||||
UDTValue alternative;
|
||||
}
|
||||
Reference in New Issue
Block a user