-
Notifications
You must be signed in to change notification settings - Fork 477
/
EndpointConfigurationCassandraDao.java
87 lines (73 loc) · 3.14 KB
/
EndpointConfigurationCassandraDao.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 2014-2016 CyberVision, 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 org.kaaproject.kaa.server.common.nosql.cassandra.dao;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getByteBuffer;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getBytes;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.ENDPOINT_CONFIGURATION_COLUMN_FAMILY_NAME;
import org.kaaproject.kaa.common.dto.EndpointConfigurationDto;
import org.kaaproject.kaa.server.common.dao.impl.EndpointConfigurationDao;
import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import java.nio.ByteBuffer;
@Repository(value = "endpointConfigurationDao")
public class EndpointConfigurationCassandraDao
extends AbstractCassandraDao<CassandraEndpointConfiguration, ByteBuffer>
implements EndpointConfigurationDao<CassandraEndpointConfiguration> {
private static final Logger LOG =
LoggerFactory.getLogger(EndpointConfigurationCassandraDao.class);
@Override
protected Class<CassandraEndpointConfiguration> getColumnFamilyClass() {
return CassandraEndpointConfiguration.class;
}
@Override
protected String getColumnFamilyName() {
return ENDPOINT_CONFIGURATION_COLUMN_FAMILY_NAME;
}
@Override
public CassandraEndpointConfiguration findByHash(final byte[] hash) {
LOG.debug("Try to find endpoint configuration by hash [{}] ", hash);
return (CassandraEndpointConfiguration) getMapper().get(getByteBuffer(hash));
}
@Override
public void removeByHash(final byte[] hash) {
LOG.debug("Remove endpoint configuration by hash [{}] ", hash);
getMapper().delete(getByteBuffer(hash));
}
@Override
public CassandraEndpointConfiguration save(EndpointConfigurationDto dto) {
LOG.debug("Save endpoint configuration [{}] ", dto);
return save(new CassandraEndpointConfiguration(dto));
}
@Override
public CassandraEndpointConfiguration findById(ByteBuffer key) {
LOG.debug("Try to find endpoint configuration by hash [{}] ", key);
CassandraEndpointConfiguration configuration = null;
if (key != null) {
configuration = findByHash(getBytes(key));
}
LOG.debug("[{}] Found endpoint configuration by hash {} ", key, configuration);
return configuration;
}
@Override
public void removeById(ByteBuffer key) {
LOG.debug("Remove endpoint configuration by hash [{}] ", key);
if (key != null) {
removeByHash(getBytes(key));
}
}
}