View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.provisioning.api.utils;
20  
21  import java.util.Optional;
22  import org.apache.syncope.common.lib.to.ConnPoolConfTO;
23  import org.apache.syncope.core.persistence.api.entity.ConnPoolConf;
24  import org.identityconnectors.common.pooling.ObjectPoolConfiguration;
25  
26  public final class ConnPoolConfUtils {
27  
28      public static ConnPoolConf getConnPoolConf(final ConnPoolConfTO cpcto, final ConnPoolConf cpc) {
29          ObjectPoolConfiguration opc = new ObjectPoolConfiguration();
30  
31          cpc.setMaxIdle(Optional.ofNullable(cpcto.getMaxIdle()).orElse(opc.getMaxIdle()));
32          cpc.setMaxObjects(Optional.ofNullable(cpcto.getMaxObjects()).orElse(opc.getMaxObjects()));
33          cpc.setMaxWait(Optional.ofNullable(cpcto.getMaxWait()).orElse(opc.getMaxWait()));
34          cpc.setMinEvictableIdleTimeMillis(
35                  Optional.ofNullable(cpcto.getMinEvictableIdleTimeMillis()).orElse(opc.getMinEvictableIdleTimeMillis()));
36          cpc.setMinIdle(Optional.ofNullable(cpcto.getMinIdle()).orElse(opc.getMinIdle()));
37  
38          return cpc;
39      }
40  
41      public static ObjectPoolConfiguration getObjectPoolConfiguration(final ConnPoolConf cpc) {
42          ObjectPoolConfiguration opc = new ObjectPoolConfiguration();
43          updateObjectPoolConfiguration(opc, cpc);
44          return opc;
45      }
46  
47      public static void updateObjectPoolConfiguration(final ObjectPoolConfiguration opc, final ConnPoolConf cpc) {
48          if (cpc.getMaxIdle() != null) {
49              opc.setMaxIdle(cpc.getMaxIdle());
50          }
51          if (cpc.getMaxObjects() != null) {
52              opc.setMaxObjects(cpc.getMaxObjects());
53          }
54          if (cpc.getMaxWait() != null) {
55              opc.setMaxWait(cpc.getMaxWait());
56          }
57          if (cpc.getMinEvictableIdleTimeMillis() != null) {
58              opc.setMinEvictableIdleTimeMillis(cpc.getMinEvictableIdleTimeMillis());
59          }
60          if (cpc.getMinIdle() != null) {
61              opc.setMinIdle(cpc.getMinIdle());
62          }
63      }
64  
65      private ConnPoolConfUtils() {
66          // empty constructor for static utility class
67      }
68  }