/* * Copyright 2022 Anton Tananaev (anton@traccar.org) * * 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.traccar.storage; import org.traccar.model.BaseModel; import org.traccar.model.Permission; import org.traccar.storage.query.Request; import java.util.List; public abstract class Storage { public abstract List getObjects(Class clazz, Request request) throws StorageException; public abstract long addObject(T entity, Request request) throws StorageException; public abstract void updateObject(T entity, Request request) throws StorageException; public abstract void removeObject(Class clazz, Request request) throws StorageException; public abstract List getPermissions( Class ownerClass, long ownerId, Class propertyClass, long propertyId) throws StorageException; public abstract void addPermission(Permission permission) throws StorageException; public abstract void removePermission(Permission permission) throws StorageException; public List getPermissions( Class ownerClass, Class propertyClass) throws StorageException { return getPermissions(ownerClass, 0, propertyClass, 0); } public T getObject(Class clazz, Request request) throws StorageException { var objects = getObjects(clazz, request); return objects.isEmpty() ? null : objects.get(0); } }