2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.notification.dao.impl;
23 import com.datastax.driver.core.ResultSet;
24 import com.datastax.driver.core.Row;
25 import com.datastax.driver.mapping.Mapper;
26 import com.datastax.driver.mapping.Result;
27 import com.datastax.driver.mapping.annotations.Accessor;
28 import com.datastax.driver.mapping.annotations.Query;
29 import org.openecomp.core.dao.impl.CassandraBaseDao;
30 import org.openecomp.core.nosqldb.api.NoSqlDb;
31 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
32 import org.openecomp.sdc.notification.dao.LastNotificationDao;
33 import org.openecomp.sdc.notification.dao.types.LastSeenNotificationEntity;
35 import java.util.Collection;
36 import java.util.UUID;
39 public class LastNotificationDaoCassandraImpl extends CassandraBaseDao<LastSeenNotificationEntity> implements LastNotificationDao {
41 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
42 private static final Mapper<LastSeenNotificationEntity> mapper =
43 noSqlDb.getMappingManager().mapper(LastSeenNotificationEntity.class);
44 private static final LastNotificationAccessor accessor =
45 noSqlDb.getMappingManager().createAccessor(LastNotificationAccessor.class);
48 protected Mapper<LastSeenNotificationEntity> getMapper() {
53 protected Object[] getKeys(LastSeenNotificationEntity entity) {
54 return new Object[]{entity.getOwnerId()};
58 public Collection<LastSeenNotificationEntity> list(LastSeenNotificationEntity entity) {
59 return accessor.list(entity.getOwnerId()).all();
63 public UUID getOwnerLastEventId(String ownerId) {
64 ResultSet ownerLastEventId = accessor.getOwnerLastEventId(ownerId);
65 Row one = ownerLastEventId.one();
66 return one != null ? one.getUUID("event_id") : null;
70 public void persistOwnerLastEventId(String ownerId, UUID eventId) {
71 accessor.updateOwnerLastEventId(eventId, ownerId);
75 interface LastNotificationAccessor {
77 @Query("select * from last_notification where owner_id=?")
78 Result<LastSeenNotificationEntity> list(String ownerId);
80 @Query("select event_id from last_notification where owner_id=?")
81 ResultSet getOwnerLastEventId(String ownerId);
83 @Query("update last_notification set event_id=? where owner_id=?")
84 ResultSet updateOwnerLastEventId(UUID eventId, String ownerId);