001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.migration.version.impl; 017 018import java.time.Instant; 019 020import org.ametys.core.migration.action.data.ActionData; 021import org.ametys.core.migration.handler.VersionHandler; 022import org.ametys.core.migration.version.AbstractVersion; 023import org.ametys.core.migration.version.Version; 024 025/** 026 * SQL implementation of a version, contains also information about the datasource where the version will be stored 027 */ 028public class SqlVersion extends AbstractVersion 029{ 030 private String _datasourceId; 031 private String _databaseType; 032 033 /** 034 * Create a Version, with all standard informations, plus informations about the datasource 035 * @param versionHandlerId id of the {@link VersionHandler} 036 * @param componentId id of the component 037 * @param versionNumber version number of the upgrade that created this version 038 * @param executionInstant time of the application of this version 039 * @param comment comment stored about this version 040 * @param datasourceId datasource id 041 * @param databaseType database type 042 */ 043 public SqlVersion(String versionHandlerId, String componentId, String versionNumber, Instant executionInstant, String comment, String datasourceId, String databaseType) 044 { 045 super(versionHandlerId, componentId, versionNumber, executionInstant, comment); 046 _datasourceId = datasourceId; 047 _databaseType = databaseType; 048 } 049 050 /** 051 * Create a version from the data of an {@link ActionData} and its associated version. 052 * @param actionData The action data 053 */ 054 protected SqlVersion(ActionData actionData) 055 { 056 super(actionData); 057 SqlVersion version = (SqlVersion) actionData.getVersion(); 058 _datasourceId = version.getDatasourceId(); 059 _databaseType = version.getDatabaseType(); 060 } 061 062 @Override 063 public String toString() 064 { 065 String log = super.toString(); 066 log += " dataSource id: '" + _datasourceId + "', databaseType: '" + _databaseType + "'"; 067 return log; 068 } 069 070 /** 071 * Get the datasource id 072 * @return The datasource id 073 */ 074 public String getDatasourceId() 075 { 076 return _datasourceId; 077 } 078 079 /** 080 * Get the database type 081 * @return The database type 082 */ 083 public String getDatabaseType() 084 { 085 return _databaseType; 086 } 087 088 @Override 089 public Version copyFromActionData(ActionData actionData) 090 { 091 return new SqlVersion(actionData); 092 } 093}