ijokarumawak commented on a change in pull request #3341: NIFI-6082: Added 
DatabaseRecordLookupService, refactored common DB utils
URL: https://github.com/apache/nifi/pull/3341#discussion_r263674113
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/db/AbstractDatabaseLookupService.java
 ##########
 @@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.lookup.db;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.dbcp.DBCPService;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.util.db.JdbcCommon;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class AbstractDatabaseLookupService extends AbstractControllerService {
+
+    protected static final String KEY = "key";
+
+    protected static final Set<String> REQUIRED_KEYS = 
Collections.unmodifiableSet(Stream.of(KEY).collect(Collectors.toSet()));
+
+    static final PropertyDescriptor DBCP_SERVICE = new 
PropertyDescriptor.Builder()
+            .name("dbrecord-lookup-dbcp-service")
+            .displayName("Database Connection Pooling Service")
+            .description("The Controller Service that is used to obtain 
connection to database")
+            .required(true)
+            .identifiesControllerService(DBCPService.class)
+            .build();
+
+    static final PropertyDescriptor TABLE_NAME = new 
PropertyDescriptor.Builder()
+            .name("dbrecord-lookup-table-name")
+            .displayName("Table Name")
+            .description("The name of the database table to be queried. Note 
that this may be case-sensitive depending on the database.")
+            .required(true)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+            .build();
+
+    static final PropertyDescriptor LOOKUP_KEY_COLUMN = new 
PropertyDescriptor.Builder()
+            .name("dbrecord-lookup-key column")
+            .displayName("Lookup Key Column")
+            .description("The column in the table that will serve as the 
lookup key. This is the column that will be matched against "
+                    + "the property specified in the lookup processor. Note 
that this may be case-sensitive depending on the database.")
+            .required(true)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .build();
+
+    static final PropertyDescriptor CACHE_SIZE = new 
PropertyDescriptor.Builder()
+            .name("dbrecord-lookup-cache-size")
+            .displayName("Cache Size")
+            .description("Specifies how many lookup values/records should be 
cached. The cache is shared for all tables and keeps a map of lookup values to 
records. "
+                    + "Setting this property to zero means no caching will be 
done and the table will be queried for each lookup value in each record. If the 
lookup "
+                    + "table changes often or the most recent data must be 
retrieved, do not use the cache.")
+            .addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR)
+            .defaultValue("0")
+            .required(true)
+            .build();
+
+    static final PropertyDescriptor CLEAR_CACHE_ON_ENABLED = new 
PropertyDescriptor.Builder()
+            .name("dbrecord-lookup-clear-cache-on-enabled")
+            .displayName("Clear Cache on Enabled")
+            .description("Whether to clear the cache when this service is 
enabled. If the Cache Size is zero then this property is ignored. Clearing the 
cache when the "
+                    + "service is enabled ensures that the service will first 
go to the database to get the most recent data.")
+            .allowableValues("true", "false")
+            .addValidator(StandardValidators.BOOLEAN_VALIDATOR)
+            .defaultValue("true")
+            .required(true)
+            .build();
+
+    protected List<PropertyDescriptor> properties;
+
+    protected DBCPService dbcpService;
+
+    protected volatile String lookupKeyColumn;
+
+    protected volatile JdbcCommon.AvroConversionOptions options;
 
 Review comment:
   This AvroConversionOptions is only used when DatabaseRecordLookupService 
creates schema for resultSetRecordSet. Should be moved from 
AbstractDatabaseLookupService to DatabaseRecordLookupService.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to