generated from DataStax-Examples/datastax-examples-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
VideoDao.java
70 lines (62 loc) · 2.53 KB
/
VideoDao.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright DataStax, 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 com.datastax.examples.mapper.killrvideo.video;
import com.datastax.oss.driver.api.core.PagingIterable;
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.mapper.annotations.QueryProvider;
import com.datastax.oss.driver.api.mapper.annotations.Select;
import com.datastax.oss.driver.api.mapper.annotations.Update;
import com.datastax.oss.driver.api.mapper.entity.saving.NullSavingStrategy;
import java.util.UUID;
@Dao
public interface VideoDao {
/** Simple selection by full primary key. */
@Select
Video get(UUID videoid);
/**
* Selection by partial primary key, this will return multiple rows.
*
* <p>Also, note that this queries a different table: DAOs are not limited to a single entity, the
* return type of the method dictates what rows will be mapped to.
*/
@Select
PagingIterable<UserVideo> getByUser(UUID userid);
/** Other selection by partial primary key, for another table. */
@Select
PagingIterable<LatestVideo> getLatest(String yyyymmdd);
/** Other selection by partial primary key, for yet another table. */
@Select
PagingIterable<VideoByTag> getByTag(String tag);
/**
* Creating a video is a bit more complex: because of denormalization, it involves multiple
* tables.
*
* <p>A query provider is a nice way to wrap all the queries in a single operation, and hide the
* details from the DAO interface.
*/
@QueryProvider(
providerClass = CreateVideoQueryProvider.class,
entityHelpers = {Video.class, UserVideo.class, LatestVideo.class, VideoByTag.class})
void create(Video video);
/**
* Update using a template: the template must have its full primary key set; beyond that, any
* non-null field will be considered as a value to SET on the target row.
*
* <p>Note that we specify the null saving strategy for emphasis, but this is the default.
*/
@Update(nullSavingStrategy = NullSavingStrategy.DO_NOT_SET)
void update(Video template);
}