aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/dblib/src/main/java
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-03-02 12:06:07 +0530
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-03-10 10:46:55 +0530
commit6b8e4f12fc66a64fa5c5498d06891f1f5f1189ac (patch)
tree6414988944a78393509923a5ace70d66db0b29bd /sdnr/wt/data-provider/dblib/src/main/java
parentd944abfab1a53a462868ae805ab5372935f854ef (diff)
Upgrade parents to 2.5.4-SNAPSHOT
Code changes as a result of changes induced by ODL Chlorine SR1 Issue-ID: CCSDK-3856 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ic08786f050e58bdb8371c8f8c25fb0db9f258cd4 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/dblib/src/main/java')
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java141
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java4
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java36
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java26
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java89
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java56
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java5
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java7
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java60
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java210
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java165
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java87
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java4
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java2
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java34
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java33
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java4
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java4
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java45
19 files changed, 670 insertions, 342 deletions
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java
deleted file mode 100644
index fbd105aa1..000000000
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : ccsdk features
- * ================================================================================
- * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
- * =================================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- *
- */
-package org.onap.ccsdk.features.sdnr.wt.dataprovider.database;
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateNetworkElementConnectionOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadNetworkElementConnectionListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mDeviceListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mLtpListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hDeviceListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hLtpListOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadStatusOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionOutputBuilder;
-
-
-public interface DatabaseDataProvider {
-
- HtDatabaseClient getRawClient();
-
- ReadFaultcurrentListOutputBuilder readFaultCurrentList(EntityInput input);
-
- ReadFaultlogListOutputBuilder readFaultLogList(EntityInput input);
-
- ReadCmlogListOutputBuilder readCMLogList(EntityInput input);
-
- ReadMaintenanceListOutputBuilder readMaintenanceList(EntityInput input);
-
- ReadMediatorServerListOutputBuilder readMediatorServerList(EntityInput input);
-
- ReadNetworkElementConnectionListOutputBuilder readNetworkElementConnectionList(EntityInput input);
-
- ReadInventoryListOutputBuilder readInventoryList(EntityInput input);
-
- ReadConnectionlogListOutputBuilder readConnectionlogList(EntityInput input);
-
- ReadEventlogListOutputBuilder readEventlogList(EntityInput input) throws IOException;
-
- ReadPmdata15mListOutputBuilder readPmdata15mList(EntityInput input);
-
- ReadPmdata24hListOutputBuilder readPmdata24hList(EntityInput input);
-
- ReadPmdata15mLtpListOutputBuilder readPmdata15mLtpList(EntityInput input) throws IOException;
-
- ReadPmdata15mDeviceListOutputBuilder readPmdata15mDeviceList(EntityInput input) throws IOException;
-
- ReadPmdata24hLtpListOutputBuilder readPmdata24hLtpList(EntityInput input) throws IOException;
-
- ReadPmdata24hDeviceListOutputBuilder readPmdata24hDeviceList(EntityInput input) throws IOException;
-
- ReadStatusOutputBuilder readStatus(EntityInput input) throws IOException;
-
- boolean waitForYellowDatabaseStatus(long timeout, TimeUnit unit);
-
- CreateNetworkElementConnectionOutputBuilder createNetworkElementConnection(NetworkElementConnectionEntity input)
- throws IOException;
-
- UpdateNetworkElementConnectionOutputBuilder updateNetworkElementConnection(
- UpdateNetworkElementConnectionInput input) throws IOException;
-
- DeleteNetworkElementConnectionOutputBuilder deleteNetworkElementConnection(
- DeleteNetworkElementConnectionInput input) throws IOException;
-
- DeleteMediatorServerOutputBuilder deleteMediatorServer(DeleteMediatorServerInput input) throws IOException;
-
- DeleteMaintenanceOutputBuilder deleteMaintenance(DeleteMaintenanceInput input) throws IOException;
-
- UpdateMaintenanceOutputBuilder updateMaintenance(UpdateMaintenanceInput input) throws IOException;
-
- UpdateMediatorServerOutputBuilder updateMediatorServer(UpdateMediatorServerInput input) throws IOException;
-
- CreateMaintenanceOutputBuilder createMaintenance(CreateMaintenanceInput input) throws IOException;
-
- CreateMediatorServerOutputBuilder createMediatorServer(CreateMediatorServerInput input) throws IOException;
-
- ReadGuiCutThroughEntryOutputBuilder readGuiCutThroughEntry(EntityInput input);
-
- DataProvider getDataProvider();
-
- HtDatabaseMaintenance getHtDatabaseMaintenance();
-
- HtDatabaseMediatorserver getHtDatabaseMediatorServer();
-
- HtUserdataManager getUserManager();
-
-}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java
index b93145cbb..dc1241156 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java
@@ -63,7 +63,6 @@ public class SqlDBClient {
private static final String SELECT_VERSION_QUERY = "SELECT @@version as version";
private static final String DBNAME_DEFAULT = "sdnrdb";
- private static final int DEFAULT_POOLSIZE = 50;
private final String dbConnectionString;
private final String dbName;
private final String dbHost;
@@ -306,7 +305,8 @@ public class SqlDBClient {
}
public Connection getConnection() throws SQLException {
- return DriverManager.getConnection(this.dbConnectionString);
+ return this.connectionPool.getConnection();
+ //return DriverManager.getConnection(this.dbConnectionString);
}
public boolean delete(String query) throws SQLException {
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java
new file mode 100644
index 000000000..d2321fc2b
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data;
+
+import java.util.ArrayList;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+@SuppressWarnings("serial")
+public class PropertyList extends ArrayList<SqlPropertyInfo> {
+
+
+ public PropertyList(Class<? extends DataObject> clazz){
+ super(SqlDBMapper.getProperties(clazz));
+ }
+
+}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
index cb66fc6fb..d00941d86 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
@@ -28,7 +28,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.HtDatabaseEventsService;
@@ -39,9 +38,11 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlD
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBStatusReader;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.DeleteQuery;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInput;
@@ -64,6 +65,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder;
@@ -101,6 +103,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
private final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> maintenanceRW;
private final SqlDBStatusReader readStatus;
private final HtUserdataManager usermanager;
+ private final InventoryTreeProvider inventoryTreeProvider;
public SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> getMaintenanceReaderWriter() {
@@ -145,6 +148,8 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
LOG.warn("problem setting controllerId: ", e);
}
}
+ this.inventoryTreeProvider = new SqlDbInventoryTreeProvider(this.dbClient, this.getControllerId());
+
}
@@ -242,6 +247,17 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
}
@Override
+ public ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input) {
+ ReadInventoryDeviceListOutputBuilder outputBuilder = new ReadInventoryDeviceListOutputBuilder();
+ QueryResult<String> result = this.equipmentRW.getDataDeviceList(input);
+ outputBuilder.setPagination(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.device.list.output.PaginationBuilder(
+ result.getPagination()).build());
+ outputBuilder.setData(result.getResultSet());
+ return outputBuilder;
+ }
+
+ @Override
public ReadConnectionlogListOutputBuilder readConnectionlogList(EntityInput input) {
ReadConnectionlogListOutputBuilder outputBuilder = new ReadConnectionlogListOutputBuilder();
QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> result =
@@ -504,7 +520,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
}
LOG.info("set controllerId {}", this.controllerId);
String query =
- String.format("SELECT * FROM `%s` WHERE `id`='%s';", this.controllerTableName, this.controllerId);
+ String.format("SELECT * FROM `%s` WHERE `id`='%s'", this.controllerTableName, this.controllerId);
LOG.trace(query);
ResultSet data = this.dbClient.read(query);
@@ -515,6 +531,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
try { if(data!=null){data.close();} } catch (SQLException ignore) { }
return this.dbClient.write(query);
} else {
+ this.controllerId = data.getString(0);
LOG.trace("controllerId already set");
}
return true;
@@ -533,5 +550,10 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
return this.usermanager;
}
+ @Override
+ public InventoryTreeProvider getInventoryTreeProvider() {
+ return this.inventoryTreeProvider;
+ }
+
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java
new file mode 100644
index 000000000..425007016
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java
@@ -0,0 +1,89 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.BaseInventoryTreeProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Sortorder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.SortorderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.SortorderKey;
+
+public class SqlDbInventoryTreeProvider extends BaseInventoryTreeProvider {
+ private final SqlDBReaderWriter<Inventory> dbReader;
+
+ public SqlDbInventoryTreeProvider(SqlDBClient dbClient, String controllerId) {
+ this.dbReader = new SqlDBReaderWriter<>(dbClient, Entity.Inventoryequipment, "", Inventory.class, controllerId);
+ }
+
+ @Override
+ protected List<String> getAllNodeIds() {
+ return this.dbReader.readAll(INVENTORY_PROPERTY_NODEID);
+ }
+
+ @Override
+ protected List<InventoryEntity> search(String filter, String sortOrderProperty, SortOrder sortOrder) {
+ return new ArrayList<>(this.dbReader.searchAll(Inventory.class, null, filter));
+ }
+
+ @Override
+ protected List<InventoryEntity> search(String filter, String nodeId, String parentUuid, String uuid,
+ String sortOrderProperty, SortOrder sortOrder) {
+ List<Filter> filters = new ArrayList<>();
+ if (nodeId != null) {
+ filters.add(new FilterBuilder().setProperty(INVENTORY_PROPERTY_NODEID).setFiltervalue(nodeId).build());
+ }
+ EntityInput input = new ReadInventoryListInputBuilder()
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class, filters)).build();
+ return new ArrayList<>(this.dbReader.searchAll(Inventory.class, input, filter));
+ }
+
+ @Override
+ protected List<InventoryEntity> getItemsForNodes(List<String> nodeIds, String sortOrderProperty,
+ SortOrder sortOrder) {
+ Map<FilterKey, Filter> nodeFilter = new HashMap<>();
+ Filter filter = new FilterBuilder().setProperty(INVENTORY_PROPERTY_NODEID)
+ .setFiltervalues(nodeIds.stream().collect(Collectors.toSet())).build();
+ nodeFilter.put(filter.key(), filter);
+ Map<SortorderKey, Sortorder> so = new HashMap<>();
+ Sortorder soItem = new SortorderBuilder().setProperty(sortOrderProperty)
+ .setSortorder(YangHelper2.getSortOrder(sortOrder)).build();
+ so.put(soItem.key(), soItem);
+ EntityInput input = new ReadInventoryListInputBuilder().setFilter(nodeFilter).setSortorder(so).build();
+ return new ArrayList<>(this.dbReader.readAll(Inventory.class, input));
+ }
+}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java
new file mode 100644
index 000000000..76e5d70fe
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data;
+
+import java.lang.reflect.Method;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper;
+
+public class SqlPropertyInfo {
+
+ private final Class<?> javaType;
+ private final String name;
+ private final String sqlType;
+
+ public SqlPropertyInfo(Method method) throws SqlDBMapper.UnableToMapClassException {
+ this.name = SqlDBMapper.getColumnName(method);
+ this.javaType = method.getReturnType();
+ this.sqlType = SqlDBMapper.getDBType(this.javaType);
+ }
+
+ public SqlPropertyInfo(String name, Class<?> javaType, String sqlType){
+ this.name =name;
+ this.javaType = javaType;
+ this.sqlType = sqlType;
+ }
+
+ public boolean isSqlStringType(){
+ return String.class.equals(this.javaType);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getSqlType() {
+ return sqlType;
+ }
+}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java
index bb1268cc9..b10aaaa60 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java
@@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.processing.Generated;
-import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.AbstractAugmentable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -71,7 +70,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
*
*/
@Generated("mdsal-binding-generator")
-public class UserdataBuilder implements Builder<Userdata> {
+public class UserdataBuilder {
private String _id;
private String _value;
@@ -148,7 +147,7 @@ public class UserdataBuilder implements Builder<Userdata> {
return this;
}
- @Override
+
public Userdata build() {
return new UserdataImpl(this);
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java
index 776c91fe5..09baa3775 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java
@@ -35,6 +35,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterFault;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterInventory;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterPm;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
@@ -68,12 +69,12 @@ public class HtDatabaseEventsService implements DataProvider {
private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();;
protected final SqlDBClient dbClient;
- protected final String controllerId;
+ protected String controllerId;
protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> connectionlogRW;
protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.eventlog.list.output.Data> eventlogRW;
protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultlog.list.output.Data> eventRWFaultLog;
protected final SqlDBReaderWriterFault<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data> eventRWFaultCurrent;
- protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data> equipmentRW;
+ protected final SqlDBReaderWriterInventory<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data> equipmentRW;
protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.gui.cut.through.entry.output.Data> guicutthroughRW;
protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data> networkelementConnectionRW;
protected final SqlDBReaderWriterPm<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data> pm15mRW;
@@ -101,7 +102,7 @@ public class HtDatabaseEventsService implements DataProvider {
this.eventRWFaultCurrent = new SqlDBReaderWriterFault<>(dbClient, Entity.Faultcurrent, config.getDbSuffix(),
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data.class,
this.controllerId);
- this.equipmentRW = new SqlDBReaderWriter<>(dbClient, Entity.Inventoryequipment, config.getDbSuffix(),
+ this.equipmentRW = new SqlDBReaderWriterInventory<>(dbClient, Entity.Inventoryequipment, config.getDbSuffix(),
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data.class,
this.controllerId);
this.guicutthroughRW = new SqlDBReaderWriter<>(dbClient,
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
index 1c24636db..8167c7bbf 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
@@ -34,7 +34,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
+import java.util.stream.Collectors;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlPropertyInfo;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBKeyValuePair;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
@@ -91,8 +92,7 @@ public class SqlDBMapper {
}
public static <T> String createTable(Class<T> clazz, Entity e, String suffix, boolean autoIndex,
- boolean withControllerId)
- throws UnableToMapClassException {
+ boolean withControllerId) throws UnableToMapClassException {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE IF NOT EXISTS `" + e.getName() + suffix + "` (\n");
if (autoIndex) {
@@ -101,7 +101,7 @@ public class SqlDBMapper {
} else {
sb.append("`" + ID_DBCOL + "` " + STRING_DBTYPE + " " + getColumnOptions(ID_DBCOL, STRING_DBTYPE) + ",\n");
}
- if(withControllerId) {
+ if (withControllerId) {
sb.append("`" + ODLID_DBCOL + "` " + ODLID_DBTYPE + " " + getColumnOptions(ODLID_DBCOL, ODLID_DBTYPE) + ",\n");
}
for (Method method : getFilteredMethods(clazz, true)) {
@@ -115,7 +115,7 @@ public class SqlDBMapper {
sb.append("`" + colName + "` " + dbType + " " + options + ",\n");
}
sb.append("primary key(" + ID_DBCOL + ")");
- if(withControllerId) {
+ if (withControllerId) {
sb.append(",foreign key(`" + ODLID_DBCOL + "`) references " + TABLENAME_CONTROLLER + "(" + ID_DBCOL + ")");
}
@@ -138,6 +138,12 @@ public class SqlDBMapper {
return options.toString();
}
+ /**
+ *
+ * @param clazz Class to scan for methods for their properties
+ * @param getterOrSetter true for using only getters, false using setters
+ * @return
+ */
public static List<Method> getFilteredMethods(Class<?> clazz, boolean getterOrSetter) {
Method[] methods = clazz.getMethods();
List<Method> list = new ArrayList<>();
@@ -220,7 +226,7 @@ public class SqlDBMapper {
return convertCamelToKebabCase(camelName);
}
- private static String getDBType(Class<?> valueType) throws UnableToMapClassException {
+ public static String getDBType(Class<?> valueType) throws UnableToMapClassException {
String type = mariaDBTypeMap.getOrDefault(valueType, null);
if (type == null) {
if (implementsInterface(valueType, DataObject.class) || implementsInterface(valueType, List.class)
@@ -292,6 +298,16 @@ public class SqlDBMapper {
return result.toString();
}
+ public static List<SqlPropertyInfo> getProperties(Class<? extends DataObject> clazz) {
+ return getFilteredMethods(clazz, true).stream().map(e -> {
+ try {
+ return new SqlPropertyInfo(e);
+ } catch (UnableToMapClassException ex) {
+ throw new RuntimeException(ex);
+ }
+ }).collect(Collectors.toList());
+ }
+
public static class UnableToMapClassException extends Exception {
private static final long serialVersionUID = 1L;
@@ -307,11 +323,12 @@ public class SqlDBMapper {
}
public static String escape(String o) {
- return o.replace("'", "\'");
+ return o.replace("'", "\\'");
}
public static boolean isComplex(Class<?> valueType) {
- return DataObject.class.isAssignableFrom(valueType) || List.class.isAssignableFrom(valueType);
+ return DataObject.class.isAssignableFrom(valueType) || List.class.isAssignableFrom(valueType)
+ || Set.class.isAssignableFrom(valueType);
}
public static Object getNumericValue(Object value, Class<?> valueType) {
@@ -353,15 +370,15 @@ public class SqlDBMapper {
}
@SuppressWarnings("unchecked")
- public static <S,T> List<T> read(ResultSet data, Class<T> clazz, String column)
+ public static <S, T> List<T> read(ResultSet data, Class<T> clazz, String column)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException,
InstantiationException, SecurityException, NoSuchMethodException, JsonProcessingException {
- if(data==null) {
+ if (data == null) {
return Arrays.asList();
}
S builder = findPOJOBuilder(clazz);
- if(builder==null && column==null) {
- throw new InstantiationException("unable to find builder for class "+clazz.getName());
+ if (builder == null && column == null) {
+ throw new InstantiationException("unable to find builder for class " + clazz.getName());
}
List<T> list = new ArrayList<>();
@@ -387,13 +404,14 @@ public class SqlDBMapper {
}
@SuppressWarnings("unchecked")
- private static <S,T> T callBuild(S builder) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- Method method = builder.getClass().getMethod("build");
- return (T) method.invoke(builder);
- }
+ private static <S, T> T callBuild(S builder) throws NoSuchMethodException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Method method = builder.getClass().getMethod("build");
+ return (T) method.invoke(builder);
+ }
- @SuppressWarnings("unchecked")
- private static <S,T> S findPOJOBuilder(Class<T> ac) throws InstantiationException, IllegalAccessException,
+ @SuppressWarnings("unchecked")
+ private static <S, T> S findPOJOBuilder(Class<T> ac) throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException {
try {
String builder = null;
@@ -407,7 +425,7 @@ public class SqlDBMapper {
}
if (builder != null) {
Class<?> innerBuilder = YangToolsMapperHelper.findClass(builder);
- //Class<Builder<T>> builderClass = (Class<Builder<T>>) innerBuilder;
+ // Class<Builder<T>> builderClass = (Class<Builder<T>>) innerBuilder;
return (S) innerBuilder.getDeclaredConstructor().newInstance();
}
} catch (ClassNotFoundException e) {
@@ -464,9 +482,9 @@ public class SqlDBMapper {
} else if (dstType.equals(Long.class)) {
return value;
} else if (dstType.equals(Integer.class)) {
- return (int)value;
+ return (int) value;
} else if (dstType.equals(Byte.class)) {
- return (byte)value;
+ return (byte) value;
}
return null;
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java
new file mode 100644
index 000000000..9798d12f8
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java
@@ -0,0 +1,210 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SqlQuery;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class SqlDBReader<T extends DataObject> {
+ private static final Logger LOG = LoggerFactory.getLogger(SqlDBReader.class);
+
+ protected final Entity entity;
+ private final Class<T> clazz;
+ protected final SqlDBClient dbService;
+ protected final String controllerId;
+ protected final String tableName;
+ protected final boolean ignoreControllerId;
+ protected final PropertyList propertyList;
+ public SqlDBReader(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
+ String controllerId) {
+ this(dbService, e, dbSuffix, clazz, controllerId, false);
+ }
+
+ public SqlDBReader(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
+ String controllerId, boolean ignoreControllerId) {
+ this.dbService = dbService;
+ this.entity = e;
+ this.clazz = clazz;
+ this.tableName = this.entity.getName() + dbSuffix;
+ this.controllerId = controllerId;
+ this.ignoreControllerId = ignoreControllerId;
+ this.propertyList = new PropertyList(clazz);
+ }
+
+ public long count(List<Filter> filter) throws SQLException {
+ String query;
+ if (filter == null || filter.isEmpty()) {
+ // query = String.format("SELECT table_rows FROM `information_schema`.`tables` "
+ // + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName);
+ query = String.format("SELECT COUNT(`id`) FROM `%s`", this.tableName);
+ } else {
+ query = String.format("SELECT COUNT(`id`) FROM `%s` %s", this.tableName,
+ SqlQuery.getWhereExpression(filter));
+ }
+ ResultSet data = this.dbService.read(query);
+ if (data == null) {
+ return 0;
+ }
+ long cnt = 0;
+ if (data.next()) {
+ cnt = data.getLong(1);
+ }
+ try {
+ data.close();
+ } catch (SQLException ignore) {
+ }
+ return cnt;
+ }
+
+ public long count(List<Filter> list, String controllerId) throws SQLException {
+ if (list == null) {
+ list = new ArrayList<>();
+ }
+ Optional<Filter> cFilter =
+ list.stream().filter(e -> SqlDBMapper.ODLID_DBCOL.equals(e.getProperty())).findFirst();
+ if (!cFilter.isEmpty()) {
+ list.remove(cFilter.get());
+ }
+ if (controllerId != null) {
+ list.add(
+ new FilterBuilder().setProperty(SqlDBMapper.ODLID_DBCOL).setFiltervalue(this.controllerId).build());
+ }
+ return this.count(list);
+ }
+
+ public QueryResult<T> getData(EntityInput input) {
+ SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("query={}", query.toSql());
+ }
+ try {
+ ResultSet data = this.dbService.read(query.toSql());
+ List<T> mappedData = SqlDBMapper.read(data, clazz);
+ final Map<FilterKey, Filter> filter = input.getFilter();
+ try {
+ if (data != null) {
+ data.close();
+ }
+ } catch (SQLException ignore) {
+ }
+ long total = this.count(filter != null ? new ArrayList<>(filter.values()) : null, this.controllerId);
+ return new QueryResult<T>(mappedData, query.getPage(), query.getPageSize(), total);
+ } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
+ LOG.warn("problem reading data {}: ", this.entity, e);
+ }
+ return QueryResult.createEmpty();
+ }
+
+ public <S extends DataObject> List<S> readAll(Class<S> clazz) {
+ SelectQuery query = new SelectQuery(this.tableName, this.controllerId);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("query={}", query.toSql());
+ }
+ return this.readAll(clazz, query);
+ }
+
+ public <S extends DataObject> List<S> readAll(Class<S> clazz, EntityInput input) {
+ SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId);
+ return this.readAll(clazz, query);
+ }
+ public <S extends DataObject> List<S> searchAll(Class<S> clazz, EntityInput input, String searchTerm) {
+ SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId);
+ if(searchTerm!=null && !searchTerm.isEmpty()) {
+ query.setAllPropertyFilter(searchTerm, this.propertyList);
+ }
+ return this.readAll(clazz, query);
+ }
+ public <S extends DataObject> List<S> readAll(Class<S> clazz, SelectQuery query) {
+ try {
+ ResultSet data = this.dbService.read(query.toSql());
+ List<S> mappedData = SqlDBMapper.read(data, clazz);
+ try {
+ data.close();
+ } catch (SQLException ignore) {
+ }
+ return mappedData;
+ } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
+ LOG.warn("problem reading all data{}: ", this.entity, e);
+ }
+ return null;
+ }
+
+ public List<String> readAll(String key) {
+ SelectQuery query = new SelectQuery(this.tableName, key, this.controllerId).groupBy(key);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("query={}", query.toSql());
+ }
+ try {
+ ResultSet data = this.dbService.read(query.toSql());
+ List<String> mappedData = SqlDBMapper.read(data, String.class, key);
+ try {
+ data.close();
+ } catch (SQLException ignore) {
+ }
+ return mappedData;
+ } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
+ LOG.warn("problem reading all data {} for key: ", this.entity, key, e);
+ }
+ return null;
+ }
+
+ public T read(String id) {
+ SelectQuery query =
+ new SelectQuery(this.tableName, this.controllerId).addFilter(SqlDBMapper.ID_DBCOL, id);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("query={}", query.toSql());
+ }
+ T item = null;
+ try {
+ ResultSet data = this.dbService.read(query.toSql());
+ List<T> mappedData = SqlDBMapper.read(data, clazz);
+ item = mappedData.size() > 0 ? mappedData.get(0) : null;
+ } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
+ LOG.warn("problem reading data {}: ", this.entity, e);
+ }
+ return item;
+ }
+}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
index 56a986e55..0df2dc5d6 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
@@ -21,128 +21,39 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import java.lang.reflect.InvocationTargetException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.Nullable;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.DeleteQuery;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.InsertQuery;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SqlQuery;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.UpdateQuery;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.UpsertQuery;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SqlDBReaderWriter<T extends DataObject> {
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
- private static final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriter.class);
+public class SqlDBReaderWriter<T extends DataObject> extends SqlDBReader<T> {
- protected final Entity entity;
- private final Class<T> clazz;
- protected final SqlDBClient dbService;
- protected final String controllerId;
- protected final String tableName;
- private final boolean ignoreControllerId;
+ private static final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriter.class);
public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
String controllerId) {
- this(dbService, e, dbSuffix, clazz, controllerId, false);
+ super(dbService, e, dbSuffix, clazz, controllerId);
}
public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
String controllerId, boolean ignoreControllerId) {
- this.dbService = dbService;
- this.entity = e;
- this.clazz = clazz;
- this.tableName = this.entity.getName() + dbSuffix;
- this.controllerId = controllerId;
- this.ignoreControllerId = ignoreControllerId;
- }
-
- public long count(List<Filter> filter) throws SQLException {
- String query;
- if (filter == null || filter.isEmpty()) {
- // query = String.format("SELECT table_rows FROM `information_schema`.`tables` "
- // + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName);
- query = String.format("SELECT COUNT(`id`) FROM `%s`", this.tableName);
- } else {
- query = String.format("SELECT COUNT(`id`) FROM `%s` %s", this.tableName,
- SqlQuery.getWhereExpression(filter));
- }
- ResultSet data = this.dbService.read(query);
- if(data==null) {
- return 0;
- }
- long cnt = 0;
- if (data.next()) {
- cnt = data.getLong(1);
- }
- try {
- data.close();
- } catch (SQLException ignore) {
- }
- return cnt;
- }
-
- public long count(List<Filter> list, String controllerId) throws SQLException {
- if (list == null) {
- list = new ArrayList<>();
- }
- Optional<Filter> cFilter =
- list.stream().filter(e -> SqlDBMapper.ODLID_DBCOL.equals(e.getProperty())).findFirst();
- if (!cFilter.isEmpty()) {
- list.remove(cFilter.get());
- }
- if (controllerId != null) {
- list.add(
- new FilterBuilder().setProperty(SqlDBMapper.ODLID_DBCOL).setFiltervalue(this.controllerId).build());
- }
- return this.count(list);
- }
-
- public QueryResult<T> getData(EntityInput input) {
- SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId);
- if (LOG.isTraceEnabled()) {
- LOG.trace("query={}", query.toSql());
- }
- try {
- ResultSet data = this.dbService.read(query.toSql());
- List<T> mappedData = SqlDBMapper.read(data, clazz);
- final Map<FilterKey, Filter> filter = input.getFilter();
- try {
- if(data!=null) {
- data.close();
- }
- } catch (SQLException ignore) {
- }
- long total = this.count(filter != null ? new ArrayList<>(filter.values()) : null, this.controllerId);
- return new QueryResult<T>(mappedData, query.getPage(), query.getPageSize(), total);
- } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
- LOG.warn("problem reading data {}: ", this.entity, e);
- }
- return QueryResult.createEmpty();
+ super(dbService, e, dbSuffix, clazz, controllerId, ignoreControllerId);
}
-
-
public <S extends DataObject> String write(S object, String id) {
if (id == null) {
return this.writeWithoutId(object);
@@ -309,62 +220,4 @@ public class SqlDBReaderWriter<T extends DataObject> {
public int remove(@Nullable String id) {
return this.remove(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(id).build()));
}
-
- public <S extends DataObject> List<S> readAll(Class<S> clazz) {
- SelectQuery query = new SelectQuery(this.tableName);
- if (LOG.isTraceEnabled()) {
- LOG.trace("query={}", query.toSql());
- }
- try {
- ResultSet data = this.dbService.read(query.toSql());
- List<S> mappedData = SqlDBMapper.read(data, clazz);
- try {
- data.close();
- } catch (SQLException ignore) {
- }
- return mappedData;
- } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
- LOG.warn("problem reading all data{}: ", this.entity, e);
- }
- return null;
- }
-
- public List<String> readAll(String key) {
- SelectQuery query = new SelectQuery(this.tableName, key, this.controllerId).groupBy(key);
- if (LOG.isTraceEnabled()) {
- LOG.trace("query={}", query.toSql());
- }
- try {
- ResultSet data = this.dbService.read(query.toSql());
- List<String> mappedData = SqlDBMapper.read(data, String.class, key);
- try {
- data.close();
- } catch (SQLException ignore) {
- }
- return mappedData;
- } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
- LOG.warn("problem reading all data {} for key: ", this.entity, key, e);
- }
- return null;
- }
-
- public T read(String id) {
- SelectQuery query =
- new SelectQuery(this.tableName, this.controllerId).addFilter(SqlDBMapper.ID_DBCOL, id);
- if (LOG.isTraceEnabled()) {
- LOG.trace("query={}", query.toSql());
- }
- T item = null;
- try {
- ResultSet data = this.dbService.read(query.toSql());
- List<T> mappedData = SqlDBMapper.read(data, clazz);
- item = mappedData.size()>0? mappedData.get(0): null;
- } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
- LOG.warn("problem reading data {}: ", this.entity, e);
- }
- return item;
- }
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java
new file mode 100644
index 000000000..5ed44cb29
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SqlDBReaderWriterInventory<T extends DataObject> extends SqlDBReaderWriter<T> {
+
+ private final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriterInventory.class);
+
+ private static final String KEY = "node-id";
+
+ private static final FilterKey FILTERKEY = new FilterKey(KEY);
+
+ public SqlDBReaderWriterInventory(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
+ String controllerId) {
+ super(dbService, e, dbSuffix, clazz, controllerId);
+ }
+
+ /**
+ * get aggregated devices list
+ *
+ * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name')
+ * @return
+ */
+ public QueryResult<String> getDataDeviceList(EntityInput input) {
+
+ SelectQuery query = new SelectQuery(this.tableName, KEY, this.controllerId).groupBy(KEY);
+ query.setPagination(input.getPagination());
+ Map<FilterKey, Filter> filter = input.getFilter();
+ if (filter != null) {
+ for (Filter f : filter.values()) {
+ query.addFilter(f.getProperty(), f.getFiltervalue());
+ }
+ }
+
+ try {
+ ResultSet data = this.dbService.read(query.toSql());
+ List<String> mappedData = SqlDBMapper.read(data, String.class, KEY);
+ try { data.close(); } catch (SQLException ignore) { }
+ Map<FilterKey, Filter> inpFilter = input.getFilter();
+ long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId);
+ return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total);
+ } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
+ LOG.warn("problem reading device list: ", e);
+ }
+ return null;
+ }
+
+
+}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java
index 258cd160f..398e9501a 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java
@@ -30,8 +30,4 @@ public class SqlDBReaderWriterUserdata extends SqlDBReaderWriter<Userdata> {
public SqlDBReaderWriterUserdata(SqlDBClient dbService, Entity e, String dbSuffix) {
super(dbService, e, dbSuffix, Userdata.class, null, true);
}
-
-
-
-
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java
index f52fbd55a..c505816ef 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java
@@ -107,7 +107,7 @@ public class InsertQuery<T extends DataObject> implements SqlQuery {
}
if (this.id != null && !cols.contains("`id`")) {
cols.add("`id`");
- args.add("'" + this.id + "'");
+ args.add("'" + SqlDBMapper.escape(this.id) + "'");
}
if (!this.ignoreControllerId) {
args.add("'" + this.controllerId + "'");
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
index a4df26bae..48165f1bf 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
@@ -28,7 +28,9 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.Nullable;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.SqlDBSearchFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SortOrder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
@@ -49,10 +51,12 @@ public class SelectQuery implements SqlQuery {
private final String tableName;
private final List<Filter> filters;
private final List<String> sortExpressions;
+ private final String controllerId;
private long page;
private long pageSize;
private final List<String> fields;
private final List<String> groups;
+ private SqlDBSearchFilter allPropertyFilter;
public SelectQuery(String tableName) {
this(tableName, (String)null);
@@ -68,6 +72,8 @@ public class SelectQuery implements SqlQuery {
this.groups = new ArrayList<>();
this.page = DEFAULT_PAGE;
this.pageSize = DEFAULT_PAGESIZE;
+ this.controllerId = controllerId;
+ this.allPropertyFilter = null;
if (controllerId != null) {
this.addFilter(SqlDBMapper.ODLID_DBCOL, controllerId);
}
@@ -146,7 +152,9 @@ public class SelectQuery implements SqlQuery {
public void addSortOrder(String col, String order) {
this.sortExpressions.add(String.format("`%s` %s", col, order));
}
-
+ public void setAllPropertyFilter(String filter, PropertyList propertyList) {
+ this.allPropertyFilter = new SqlDBSearchFilter(propertyList, filter);
+ }
public void setPagination(long page, long pageSize) {
this.page = page;
this.pageSize = pageSize;
@@ -175,7 +183,7 @@ public class SelectQuery implements SqlQuery {
} else {
sb.append(String.format("SELECT `%s` FROM `%s`", String.join("`,`", this.fields), this.tableName));
}
- sb.append(SqlQuery.getWhereExpression(this.filters));
+ sb.append(SqlQuery.getWhereExpression(this.filters, this.controllerId, this.allPropertyFilter));
if (this.groups.size() > 0) {
sb.append(String.format(" GROUP BY `%s`", String.join("`,`", this.groups)));
}
@@ -198,5 +206,27 @@ public class SelectQuery implements SqlQuery {
this.groups.add(group);
return this;
}
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SelectQuery [tableName=");
+ builder.append(tableName);
+ builder.append(", filters=");
+ builder.append(filters);
+ builder.append(", sortExpressions=");
+ builder.append(sortExpressions);
+ builder.append(", page=");
+ builder.append(page);
+ builder.append(", pageSize=");
+ builder.append(pageSize);
+ builder.append(", fields=");
+ builder.append(fields);
+ builder.append(", groups=");
+ builder.append(groups);
+ builder.append("]");
+ return builder.toString();
+ }
+
+
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java
index c954faadb..89638cc8b 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java
@@ -36,6 +36,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlD
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBFilterKeyValuePair;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.RangeSqlDBFilter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.RegexSqlDBFilter;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.SqlDBSearchFilter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
@@ -58,26 +59,32 @@ public interface SqlQuery {
return getWhereExpression(filters, null);
}
public static String getWhereExpression(Collection<Filter> filters, String controllerId) {
+ return getWhereExpression(filters, controllerId, null);
+ }
+ public static String getWhereExpression(Collection<Filter> filters, String controllerId, SqlDBSearchFilter allPropertyFilter) {
if (filters == null && controllerId == null) {
return "";
}
StringBuilder sb = new StringBuilder();
List<String> filters2 =
filters != null
- ? filters.stream().filter(e -> !"*".equals(e.getFiltervalue())).map(e -> getFilterExpression(e))
+ ? filters.stream().filter(e -> !isFilterEmpty(e)).map(e -> getFilterExpression(e))
.collect(Collectors.toList())
: new ArrayList<>();
- if(controllerId!=null) {
+ if (controllerId != null) {
filters2.add(getFilterExpression(SqlDBMapper.ODLID_DBCOL, controllerId));
}
- if (!filters2.isEmpty() ) {
+ if(allPropertyFilter!=null){
+ filters2.add(allPropertyFilter.getFilterExpression(true));
+ }
+ if (!filters2.isEmpty()) {
sb.append(" WHERE ");
sb.append(StringUtil.join(" AND ", filters2));
}
return sb.toString();
}
- public static String getFilterExpression(Filter filter) {
+ private static String getFilterExpression(Filter filter) {
String property = filter.getProperty();
List<String> values = collectValues(filter.getFiltervalue(), filter.getFiltervalues()).stream()
.filter(e -> !"*".equals(e)).collect(Collectors.toList());
@@ -95,7 +102,7 @@ public interface SqlQuery {
return null;
}
- public static String getFilterExpression(String property, String value) {
+ private static String getFilterExpression(String property, String value) {
String filter = null;
if (DbFilter.hasSearchParams(value)) {
if (TIMESTAMPPROPERTYNAMES.contains(property.toLowerCase())) {
@@ -118,7 +125,7 @@ public interface SqlQuery {
return new DBFilterKeyValuePair(property, value).getFilterExpression();
}
- static List<String> collectValues(String filtervalue, Set<String> filtervalues) {
+ private static List<String> collectValues(String filtervalue, Set<String> filtervalues) {
if (filtervalues == null) {
return Arrays.asList(filtervalue);
}
@@ -367,4 +374,18 @@ public interface SqlQuery {
return upperEnd;
}
+
+ private static boolean isFilterEmpty(Filter filter) {
+ @Nullable Set<String> filtervalues = filter.getFiltervalues();
+ @Nullable String filtervalue = filter.getFiltervalue();
+
+ List<String> allValues = filtervalues == null ? new ArrayList<>() : new ArrayList<>(filtervalues);
+ if (filtervalue != null) {
+ allValues.add(filtervalue);
+ }
+
+ return allValues.isEmpty() || allValues.contains("*");
+ }
+
+
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java
index 70b683a1a..7ea393da5 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java
@@ -23,6 +23,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filter
import java.math.BigInteger;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper;
+
public class DBKeyValuePair<T> implements SqlDBFilter {
private final String key;
@@ -62,7 +64,7 @@ public class DBKeyValuePair<T> implements SqlDBFilter {
} else if (this.getValue() instanceof BigInteger) {
return String.format("`%s`=%d", this.key, (BigInteger)this.value);
} else {
- return String.format("`%s`='%s'", this.key, this.value);
+ return String.format("`%s`='%s'", this.key, SqlDBMapper.escape(this.value));
}
}
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java
index 2997c7040..3ff2bdbea 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java
@@ -25,4 +25,8 @@ public interface SqlDBFilter {
public String getFilterExpression();
+ default String getFilterExpression(boolean enclose) {
+ return enclose ? String.format("(%s)", this.getFilterExpression()) : this.getFilterExpression();
+ }
+
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java
new file mode 100644
index 000000000..db5f2cb3b
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters;
+
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class SqlDBSearchFilter implements SqlDBFilter {
+ private final PropertyList propertyList;
+ private final String filter;
+
+ public SqlDBSearchFilter(PropertyList propertyList, String filter) {
+ this.propertyList = propertyList;
+ this.filter = filter;
+ }
+
+ @Override
+ public String getFilterExpression() {
+ List<String> tmp = this.propertyList.stream()
+ .map(e -> new RegexSqlDBFilter(e.getName(), this.filter).getFilterExpression())
+ .collect(Collectors.toList());
+ return String.join(" OR ", tmp);
+ }
+}