You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/03/22 10:45:15 UTC
[2/2] syncope git commit: [SYNCOPE-1285] Now performing Quartz db
init only if table QRTZ_SCHEDULER_STATE is not found
[SYNCOPE-1285] Now performing Quartz db init only if table QRTZ_SCHEDULER_STATE is not found
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/2dfefb48
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/2dfefb48
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/2dfefb48
Branch: refs/heads/master
Commit: 2dfefb487d3e4b2fd59595a4e696b1dbcf78e318
Parents: b0179ec
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Thu Mar 22 11:44:38 2018 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Thu Mar 22 11:44:52 2018 +0100
----------------------------------------------------------------------
.../provisioning/java/job/SchedulerDBInit.java | 75 ++++++++++++++++++++
.../src/main/resources/provisioningContext.xml | 3 +-
2 files changed, 76 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/2dfefb48/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SchedulerDBInit.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SchedulerDBInit.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SchedulerDBInit.java
new file mode 100644
index 0000000..00bd68b
--- /dev/null
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SchedulerDBInit.java
@@ -0,0 +1,75 @@
+/*
+ * 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.syncope.core.provisioning.java.job;
+
+import javax.sql.DataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.jdbc.BadSqlGrammarException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.init.DatabasePopulator;
+import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
+import org.springframework.util.Assert;
+
+/**
+ * Ensure Quartz database initialization occurs only if Quartz tables are not already present.
+ *
+ * @see org.springframework.jdbc.datasource.init.DataSourceInitializer
+ */
+public class SchedulerDBInit implements InitializingBean {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SchedulerDBInit.class);
+
+ private DataSource dataSource;
+
+ private DatabasePopulator databasePopulator;
+
+ public void setDataSource(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void setDatabasePopulator(final DatabasePopulator databasePopulator) {
+ this.databasePopulator = databasePopulator;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ Assert.state(this.dataSource != null, "DataSource must be set");
+ Assert.state(this.databasePopulator != null, "DatabasePopulator must be set");
+
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
+ boolean existingData;
+ try {
+ existingData = jdbcTemplate.queryForObject("SELECT COUNT(0) FROM QRTZ_SCHEDULER_STATE", Integer.class) > 0;
+ } catch (BadSqlGrammarException e) {
+ LOG.debug("Could not access to table QRTZ_SCHEDULER_STATE", e);
+ existingData = false;
+ }
+
+ if (existingData) {
+ LOG.info("Quartz tables found in the database, leaving untouched");
+ } else {
+ LOG.info("No Quartz tables found, creating");
+
+ DatabasePopulatorUtils.execute(databasePopulator, this.dataSource);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/2dfefb48/core/provisioning-java/src/main/resources/provisioningContext.xml
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/resources/provisioningContext.xml b/core/provisioning-java/src/main/resources/provisioningContext.xml
index c049c6f..a301cb7 100644
--- a/core/provisioning-java/src/main/resources/provisioningContext.xml
+++ b/core/provisioning-java/src/main/resources/provisioningContext.xml
@@ -46,9 +46,8 @@ under the License.
<bean class="${groupProvisioningManager}"/>
<bean class="${anyObjectProvisioningManager}"/>
- <bean id="quartzDataSourceInit" class="org.springframework.jdbc.datasource.init.DataSourceInitializer">
+ <bean id="quartzDataSourceInit" class="org.apache.syncope.core.provisioning.java.job.SchedulerDBInit">
<property name="dataSource" ref="MasterDataSource"/>
- <property name="enabled" value="true"/>
<property name="databasePopulator">
<bean class="org.springframework.jdbc.datasource.init.ResourceDatabasePopulator">
<property name="continueOnError" value="true"/>