Skip to content
Snippets Groups Projects
Commit 11604b4f authored by Dongyue Mou's avatar Dongyue Mou
Browse files

added migration service for model upgrade

refs 1376
parent dd0f7311
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IMigrationService;
import org.fortiss.tooling.kernel.service.base.IObjectAware;
/**
* Interface for the migration provider implementations.
* <P>
* migration provider extensions are handled by {@link IMigrationService}.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED
*/
public interface IMigrationProvider extends IObjectAware<ITopLevelElement> {
/**
* Determines whether migration provider is needed for the given
* model element.
*/
boolean needMigration(ITopLevelElement modelElement);
/** Applies the provider to the given element. */
void migrate(ITopLevelElement modelElement);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 ForTISS GmbH |
| |
| 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. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IMigrationService;
import org.fortiss.tooling.kernel.service.base.ObjectAwareServiceBase;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
/**
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class MigrationService extends ObjectAwareServiceBase<IMigrationProvider> implements
IMigrationService {
/** The connector extension point ID. */
private static final String EXTENSION_POINT_NAME =
"org.fortiss.tooling.kernel.migrationProvider";
/** The connector configuration element name. */
private static final String CONFIGURATION_ELEMENT_NAME = "migrationProvider";
/** The connector attribute name. */
private static final String ATTRIBUTE_NAME = "migrationProvider";
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement input) {
return getProvider(input) != null;
}
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement input) {
try {
IMigrationProvider provider;
while(null != (provider = getProvider(input))) {
provider.migrate(input);
}
input.doSave(new NullProgressMonitor());
} catch(Exception e) {
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Error during migration of model!", e);
if(e instanceof RuntimeException) {
throw (RuntimeException)e;
}
throw new RuntimeException(e);
}
}
/** get the suitable provider for the input */
private IMigrationProvider getProvider(ITopLevelElement input) {
for(IMigrationProvider provider : getAllHandlers()) {
if(provider.needMigration(input)) {
return provider;
}
}
return null;
}
/** {@inheritDoc} */
@Override
protected String getExtensionPointName() {
return EXTENSION_POINT_NAME;
}
/** {@inheritDoc} */
@Override
protected String getConfigurationElementName() {
return CONFIGURATION_ELEMENT_NAME;
}
/** {@inheritDoc} */
@Override
protected String getHandlerClassAttribute() {
return ATTRIBUTE_NAME;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.internal.MigrationService;
/**
* The migration service checks and upgrades the old models from the last release.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED
*/
public interface IMigrationService {
/** Returns the singleton instance of the service. */
public static final IMigrationService INSTANCE = new MigrationService();
/** Checks whether the migration is needed. */
public boolean needMigration(ITopLevelElement input);
/** Performs the migration for the given input. */
public void migrate(ITopLevelElement input);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment