├── .github └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml ├── src └── assembly │ └── assembly.xml ├── upgrade-framework-core ├── instructions.bnd ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── vmware │ │ └── upgrade │ │ ├── PersistenceContext.java │ │ ├── Task.java │ │ ├── UpgradeContext.java │ │ ├── UpgradeDefinition.java │ │ ├── context │ │ ├── PersistenceContextHelper.java │ │ ├── PersistenceContextReference.java │ │ └── package-info.java │ │ ├── factory │ │ ├── CompositeUpgradeDefinitionFactory.java │ │ ├── GraphUpgradeDefinitionFactory.java │ │ ├── UpgradeDefinitionFactory.java │ │ └── package-info.java │ │ ├── logging │ │ ├── Log4jLoggerImpl.java │ │ ├── LogLevel.java │ │ ├── Logger.java │ │ ├── SecurityLevel.java │ │ ├── UpgradeLogger.java │ │ ├── UpgradeLoggerHelper.java │ │ ├── UpgradeLoggerImpl.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── progress │ │ ├── ExecutionState.java │ │ ├── ExecutionStateAggregator.java │ │ ├── ProgressReport.java │ │ ├── ProgressReporter.java │ │ ├── impl │ │ │ ├── AbstractProgressReporter.java │ │ │ ├── DefaultExecutionStateAggregator.java │ │ │ ├── ImmutableProgressReport.java │ │ │ ├── SimpleAggregatingProgressReporter.java │ │ │ ├── SimpleProgressReporter.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── sequencing │ │ ├── AbstractGraph.java │ │ ├── Graph.java │ │ ├── GraphHelper.java │ │ ├── Version.java │ │ └── package-info.java │ │ ├── task │ │ ├── AbstractAggregateTask.java │ │ ├── AbstractDelegatingTask.java │ │ ├── AbstractSimpleTask.java │ │ ├── AbstractTask.java │ │ ├── ParallelAggregateTask.java │ │ ├── SerialAggregateTask.java │ │ ├── TrivialTask.java │ │ └── package-info.java │ │ └── transformation │ │ ├── ReferenceTransformation.java │ │ └── Transformation.java │ └── test │ ├── java │ └── com │ │ └── vmware │ │ └── upgrade │ │ ├── DummyUpgradeContext.java │ │ ├── TestGroups.java │ │ ├── WorkflowTest.java │ │ ├── context │ │ └── PersistenceContextHelperTest.java │ │ ├── factory │ │ └── GraphUpgradeDefinitionFactoryTest.java │ │ ├── progress │ │ ├── DefaultExecutionStateAggregatorTest.java │ │ └── ProgressReportingTest.java │ │ ├── sequencing │ │ └── VersionTest.java │ │ └── task │ │ ├── AbstractDelegatingTaskTest.java │ │ ├── TaskAggregationTest.java │ │ ├── TaskTestUtil.java │ │ └── TrivialTaskTest.java │ └── resources │ └── testng.xml ├── upgrade-framework-distribution └── pom.xml ├── upgrade-framework-dsl ├── instructions.bnd ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── vmware │ │ └── upgrade │ │ └── dsl │ │ ├── Loader.groovy │ │ ├── Processor.java │ │ ├── TaskResolver.java │ │ ├── model │ │ ├── ManifestModel.groovy │ │ ├── NamespaceModel.groovy │ │ ├── UpgradeDefinitionModel.groovy │ │ ├── UpgradeTaskModel.groovy │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── syntax │ │ ├── ManifestSyntax.groovy │ │ ├── NamespaceSyntax.groovy │ │ ├── ScriptSyntax.groovy │ │ ├── UnknownKeywordWrapper.groovy │ │ ├── UpgradeCompilationException.groovy │ │ ├── UpgradeDefinitionSyntax.groovy │ │ └── package-info.java │ │ └── util │ │ ├── AggregateProcessor.java │ │ ├── BasicTaskResolver.groovy │ │ ├── FinalVariableBinding.java │ │ ├── NoopProcessor.java │ │ ├── NoopTaskResolver.java │ │ └── package-info.java │ └── test │ ├── java │ └── com │ │ └── vmware │ │ └── upgrade │ │ └── dsl │ │ ├── LoaderTest.groovy │ │ ├── ManifestLoader.groovy │ │ ├── syntax │ │ ├── BadSyntaxTest.java │ │ ├── FromToKeywordTest.java │ │ ├── NamespaceKeywordTest.java │ │ ├── RequiredKeywordProcessor.groovy │ │ ├── ResourceInclusionTest.groovy │ │ └── VersionKeywordTest.groovy │ │ └── util │ │ └── UpgradeLoader.groovy │ └── resources │ ├── testng.xml │ └── upgrade │ └── nullManifest.groovy ├── upgrade-framework-sql-dsl ├── instructions.bnd ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── vmware │ │ └── upgrade │ │ └── dsl │ │ └── sql │ │ ├── model │ │ ├── CommentModel.groovy │ │ ├── ConstraintModel.groovy │ │ ├── IndexModel.groovy │ │ ├── ReferenceModel.groovy │ │ ├── SQLStatementProxy.groovy │ │ ├── TableAlterationModel.groovy │ │ ├── TableCreationModel.groovy │ │ ├── TransformingModel.groovy │ │ ├── UnindexModel.groovy │ │ ├── UnreferenceModel.groovy │ │ ├── defaults │ │ │ ├── DefaultCommentModel.groovy │ │ │ ├── DefaultDropViewModel.groovy │ │ │ ├── DefaultIndexModel.groovy │ │ │ ├── DefaultReferenceModel.groovy │ │ │ ├── DefaultSQLStatementProxy.groovy │ │ │ ├── DefaultTableAlterationModel.groovy │ │ │ ├── DefaultTableCreationModel.groovy │ │ │ ├── DefaultUnindexModel.groovy │ │ │ └── DefaultUnreferenceModel.groovy │ │ ├── package-info.java │ │ └── safe │ │ │ ├── SafeCommentModel.groovy │ │ │ ├── SafeDropViewModel.groovy │ │ │ ├── SafeIndexModel.groovy │ │ │ ├── SafeReferenceModel.groovy │ │ │ ├── SafeSQLStatementProxy.groovy │ │ │ ├── SafeSQLStatementWrapper.groovy │ │ │ ├── SafeTableAlterationModel.groovy │ │ │ ├── SafeTableCreationModel.groovy │ │ │ ├── SafeUnindexModel.groovy │ │ │ └── SafeUnreferenceModel.groovy │ │ ├── package-info.java │ │ ├── syntax │ │ ├── ColumnType.groovy │ │ ├── CommentSyntax.groovy │ │ ├── Constraints.groovy │ │ ├── DataType.java │ │ ├── IndexSyntax.groovy │ │ ├── ReferenceSyntax.groovy │ │ ├── TableAlterationSyntax.groovy │ │ ├── TableCreationColumnSyntax.groovy │ │ ├── TableCreationSyntax.groovy │ │ ├── UnindexSyntax.groovy │ │ ├── UnreferenceSyntax.groovy │ │ └── package-info.java │ │ └── util │ │ ├── AgnosticSqlProcessor.groovy │ │ ├── BasicSqlProcessor.groovy │ │ ├── ClassUtil.groovy │ │ ├── ColumnTypeSyntaxUtil.groovy │ │ ├── ConstraintNameUtil.groovy │ │ ├── DefaultAware.java │ │ ├── HasClosureMap.java │ │ ├── InitialAware.java │ │ ├── NullAware.java │ │ ├── ReservedKeywords.groovy │ │ ├── SQLStatementFactory.java │ │ ├── SqlTaskResolver.groovy │ │ ├── TransformingModelTaskResolver.groovy │ │ └── ValidationUtil.groovy │ └── test │ ├── java │ └── com │ │ └── vmware │ │ └── upgrade │ │ └── dsl │ │ └── sql │ │ ├── semantics │ │ ├── AlterSemanticsTest.java │ │ ├── CommentSemanticsTest.java │ │ ├── CreateSemanticsTest.java │ │ ├── DropViewSemanticsTest.java │ │ ├── IndexSemanticsTest.java │ │ ├── ReferenceSemanticsTest.java │ │ ├── SafeSemanticsTest.java │ │ └── SemanticTestUtil.java │ │ ├── syntax │ │ ├── AlterSyntaxTest.java │ │ ├── CommentSyntaxTest.java │ │ ├── CreateSyntaxTest.java │ │ ├── DropViewSyntaxTest.java │ │ ├── IndexSyntaxTest.java │ │ ├── ReferenceSyntaxTest.java │ │ ├── SafeSyntaxTest.java │ │ └── SyntaxTestUtil.groovy │ │ └── util │ │ ├── ClassUtilTest.java │ │ ├── ConstraintNameUtilTest.java │ │ ├── DefaultTestProcessor.groovy │ │ └── UpgradeLoader.groovy │ └── resources │ └── testng.xml └── upgrade-framework-sql ├── instructions.bnd ├── pom.xml └── src ├── main └── java │ └── com │ └── vmware │ └── upgrade │ └── sql │ ├── DatabasePersistenceContext.java │ ├── DatabaseType.java │ ├── SQLStatement.java │ ├── package-info.java │ ├── script │ ├── SQLParsedDataAggregator.java │ ├── TaskAggregator.java │ └── package-info.java │ └── task │ ├── RawSQLTask.java │ ├── ScriptTask.java │ ├── TransactionTask.java │ └── package-info.java └── test ├── java └── com │ └── vmware │ └── upgrade │ └── sql │ └── task │ └── TransactionTaskTest.java └── resources └── testng.xml /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | pull_request: 10 | branches: [ "master" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Set up JDK 11 20 | uses: actions/setup-java@v3 21 | with: 22 | java-version: '11' 23 | distribution: 'temurin' 24 | cache: maven 25 | - name: Build with Maven 26 | run: mvn -B install --file pom.xml 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # System specific files 2 | *~ 3 | ._.* 4 | .DS_Store 5 | 6 | # Eclipse files and directories 7 | .classpath 8 | .project 9 | .settings/ 10 | 11 | # IntelliJ IDEA project stuff 12 | *.iml 13 | *.ipr 14 | *.iws 15 | 16 | # Visual Studio Code 17 | .vscode/ 18 | 19 | # Directories created during the build process 20 | target/ 21 | test-output/ 22 | build/ 23 | 24 | # Auto-generated OSGI manifests 25 | META-INF/ 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Data Persistence Upgrade Framework for Java 1.0 2 | Copyright (c) 2008-2018 VMware, Inc. 3 | All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /upgrade-framework-core/instructions.bnd: -------------------------------------------------------------------------------- 1 | Bundle-SymbolicName: com.vmware.upgrade 2 | Bundle-RequiredExecutionEnvironment: JavaSE-11 3 | Export-Package: * 4 | Import-Package: * 5 | -------------------------------------------------------------------------------- /upgrade-framework-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | upgrade-framework-core 8 | 9 | upgrade-framework-core - Core Upgrade Framework 10 | Library which provides core upgrade logic. 11 | 12 | jar 13 | 14 | 15 | com.vmware.vcloud 16 | upgrade-framework-parent 17 | 2.0.0 18 | ../pom.xml 19 | 20 | 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 26 | 27 | 28 | commons-math 29 | commons-math 30 | 31 | 32 | 33 | commons-collections 34 | commons-collections 35 | test 36 | 37 | 38 | 39 | ch.qos.reload4j 40 | reload4j 41 | 42 | 43 | 44 | com.fasterxml.jackson.core 45 | jackson-core 46 | 47 | 48 | 49 | com.fasterxml.jackson.core 50 | jackson-annotations 51 | 52 | 53 | 54 | com.fasterxml.jackson.core 55 | jackson-databind 56 | 57 | 58 | 59 | org.eclipse.osgi 60 | org.eclipse.osgi 61 | 62 | 63 | 64 | 65 | 66 | 67 | maven-compiler-plugin 68 | 69 | javac 70 | 71 | 72 | 73 | 74 | 75 | true 76 | 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-jar-plugin 82 | 83 | 84 | 85 | org.apache.felix 86 | maven-bundle-plugin 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/PersistenceContext.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade; 24 | 25 | /** 26 | * A {@link PersistenceContext} encapsulates the information about a particular persistence store 27 | * and specific implementations act as entry points suitable for interacting with specific types of 28 | * persistence mechanisms. 29 | * 30 | * @see UpgradeContext#getPersistenceContext(Class) 31 | * @see UpgradeContext#getPersistenceContext(Class, String) 32 | * 33 | * @author Zach Shepherd shepherdz@vmware.com 34 | * @version 1.0 35 | * @since 1.0 36 | */ 37 | public interface PersistenceContext { 38 | /** 39 | * Returns {@code true} if the context is in a usable state. 40 | * 41 | * @return Returns {@code true} if the context can be safely used. Returns {@code false} 42 | * otherwise. 43 | */ 44 | public boolean isConnected(); 45 | } 46 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/Task.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade; 24 | 25 | import java.util.concurrent.Callable; 26 | 27 | import com.vmware.upgrade.progress.ExecutionState; 28 | import com.vmware.upgrade.progress.ProgressReport; 29 | import com.vmware.upgrade.progress.ProgressReporter; 30 | import com.vmware.upgrade.progress.ProgressReporter.ProgressListener; 31 | 32 | /** 33 | * A {@link Task} represents some concrete piece of work to be performed as part of the upgrade 34 | * process. 35 | * 36 | * @author Zach Shepherd shepherdz@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | public interface Task extends Callable, ProgressReporter { 41 | /** 42 | * Returns a name for the task appropriate for displaying as part of a log statement, error 43 | * message, or progress information. 44 | * 45 | * @return a human-readable name for the task 46 | */ 47 | String getName(); 48 | 49 | /** 50 | * Perform the action represented by this {@link Task}. 51 | *

52 | * {@link ProgressReport}s are provided to {@link ProgressListener} to 53 | * indicate changes in {@link ExecutionState} or {@link ProgressReport#getProgress() progress}. 54 | */ 55 | @Override 56 | Void call() throws Exception; 57 | } 58 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/UpgradeDefinition.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2010-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade; 24 | 25 | import java.util.List; 26 | 27 | import com.vmware.upgrade.factory.UpgradeDefinitionFactory; 28 | 29 | /** 30 | * Encapsulates the {@link Task}s which define a given upgrade process. 31 | * 32 | * @see UpgradeDefinitionFactory 33 | * 34 | * @author Stephen Evanchik evanchik@vmware.com 35 | * @version 1.0 36 | * @since 1.0 37 | */ 38 | public interface UpgradeDefinition { 39 | /** 40 | * The {@link Task}s that define the upgrade steps, to be run in the order returned. 41 | * 42 | * @return list of {@link Task}s to be run 43 | */ 44 | public List getUpgradeTasks(); 45 | } 46 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/context/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Utility classes to assist in the implementation of 25 | * {@link com.vmware.upgrade.UpgradeContext#getPersistenceContext(Class)} and 26 | * {@link com.vmware.upgrade.UpgradeContext#getPersistenceContext(Class, String)}. 27 | * 28 | * @since 1.0 29 | */ 30 | package com.vmware.upgrade.context; 31 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/factory/UpgradeDefinitionFactory.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.factory; 24 | 25 | import java.io.IOException; 26 | 27 | import com.vmware.upgrade.UpgradeContext; 28 | import com.vmware.upgrade.UpgradeDefinition; 29 | import com.vmware.upgrade.sequencing.Version; 30 | 31 | /** 32 | * A factory which will create {@link UpgradeDefinition}s for a specified {@link UpgradeContext}. 33 | * 34 | * @author Zach Shepherd shepherdz@vmware.com 35 | * @version 1.0 36 | * @since 1.0 37 | */ 38 | public interface UpgradeDefinitionFactory { 39 | /** 40 | * Determine whether an {@link UpgradeDefinition} can be produced for the given context. 41 | * 42 | * @param context The {@link UpgradeContext} within which the upgrade would run. 43 | * @return true if the factory should be able to produce an upgrade for that context 44 | * @throws IOException if an IO error occurs when reading files defining the upgrade. 45 | */ 46 | boolean isUpgradeSupported (final UpgradeContext context) throws IOException; 47 | 48 | /** 49 | * Generate an {@link UpgradeDefinition} which, when executed, will result in upgrade from the 50 | * {@link UpgradeContext#getVersion() current version} to the 51 | * {@link #getTargetVersion() highest reachable version}. 52 | * 53 | * @param context The {@link UpgradeContext} within which the upgrade should run. 54 | * @return the created {@link UpgradeDefinition} 55 | * @throws IOException if an IO error occurs when reading files defining the upgrade. 56 | */ 57 | UpgradeDefinition create(final UpgradeContext context) throws IOException; 58 | 59 | /** 60 | * Return the highest {@link Version} reachable via execution of an {@link UpgradeDefinition} 61 | * produced by this factory. 62 | * 63 | * @return the maximum reachable {@link Version} 64 | */ 65 | Version getTargetVersion(); 66 | } 67 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/factory/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Factory classes for generating {@link com.vmware.upgrade.UpgradeDefinition} instances. 25 | * 26 | * @since 1.0 27 | */ 28 | package com.vmware.upgrade.factory; 29 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/logging/LogLevel.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2009-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.logging; 24 | 25 | /** 26 | * LogLevel enumeration contains all possible log severities 27 | * 28 | * @author Vassil Popovski vpopovski@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public enum LogLevel { 33 | /** 34 | * very severe error events that will presumably lead the application to 35 | * abort. 36 | */ 37 | FATAL, 38 | 39 | /** 40 | * error events that might still allow the application to continue running. 41 | */ 42 | ERROR, 43 | 44 | /** 45 | * potentially harmful situations. 46 | */ 47 | WARN, 48 | 49 | /** 50 | * security related events such as invalid logins 51 | */ 52 | SECURITY, 53 | 54 | /** 55 | * informational messages that highlight the progress of the application at 56 | * coarse-grained level. 57 | */ 58 | INFO, 59 | 60 | /** 61 | * fine-grained informational events that are most useful to debug an 62 | * application. 63 | */ 64 | DEBUG, 65 | 66 | /** 67 | * finer-grained informational events than the DEBUG. 68 | */ 69 | TRACE 70 | } 71 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/logging/UpgradeLogger.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.logging; 24 | 25 | /** 26 | * Wrapper around {@link Logger} (which is not intended to be exposed to framework users and should 27 | * remain in-sync with the {@code Logger} interface in {@code com.vmware.vcloud.activity.logging} 28 | * and {@code com.vmware.vcloud.logging}) for project-specific customizations. 29 | * 30 | * @author Zach Shepherd shepherdz@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface UpgradeLogger extends Logger { 35 | // Intentionally blank; intended for future extension 36 | } 37 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/logging/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Utility classes for assisting with creation of {@link com.vmware.upgrade.logging.UpgradeLogger} 25 | * instances. 26 | * 27 | * @since 1.0 28 | */ 29 | package com.vmware.upgrade.logging; 30 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * The core upgrade framework. 25 | *

26 | * The upgrade framework exists to generally describe the process of performing a set of actions, 27 | * represented as {@link com.vmware.upgrade.Task} objects, to transition one or more persistence 28 | * mechanisms, described by {@link com.vmware.upgrade.PersistenceContext} objects encapsulated 29 | * within an overall {@link com.vmware.upgrade.UpgradeContext}, from one 30 | * {@link com.vmware.upgrade.sequencing.Version} to another later 31 | * {@link com.vmware.upgrade.sequencing.Version}. 32 | *

33 | * In addition to encapsulating the {@linkplain com.vmware.upgrade.PersistenceContext} objects, the 34 | * {@link com.vmware.upgrade.UpgradeContext} is responsible for capturing information about 35 | * the environment within which the upgrade is occurring, including the current 36 | * {@link com.vmware.upgrade.sequencing.Version} of the environment and the process for 37 | * {@linkplain com.vmware.upgrade.logging.UpgradeLogger logging} the changes being made. 38 | * 39 | * @since 1.0 40 | */ 41 | package com.vmware.upgrade; 42 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/progress/ExecutionStateAggregator.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.progress; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * This class contains a method to calculate task state of a parent task from a collection 29 | * of task states of its children. 30 | * 31 | * @author Zach Shepherd shepherdz@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | public interface ExecutionStateAggregator { 36 | /** 37 | * Calculates the state of a parent task from a collection of states of child tasks. 38 | *

39 | * Parent states calculated by this method must be compatible with the state transition diagram 40 | * defined in {@link ExecutionState}, e.g. valid state transitions of the child states must 41 | * produce valid state transitions of the parent state. 42 | * 43 | * @param childStates non-empty collection of task states to aggregate 44 | * @return an aggregate state 45 | * @throws IllegalArgumentException if {@code taskStates} is {@code null} or is empty or 46 | * contains a {@code null} member 47 | */ 48 | public ExecutionState aggregate(Collection childStates); 49 | } 50 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/progress/ProgressReport.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.progress; 24 | 25 | /** 26 | * A point-in-time representation of the progress of a task. 27 | * 28 | * @author Zach Shepherd shepherdz@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface ProgressReport { 33 | 34 | /** 35 | * Get current progress as a percentage. 36 | * 37 | * @return current progress between 0..100 38 | */ 39 | int getProgress(); 40 | 41 | /** 42 | * Get the task state. 43 | * 44 | * @return the current {@link ExecutionState} 45 | */ 46 | ExecutionState getState(); 47 | } 48 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/progress/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Generally applicable implementations of interfaces defined in the 25 | * {@linkplain com.vmware.upgrade.progress progress reporting framework}. 26 | *

27 | * This package contains default implementations and utility classes related to progress reporting. 28 | * 29 | * @since 1.0 30 | */ 31 | package com.vmware.upgrade.progress.impl; 32 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/progress/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * The progress reporting framework for the upgrade process. 25 | *

26 | * This package contains interfaces and helper classes for long running operations to 27 | * report progress and for clients to subscribe to progress updates. 28 | * 29 | * @since 1.0 30 | */ 31 | package com.vmware.upgrade.progress; 32 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/sequencing/GraphHelper.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.sequencing; 24 | 25 | import java.util.LinkedList; 26 | import java.util.List; 27 | 28 | import com.vmware.upgrade.sequencing.Graph.Edge; 29 | 30 | /** 31 | * Utility class for convenience methods related to use of {@link Graph} instances. 32 | * 33 | * @author Zach Shepherd shepherdz@vmware.com 34 | * @version 1.0 35 | * @since 1.0 36 | */ 37 | public class GraphHelper { 38 | public static List extractPath(final Graph graph, final Version version) { 39 | final List upgrades = new LinkedList(); 40 | 41 | Version runningSourceVersionPart = version; 42 | 43 | Edge nextModel = graph.getEdge(runningSourceVersionPart); 44 | while (nextModel != null) { 45 | final Version nextSourceVersionPart = nextModel.getTarget(); 46 | 47 | // This should never happen as it is checked elsewhere, but is double-checked here to 48 | // be safe (i.e. prevent a potential infinite loop). 49 | if (runningSourceVersionPart.compareTo(nextSourceVersionPart) > 0) { 50 | throw new AssertionError(runningSourceVersionPart); 51 | } 52 | 53 | upgrades.add(nextModel); 54 | 55 | runningSourceVersionPart = nextSourceVersionPart; 56 | nextModel = graph.getEdge(runningSourceVersionPart); 57 | } 58 | 59 | return upgrades; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/sequencing/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Objects related to expressing the sequential relationship between a collection of 25 | * {@link com.vmware.upgrade.Task}s. 26 | * 27 | * @since 1.0 28 | */ 29 | package com.vmware.upgrade.sequencing; 30 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/task/SerialAggregateTask.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.task; 24 | 25 | import java.util.List; 26 | 27 | import com.vmware.upgrade.Task; 28 | import com.vmware.upgrade.UpgradeContext; 29 | import com.vmware.upgrade.logging.UpgradeLogger; 30 | 31 | /** 32 | * A {@link Task} which aggregates other {@link Task}s and executes them in series 33 | * 34 | * @author Zach Shepherd shepherdz@vmware.com 35 | * @version 1.0 36 | * @since 1.0 37 | */ 38 | public final class SerialAggregateTask extends AbstractAggregateTask { 39 | private final UpgradeLogger logger; 40 | 41 | /** 42 | * Constructs a named task which aggregates the supplied tasks. 43 | * 44 | * @param context 45 | * the {@link UpgradeContext} 46 | * @param name 47 | * see {@link Task#getName()} 48 | * @param children 49 | * the children to execute 50 | * @throws IllegalArgumentException 51 | * if {@code children} is {@code null} 52 | */ 53 | public SerialAggregateTask(final UpgradeContext context, final String name, final List children) { 54 | super(name, children); 55 | logger = context.getLogger(getClass()); 56 | } 57 | 58 | @Override 59 | public Void call() throws Exception { 60 | logger.trace("{0}: Beginning execution", getName()); 61 | 62 | try { 63 | for (final Task child : getChildren()) { 64 | logger.debug("{0}: Beginning execution of task {1}", getName(), child.getName()); 65 | child.call(); 66 | } 67 | } catch (Exception e) { 68 | logger.warn(e, "{0}: Task failed due to uncaught exception", getName()); 69 | getReporter().terminateWithFailure(); 70 | throw e; 71 | } 72 | 73 | logger.trace("{0}: Completed successfully", getName()); 74 | 75 | return null; 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/task/TrivialTask.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.task; 24 | 25 | import java.util.concurrent.Callable; 26 | import java.util.concurrent.Executors; 27 | 28 | import com.vmware.upgrade.progress.ExecutionState; 29 | 30 | /** 31 | * Creates a trivial task from a {@link Runnable} or {@link Callable}. 32 | * 33 | * @author Zach Shepherd shepherdz@vmware.com 34 | * @version 1.0 35 | * @since 1.0 36 | */ 37 | public class TrivialTask extends AbstractSimpleTask { 38 | 39 | private final Callable callable; 40 | 41 | public TrivialTask(String name, Runnable r) { 42 | this(name, Executors.callable(r)); 43 | } 44 | 45 | public TrivialTask(String name, Callable callable) { 46 | super(name, 1); 47 | 48 | this.callable = callable; 49 | } 50 | 51 | @Override 52 | public Void call() throws Exception { 53 | setState(ExecutionState.RUNNING); 54 | try { 55 | callable.call(); 56 | incrementProgress(); 57 | } catch (Exception e) { 58 | setState(ExecutionState.FAILED); 59 | throw e; 60 | } 61 | setState(ExecutionState.COMPLETED); 62 | 63 | return null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/main/java/com/vmware/upgrade/transformation/ReferenceTransformation.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.transformation; 24 | 25 | import com.vmware.upgrade.Task; 26 | 27 | /** 28 | * Extension of {@link Transformation} to hold information detailing how a {@link Task} 29 | * that adds or drops a reference would alter a database. 30 | * 31 | * @author Matthew Frost mfrost@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | public class ReferenceTransformation extends Transformation { 36 | 37 | private final String referencedTableName; 38 | private final boolean hasDeleteConstraint; 39 | 40 | public ReferenceTransformation(String tableName, String referencedTableName, 41 | boolean hasDeleteConstraint, TransformationType alterationType) { 42 | super(tableName, alterationType); 43 | if (alterationType != TransformationType.ADD_FOREIGN_KEY && alterationType != TransformationType.DROP_FOREIGN_KEY) { 44 | throw new AssertionError("alterationType must be either ADD_FOREIGN_KEY or DROP_FOREIGN_KEY"); 45 | } 46 | this.referencedTableName = referencedTableName; 47 | this.hasDeleteConstraint = hasDeleteConstraint; 48 | } 49 | 50 | /** 51 | * The name of the table that would be referenced by a foreign key. 52 | * 53 | * @return {@link String} the referenced table name 54 | */ 55 | public String getReferencedTableName() { 56 | return referencedTableName; 57 | } 58 | 59 | public boolean hasDeleteConstraint() { 60 | return hasDeleteConstraint; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return String.format("Transforming table %s (referencing %s) via %s", 66 | tableName, referencedTableName, transformationType); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/test/java/com/vmware/upgrade/DummyUpgradeContext.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade; 24 | 25 | import java.util.NoSuchElementException; 26 | 27 | import com.vmware.upgrade.logging.UpgradeLogger; 28 | import com.vmware.upgrade.logging.UpgradeLoggerHelper; 29 | import com.vmware.upgrade.sequencing.Version; 30 | 31 | /** 32 | * A fake implementation of {@link UpgradeContext} for use in test code. 33 | * 34 | * Suitable for use only when a non-{@code null} placeholder {@link UpgradeContext} is needed. 35 | * 36 | * @author Zach Shepherd shepherdz@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | public class DummyUpgradeContext implements UpgradeContext { 41 | @Override 42 | public UpgradeLogger getLogger(Class clazz) { 43 | return UpgradeLoggerHelper.NO_OP_LOGGER; 44 | } 45 | 46 | @Override 47 | public T getPersistenceContext(Class type) { 48 | throw new NoSuchElementException(); 49 | } 50 | 51 | @Override 52 | public T getPersistenceContext(Class type, String qualifier) { 53 | throw new NoSuchElementException(); 54 | } 55 | 56 | @Override 57 | public Version getVersion() { 58 | return Version.INITIAL; 59 | } 60 | 61 | @Override 62 | public void setVersion(Version version) { 63 | // TODO Auto-generated method stub 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/test/java/com/vmware/upgrade/TestGroups.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade; 24 | 25 | /** 26 | * Constants for use as TestNG Test Groups. 27 | * 28 | * @author Stephen Evanchik evanchik@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface TestGroups { 33 | public static final String UNIT = "Unit"; 34 | 35 | public static final String MINIMUM = "Minimum"; 36 | 37 | public static final String REQUIRE_SPECIFIC_RESOURCE = "RequireSpecificResource"; 38 | } 39 | -------------------------------------------------------------------------------- /upgrade-framework-core/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/instructions.bnd: -------------------------------------------------------------------------------- 1 | Bundle-SymbolicName: com.vmware.upgrade.dsl 2 | Bundle-RequiredExecutionEnvironment: JavaSE-11 3 | Export-Package: * 4 | Import-Package: org.apache.commons.lang, * 5 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | upgrade-framework-dsl 8 | 9 | upgrade-framework-dsl - Domain Specific Language for Upgrade Framework 10 | Library which provides DSL processing logic for the upgrade framework. 11 | 12 | jar 13 | 14 | 15 | com.vmware.vcloud 16 | upgrade-framework-parent 17 | 2.0.0 18 | ../pom.xml 19 | 20 | 21 | 22 | 23 | org.codehaus.groovy 24 | groovy-all 25 | ${groovy.version} 26 | pom 27 | 28 | 29 | 30 | com.vmware.vcloud 31 | upgrade-framework-core 32 | 33 | 34 | 35 | com.vmware.vcloud 36 | upgrade-framework-core 37 | test-jar 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | maven-compiler-plugin 46 | 47 | groovy-eclipse-compiler 48 | 49 | 50 | 51 | org.codehaus.groovy 52 | groovy-eclipse-compiler 53 | ${groovy.eclipse.compiler.version} 54 | 55 | 56 | org.codehaus.groovy 57 | groovy-eclipse-batch 58 | 59 | 60 | 61 | 62 | org.codehaus.groovy 63 | groovy-eclipse-batch 64 | ${groovy.eclipse.batch.version} 65 | 66 | 67 | 68 | 69 | 70 | org.apache.maven.plugins 71 | maven-jar-plugin 72 | 73 | 74 | 75 | org.apache.felix 76 | maven-bundle-plugin 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/Processor.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl; 24 | 25 | import groovy.lang.Closure; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | public interface Processor extends Cloneable { 31 | Map> getKeywordProcessors(); 32 | List getPropertyProcessors(); 33 | } 34 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/TaskResolver.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl; 24 | 25 | import java.util.List; 26 | 27 | import com.vmware.upgrade.Task; 28 | import com.vmware.upgrade.UpgradeContext; 29 | 30 | public interface TaskResolver { 31 | Task resolve(UpgradeContext context, Class taskClass, String name, List args); 32 | 33 | Task combine(UpgradeContext context, List tasks, String name); 34 | } 35 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/model/ManifestModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.model 24 | 25 | import com.vmware.upgrade.sequencing.AbstractGraph 26 | import com.vmware.upgrade.sequencing.Graph 27 | import com.vmware.upgrade.sequencing.Version 28 | 29 | /** 30 | * A DSL model object representing a {@link Graph} of {@link Graph.Edge}s represented by 31 | * {@link UpgradeTaskModel}s. 32 | * 33 | * @author Emil Sit sit@vmware.com 34 | * @version 1.0 35 | * @since 1.0 36 | */ 37 | class ManifestModel extends AbstractGraph { 38 | private Map upgrades = [:] 39 | def name 40 | 41 | def addUpgrade(UpgradeTaskModel upgrade) { 42 | Version source = upgrade.getSource() 43 | upgrades.put(source, upgrade) 44 | } 45 | 46 | def addAll(Collection upgrades) { 47 | for (UpgradeTaskModel upgrade : upgrades) { 48 | addUpgrade(upgrade) 49 | } 50 | } 51 | 52 | UpgradeTaskModel getUpgrade(Version source) { 53 | return upgrades.get(source) 54 | } 55 | 56 | Collection getUpgrades() { 57 | return upgrades.values() 58 | } 59 | 60 | @Override 61 | public Map getEdges() { 62 | return upgrades 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return name ?: "Unnamed Manifest" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/model/NamespaceModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.model 24 | 25 | import com.vmware.upgrade.dsl.util.FinalVariableBinding 26 | 27 | /** 28 | * A DSL model object defining a namespace within which {@link UpgradeDefinitionModel}s must be 29 | * uniquely named. 30 | * 31 | * @author Ankit Shah ankitsha@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | class NamespaceModel { 36 | Binding upgrades 37 | 38 | NamespaceModel() { 39 | upgrades = new FinalVariableBinding() 40 | } 41 | 42 | def addUpgrade(String name, UpgradeDefinitionModel upgrade) { 43 | upgrades.setVariable(name, upgrade) 44 | } 45 | 46 | def propertyMissing(String name) { 47 | upgrades.getVariable(name) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/model/UpgradeTaskModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.model; 24 | 25 | import com.vmware.upgrade.Task 26 | import com.vmware.upgrade.UpgradeContext 27 | import com.vmware.upgrade.sequencing.Graph 28 | import com.vmware.upgrade.sequencing.Version 29 | 30 | /** 31 | * A DSL model object representing a {@link Graph.Edge} within the {@link Graph} represented 32 | * by the {@link ManifestModel}. 33 | *

34 | * This class represents the association between a concrete {@link UpgradeDefinitionModel} and the 35 | * version information related to that process (the required source version and the resulting 36 | * version assuming successful execution). 37 | * 38 | * @author Zach Shepherd shepherdz@vmware.com 39 | * @version 1.0 40 | * @since 1.0 41 | */ 42 | class UpgradeTaskModel implements Graph.Edge { 43 | Version source 44 | Version target 45 | UpgradeDefinitionModel definition 46 | 47 | @Override 48 | public Task createTask(UpgradeContext context) { 49 | return definition.createTask(context); 50 | } 51 | 52 | @Override 53 | public Version getSource() { 54 | return source; 55 | } 56 | 57 | @Override 58 | public Version getTarget() { 59 | return target; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/model/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * The core model objects which compose the domain specific language for defining upgrade 25 | * framework constructs. 26 | *

27 | * A com.vmware.upgrade.dsl.model.ManifestModel consists of 28 | * com.vmware.upgrade.dsl.model.UpgradeTaskModels which reference 29 | * com.vmware.upgrade.dsl.model.UpgradeDefinitionModels within 30 | * com.vmware.upgrade.dsl.model.NamespaceModels 31 | *

32 | * (Package contains Groovy classes.) 33 | * 34 | * @since 1.0 35 | */ 36 | package com.vmware.upgrade.dsl.model; 37 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/syntax/ManifestSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.syntax 24 | 25 | import com.vmware.upgrade.dsl.model.ManifestModel 26 | import com.vmware.upgrade.dsl.model.UpgradeTaskModel 27 | import com.vmware.upgrade.sequencing.Version 28 | 29 | /** 30 | * Syntax to parse a manifest object describing zero or more {@link UpgradeTaskModel}s. 31 | * 32 | * @author Emil Sit sit@vmware.com 33 | * @version 1.0 34 | * @since 1.0 35 | */ 36 | class ManifestSyntax { 37 | ManifestModel manifest = new ManifestModel() 38 | 39 | def name(manifestName) { 40 | manifest.name = manifestName 41 | } 42 | 43 | def from(version) { 44 | [see: { subManifest -> 45 | manifest.addAll(subManifest.upgrades) 46 | }, 47 | call: { upgrade -> 48 | addUpgrade(new Version(version), new Version(version).getNext(), upgrade) 49 | }, 50 | to: { target -> 51 | [call: { upgrade -> 52 | addUpgrade(new Version(version), new Version(target), upgrade) 53 | } 54 | ] 55 | } 56 | ] 57 | } 58 | 59 | def to(version) { 60 | [call: { upgrade -> 61 | final Version toVersion = new Version("${version}") 62 | 63 | for (int i = 0; new Version("${i}") < toVersion; i++) { 64 | addUpgrade(new Version("${i}"), toVersion, upgrade) 65 | } 66 | }] 67 | } 68 | 69 | def addUpgrade(source, target, definition) { 70 | if (manifest.getUpgrade(source) != null) { 71 | throw new DuplicateSourceException(source) 72 | } 73 | UpgradeTaskModel taskModel = [definition: definition, source: source, target: target] as UpgradeTaskModel 74 | manifest.addUpgrade(taskModel) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/syntax/NamespaceSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.syntax 24 | 25 | import com.vmware.upgrade.dsl.model.NamespaceModel 26 | import com.vmware.upgrade.dsl.model.UpgradeDefinitionModel 27 | 28 | /** 29 | * Syntax to parse a namespace object containing zero or more uniquely-named 30 | * {@link UpgradeDefinitionModel}s. 31 | * 32 | * @author Ankit Shah ankitsha@vmware.com 33 | * @version 1.0 34 | * @since 1.0 35 | */ 36 | class NamespaceSyntax { 37 | NamespaceModel namespace 38 | 39 | NamespaceSyntax() { 40 | namespace = new NamespaceModel() 41 | } 42 | 43 | def propertyMissing(String name, value) { 44 | if (!(value instanceof UpgradeDefinitionModel)) { 45 | throw new UpgradeCompilationException("${value} is not an upgrade definition for upgrade named ${name}") 46 | } 47 | 48 | namespace.addUpgrade name, value 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/syntax/UnknownKeywordWrapper.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.syntax 24 | 25 | /** 26 | * A wrapper for DSL closures to provide improved error handling for invalid keywords. 27 | * Wrapped delegates will throw an {@link UnknownKeywordException} (with a message noting 28 | * the unknown keyword) when an undefined keyword is encountered. This functions as an 29 | * improvement over the default behavior of a generic {@link MissingMethodException}. 30 | *

31 | * The improved error handling applies only if the delegate is a map [this wrapper is safe 32 | * to use if delegate is not a map, but it will not provide any benefit]. 33 | * 34 | * @author Matthew Frost mfrost@vmware.com 35 | * @version 1.0 36 | * @since 1.0 37 | */ 38 | public class UnknownKeywordWrapper { 39 | private Map> keywords 40 | 41 | static def wrap(delegate) { 42 | return (delegate instanceof Map) ? new UnknownKeywordWrapper(delegate) : delegate 43 | } 44 | 45 | private def UnknownKeywordWrapper(Map> keywords) { 46 | this.keywords = keywords 47 | } 48 | 49 | def methodMissing(String name, args) { 50 | if (name in keywords.keySet()) { 51 | def processor = keywords.get(name) 52 | processor.delegate = this 53 | return wrap(processor.call(*args)) 54 | } else { 55 | throw new UnknownKeywordException("Unknown keyword: " + name) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/syntax/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * The core syntax objects which define the domain specific language for the upgrade framework. 25 | *

26 | * com.vmware.upgrade.dsl.syntax.ScriptSyntax serves as the primary entry point for 27 | * processing scripts. 28 | *

29 | * (Package contains Groovy classes.) 30 | * 31 | * @since 1.0 32 | */ 33 | package com.vmware.upgrade.dsl.syntax; 34 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/util/AggregateProcessor.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.util; 24 | 25 | import groovy.lang.Closure; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.HashMap; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | import com.vmware.upgrade.dsl.Processor; 34 | 35 | /** 36 | * Aggregates zero or more {@link Processor} implementations. 37 | * 38 | * @author Zach Shepherd shepherdz@vmware.com 39 | * @version 1.0 40 | * @since 1.0 41 | */ 42 | public class AggregateProcessor implements Processor { 43 | private final Map> keywordProcessors; 44 | private final List propertyProcessors; 45 | 46 | /** 47 | * Creates an {@link AggregateProcessor} based on the state of the delegates at 48 | * construction time 49 | * 50 | * @param processors one or more {@link Processor}(s) 51 | */ 52 | public AggregateProcessor(Processor ... processors) { 53 | final Map> keywordProcessors = new HashMap>(); 54 | final List propertyProcessors = new ArrayList(); 55 | for (Processor processor : processors) { 56 | keywordProcessors.putAll(processor.getKeywordProcessors()); 57 | propertyProcessors.addAll(processor.getPropertyProcessors()); 58 | } 59 | this.keywordProcessors = Collections.unmodifiableMap(keywordProcessors); 60 | this.propertyProcessors = Collections.unmodifiableList(propertyProcessors); 61 | } 62 | 63 | @Override 64 | public Map> getKeywordProcessors() { 65 | return keywordProcessors; 66 | } 67 | 68 | @Override 69 | public List getPropertyProcessors() { 70 | return propertyProcessors; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/util/NoopProcessor.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.util; 24 | 25 | import groovy.lang.Closure; 26 | 27 | import java.util.Collections; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import com.vmware.upgrade.dsl.Processor; 32 | 33 | /** 34 | * A default {@link Processor} implementation which defines no keywords or properties. 35 | * 36 | * @author Zach Shepherd shepherdz@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | public class NoopProcessor implements Processor { 41 | 42 | @Override 43 | public Map> getKeywordProcessors() { 44 | return Collections.emptyMap(); 45 | } 46 | 47 | @Override 48 | public List getPropertyProcessors() { 49 | return Collections.emptyList(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/util/NoopTaskResolver.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.util; 24 | 25 | import java.util.List; 26 | import java.util.concurrent.Callable; 27 | 28 | import com.vmware.upgrade.Task; 29 | import com.vmware.upgrade.UpgradeContext; 30 | import com.vmware.upgrade.dsl.TaskResolver; 31 | import com.vmware.upgrade.task.SerialAggregateTask; 32 | import com.vmware.upgrade.task.TrivialTask; 33 | 34 | /** 35 | * A default {@link TaskResolver} implementation which {@linkplain #resolve resolves} all 36 | * {@link Class}es into {@link Task}s which do nothing. 37 | * 38 | * @author Zach Shepherd shepherdz@vmware.com 39 | * @version 1.0 40 | * @since 1.0 41 | */ 42 | public class NoopTaskResolver implements TaskResolver { 43 | @Override 44 | public Task resolve(UpgradeContext context, Class taskClass, String name, List args) { 45 | return new TrivialTask( 46 | name, 47 | new Callable() { 48 | @Override 49 | public Void call() throws Exception { 50 | return null; 51 | } 52 | } 53 | ); 54 | } 55 | 56 | @Override 57 | public Task combine(UpgradeContext context, List tasks, String name) { 58 | return new SerialAggregateTask(context, name, tasks); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/main/java/com/vmware/upgrade/dsl/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Utility classes for use with the upgrade framework and default implementations of interfaces. 25 | * 26 | * @since 1.0 27 | */ 28 | package com.vmware.upgrade.dsl.util; 29 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/java/com/vmware/upgrade/dsl/LoaderTest.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2013-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl 24 | 25 | import com.vmware.upgrade.TestGroups 26 | import com.vmware.upgrade.dsl.model.ManifestModel 27 | import com.vmware.upgrade.dsl.syntax.MissingFileException 28 | import com.vmware.upgrade.dsl.syntax.UpgradeCompilationException 29 | import com.vmware.upgrade.dsl.util.NoopProcessor 30 | import com.vmware.upgrade.dsl.util.NoopTaskResolver 31 | 32 | import org.testng.Assert 33 | import org.testng.annotations.Test 34 | 35 | public class LoaderTest { 36 | @Test(groups=[TestGroups.UNIT]) 37 | public void loadManifestTest() throws UpgradeCompilationException { 38 | def resourceMapper = { String name -> 39 | URL u = getClass().getResource("/upgrade/${name}") 40 | if (u == null) { 41 | throw new MissingFileException(name) 42 | } 43 | new GroovyCodeSource(u) 44 | } 45 | 46 | ManifestModel m = Loader.loadManifest("nullManifest.groovy", resourceMapper, new NoopTaskResolver(), new NoopProcessor()); 47 | Assert.assertNotNull(m); 48 | Assert.assertEquals(m.getUpgrades().size(), 0); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/java/com/vmware/upgrade/dsl/ManifestLoader.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl; 24 | 25 | import com.vmware.upgrade.dsl.model.ManifestModel 26 | import com.vmware.upgrade.dsl.syntax.UpgradeCompilationException 27 | import com.vmware.upgrade.dsl.util.NoopProcessor 28 | import com.vmware.upgrade.dsl.util.NoopTaskResolver 29 | 30 | public class ManifestLoader extends Loader { 31 | /** 32 | * Parse a string as script and return a manifest. 33 | * This class is intended for use in testing only. 34 | * 35 | * @param script a String representing an upgrade manifest 36 | * @return the ManifestModel from the provided script 37 | * @throws UpgradeCompilationException if there is an error in the source file 38 | */ 39 | static ManifestModel loadInlineManifest(String script) throws UpgradeCompilationException { 40 | def source = new GroovyCodeSource(script, "inlineScript", "inline.groovy") 41 | loadManifest(source, { it -> it }, new NoopTaskResolver(), new NoopProcessor()) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/java/com/vmware/upgrade/dsl/syntax/RequiredKeywordProcessor.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.syntax 24 | 25 | import groovy.lang.Closure 26 | 27 | import java.util.Collections 28 | import java.util.HashMap 29 | import java.util.List 30 | import java.util.Map 31 | 32 | import org.codehaus.groovy.runtime.MethodClosure 33 | 34 | import com.vmware.upgrade.dsl.Processor 35 | 36 | /** 37 | * Implementation of {@link Processor} to facilitate testing of required keyword error handling. 38 | * 39 | * @author Matthew Frost mfrost@vmware.com 40 | * @version 1.0 41 | * @since 1.0 42 | */ 43 | class RequiredKeywordProcessor implements Processor { 44 | private Map keywordProcessors = [ 45 | "outerKeyword" : { outerArg -> 46 | pushError("Keyword 'middleKeyword' is required") 47 | ["middleKeyword" : { middleArg -> 48 | popError() 49 | pushError("Keyword 'innerKeyword' is required") 50 | ["innerKeyword" : { innerArg -> 51 | popError() 52 | }] 53 | }] 54 | } 55 | ] 56 | 57 | @Override 58 | public Map> getKeywordProcessors() { 59 | return keywordProcessors 60 | } 61 | 62 | @Override 63 | public List getPropertyProcessors() { 64 | return Collections.emptyList() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/java/com/vmware/upgrade/dsl/syntax/ResourceInclusionTest.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2013-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.syntax 24 | 25 | import groovy.mock.interceptor.MockFor 26 | 27 | import com.vmware.upgrade.TestGroups 28 | import com.vmware.upgrade.dsl.Loader 29 | import com.vmware.upgrade.dsl.util.FinalVariableBinding 30 | import com.vmware.upgrade.dsl.util.NoopProcessor 31 | import com.vmware.upgrade.dsl.util.NoopTaskResolver 32 | 33 | import org.testng.Assert 34 | import org.testng.annotations.DataProvider 35 | import org.testng.annotations.Test 36 | 37 | /** 38 | * A test class to verify the resource-inclusion related behavior of {@link ScriptSyntax}. 39 | * 40 | * @author Ryan Lewis ryanlewis@vmware.com 41 | * @version 1.0 42 | * @since 1.0 43 | */ 44 | class ResourceInclusionTest { 45 | @DataProvider 46 | public Object[][] resolvePaths() { 47 | [ 48 | ["/Sub/Dir/Example.groovy", "[/Sub/Dir] | Example.groovy"], 49 | ["/Example.groovy", "[/] | Example.groovy"], 50 | ["Example.groovy", "[] | Example.groovy"] 51 | ] 52 | } 53 | 54 | @Test(groups=[TestGroups.UNIT], dataProvider = "resolvePaths") 55 | public void fromResolvesCorrectBaseAndSource(path, expected) { 56 | def mocker = new MockFor(Loader.class) 57 | mocker.demand.loadManifest(1) { source, mapper, taskResolver, processor, binding -> 58 | // Assert that mapper has been curried with the correct base. 59 | Assert.assertEquals(mapper(source), expected) 60 | } 61 | 62 | mocker.use { 63 | def mapper = { String name, Object[] base = [ "" ] -> 64 | "${base} | ${name}" 65 | } 66 | def caller = new ScriptSyntax(mapper, new FinalVariableBinding(), new NoopTaskResolver(), new NoopProcessor()) 67 | 68 | caller.from(path) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /upgrade-framework-dsl/src/test/resources/upgrade/nullManifest.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /* 24 | * Dummy manifest 25 | */ 26 | upgrade {} 27 | manifest {} 28 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/instructions.bnd: -------------------------------------------------------------------------------- 1 | Bundle-SymbolicName: com.vmware.upgrade.sql.dsl 2 | Bundle-RequiredExecutionEnvironment: JavaSE-11 3 | Export-Package: * 4 | Import-Package: com.vmware.upgrade.dsl.syntax,\ 5 | com.vmware.upgrade.sql.task,\ 6 | * 7 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/CommentModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@link CommentModel} is an {@link SQLStatement} that represents a table or 28 | * column comment. 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface CommentModel extends TransformingModel { 35 | /** 36 | * Sets the text of the comment. 37 | * 38 | * @param text the text of the comment. 39 | */ 40 | public void setText(text) 41 | 42 | /** 43 | * Sets the name of entity being commented on. This will be either the name 44 | * of a table or the name of a column. 45 | * 46 | * @param name table or column name 47 | */ 48 | public void setEntity(name) 49 | 50 | /** 51 | * In the case that a column name was given by {@link #setEntity(String)}, 52 | * the name of the table it's in is set-able by this method. 53 | * 54 | * @param tableName 55 | */ 56 | public void columnComment(tableName) 57 | } 58 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/IndexModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | import com.vmware.upgrade.sql.DatabaseType 26 | 27 | /** 28 | * {@code IndexModel} is a {@link SQLStatement} that represents the 29 | * creation of an index. 30 | * 31 | * @author Matthew Frost mfrost@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | public interface IndexModel extends TransformingModel { 36 | /** 37 | * Set the table being indexed. 38 | * 39 | * @param tableName 40 | */ 41 | public void setTable(tableName) 42 | 43 | /** 44 | * Get the table being indexed. 45 | * 46 | * @param databaseType 47 | */ 48 | public String getTable(DatabaseType databaseType) 49 | 50 | /** 51 | * Add to columns that will be indexed. 52 | * 53 | * @param column 54 | */ 55 | public void addColumn(column) 56 | 57 | /** 58 | * Set if the index should guarantee uniqueness. 59 | * 60 | * @param unique 61 | */ 62 | public void setUnique(boolean unique) 63 | } 64 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/ReferenceModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@code ReferenceModel} is an {@link SQLStatement} that represents the 28 | * creation of a foreign key constraint. 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface ReferenceModel extends TransformingModel { 35 | /** 36 | * Add columns from the source table that will be referencing the target 37 | * table. 38 | * 39 | * @param sourceColumn 40 | */ 41 | public void addToSourceColumns(sourceColumn) 42 | 43 | /** 44 | * Add columns that will be referenced in the target table. 45 | * 46 | * @param targetColumn 47 | */ 48 | public void addToTargetColumns(targetColumn) 49 | 50 | /** 51 | * Set the referencing table. 52 | * 53 | * @param tableName 54 | */ 55 | public void setSourceTable(tableName) 56 | 57 | /** 58 | * Set the table being referenced. 59 | * 60 | * @param tableName 61 | */ 62 | public void setTargetTable(tableName) 63 | 64 | /** 65 | * Override the generated foreign key name with the specified name. 66 | * 67 | * @param name 68 | */ 69 | public void setReferenceName(name) 70 | 71 | /** 72 | * Set the referential action for a related table when a row or rows of 73 | * the target (referenced) table are deleted. 74 | * 75 | * @param referentialAction 76 | */ 77 | public void setDeleteConstraint(referentialAction) 78 | 79 | /** 80 | * Set the referential action for a related table when a row or rows of 81 | * the target (referenced) table are updated. 82 | * 83 | * @param referentialAction 84 | */ 85 | public void setUpdateConstraint(referentialAction) 86 | } 87 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/TableAlterationModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@code TableAlterationModel} is an {@link SQLStatement} that represents the 28 | * alteration of table. 29 | *

30 | * Supported alterations include: 31 | *

    32 | *
  • Adding a column
  • 33 | *
  • Dropping a column
  • 34 | *
  • Renaming a column
  • 35 | *
  • Change the type of a column
  • 36 | *
  • Drop primary/unique keys
  • 37 | *
38 | * 39 | * @author Ryan Lewis ryanlewis@vmware.com 40 | * @version 1.0 41 | * @since 1.0 42 | */ 43 | public interface TableAlterationModel extends TransformingModel { 44 | /** 45 | * Add a column of the specified type. 46 | * 47 | * @param name column name 48 | * @param type column type 49 | */ 50 | public void addColumn(name, type) 51 | 52 | /** 53 | * Drop a column by the specified name. 54 | * 55 | * @param name column name 56 | */ 57 | public void dropColumn(name) 58 | 59 | /** 60 | * Rename a column. 61 | * 62 | * @param name original column name 63 | * @param newName new column name 64 | */ 65 | public void renameColumn(name, newName) 66 | 67 | /** 68 | * Change the type of the specified column. 69 | * 70 | * @param name column name 71 | * @param type new column type 72 | */ 73 | public void retypeColumn(name, type) 74 | 75 | /** 76 | * Set the {@link ConstraintModel} to be used when altering a table's constraints. 77 | */ 78 | public void setConstraint(ConstraintModel constraint) 79 | } 80 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/TableCreationModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@code TableCreationModel} is an {@link SQLStatement} that represents the 28 | * creation of a table. 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface TableCreationModel extends TransformingModel { 35 | /** 36 | * Set the columns that to be created. 37 | * 38 | * @param columns List of columns 39 | */ 40 | public void setColumns(List columns) 41 | 42 | /** 43 | * Set the constraints to be created 44 | * 45 | * @param constraints List of constraints 46 | */ 47 | public void setConstraints(List constraints) 48 | } 49 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/TransformingModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | import com.vmware.upgrade.sql.SQLStatement 26 | import com.vmware.upgrade.transformation.Transformation 27 | 28 | /** 29 | * A {@link SQLStatement} that provides information related to the transformation the 30 | * underlying model will make. 31 | * 32 | * @author Matthew Frost mfrost@vmware.com 33 | * @version 1.0 34 | * @since 1.0 35 | */ 36 | public interface TransformingModel extends SQLStatement { 37 | 38 | /** 39 | * Get the {@link Transformation} this model will make. 40 | * 41 | * @return {@link Transformation} 42 | */ 43 | public Transformation getTransformation() 44 | 45 | } 46 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/UnindexModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@code UnindexModel} is a {@link SQLStatement} that represents the 28 | * removal of an index. 29 | * 30 | * @author Matthew Frost mfrost@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface UnindexModel extends TransformingModel { 35 | /** 36 | * Set the table being indexed. 37 | * 38 | * @param tableName 39 | */ 40 | public void setTable(tableName) 41 | 42 | /** 43 | * Add to columns that will be indexed. 44 | * 45 | * @param column 46 | */ 47 | public void addColumn(column) 48 | 49 | /** 50 | * Add to columns that will be indexed. 51 | * 52 | * @param name 53 | */ 54 | public void setIndexName(name) 55 | } 56 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/UnreferenceModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model 24 | 25 | 26 | /** 27 | * {@code UnreferenceModel} is an {@link SQLStatement} that represents the 28 | * deletion of a foreign key constraint. 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface UnreferenceModel extends TransformingModel { 35 | /** 36 | * Set the referencing table. 37 | * 38 | * @param tableName 39 | */ 40 | public void setSourceTable(table) 41 | 42 | /** 43 | * Set the table being referenced. 44 | * 45 | * @param tableName 46 | */ 47 | public void setTargetTable(table) 48 | } 49 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/defaults/DefaultDropViewModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.defaults 24 | 25 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory; 26 | import com.vmware.upgrade.sql.DatabaseType 27 | import com.vmware.upgrade.sql.SQLStatement 28 | 29 | /** 30 | * {@code DefaultDropViewModel} contains the core drop view logic. 31 | *

32 | * The raw SQL returned by {@link #get(DatabaseType)} will not check for the 33 | * existence of the view before execution. 34 | * 35 | * @author Ryan Lewis ryanlewis@vmware.com 36 | * @version 1.0 37 | * @since 1.0 38 | */ 39 | class DefaultDropViewModel implements SQLStatement { 40 | private static final String DROP_VIEW_SQL = "DROP VIEW %s" 41 | 42 | protected def viewName 43 | 44 | public DefaultDropViewModel(viewName) { 45 | this.viewName = viewName 46 | } 47 | 48 | @Override 49 | public String get(final DatabaseType databaseType) { 50 | return SQLStatementFactory.format(DROP_VIEW_SQL, databaseType, viewName) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/defaults/DefaultUnindexModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.defaults 24 | 25 | import com.vmware.upgrade.dsl.sql.model.UnindexModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | import com.vmware.upgrade.sql.SQLStatement 29 | import com.vmware.upgrade.transformation.Transformation 30 | 31 | /** 32 | * {@code DefaultUnindexModel} is the core implementation of {@link UnindexModel}. 33 | *

34 | * The raw SQL returned by {@link #get(DatabaseType)} will not check for the 35 | * existence of the table before execution. 36 | * 37 | * @author Matthew Frost mfrost@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | public class DefaultUnindexModel extends DefaultIndexModel implements UnindexModel { 42 | private static final SQLStatement DROP_INDEX_SQL = SQLStatementFactory.create( 43 | [ 44 | default: "DROP INDEX %1\$s", 45 | ms_sql: "DROP INDEX %1\$s ON %2\$s" 46 | ]) 47 | 48 | private def indexName 49 | 50 | @Override 51 | public void setIndexName(indexName) { 52 | this.indexName = indexName 53 | } 54 | 55 | @Override 56 | public void addColumn(column) { 57 | super.addColumn(column) 58 | } 59 | 60 | @Override 61 | public String get(final DatabaseType databaseType) { 62 | final String table = getTable(databaseType) 63 | final String index = indexName ?: getIndexName(databaseType) 64 | 65 | return SQLStatementFactory.format(DROP_INDEX_SQL.get(databaseType), databaseType, index, table) 66 | } 67 | 68 | @Override 69 | public Transformation getTransformation() { 70 | return new Transformation(super.tableName, Transformation.TransformationType.DROP_INDEX) 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Groovy model files for the SQL-related extensions to the upgrade DSL. 25 | *

26 | * (Package contains Groovy classes.) 27 | * 28 | * @since 1.0 29 | */ 30 | package com.vmware.upgrade.dsl.sql.model; 31 | 32 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeCommentModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultCommentModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | import com.vmware.upgrade.sql.SQLStatement 29 | 30 | /** 31 | * {@link SafeCommentModel} extends the logic of {@link DefaultCommentModel} by 32 | * wrapping the raw SQL string returned by {@link DefaultCommentModel#get(DatabaseType)} 33 | * with SQL entity existence checks. 34 | *

35 | * If the {@link CommentModel} represents 36 | *

    37 | *
  1. a table comment, then a check is performed to ensure the table exists; or
  2. 38 | *
  3. a column comment, then a check is performed to ensure both the table and 39 | * column exists.
  4. 40 | *
41 | * 42 | * @author Ryan Lewis ryanlewis@vmware.com 43 | * @version 1.0 44 | * @since 1.0 45 | */ 46 | class SafeCommentModel extends DefaultCommentModel { 47 | @Override 48 | public String get(DatabaseType databaseType) { 49 | switch (commentType) { 50 | case CommentType.COLUMN: 51 | return String.format(SafeSQLStatementWrapper.TABLE_AND_COLUMN_EXISTS.get(databaseType), tableName, entity, super.get(databaseType).replace("'", "''")) 52 | case CommentType.TABLE: 53 | return String.format( 54 | SafeSQLStatementWrapper.TABLE_EXISTS.get(databaseType), 55 | entity, 56 | super.get(databaseType).replace("'", "''")) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeDropViewModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultDropViewModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | import com.vmware.upgrade.sql.SQLStatement 29 | 30 | /** 31 | * {@link SafeDropViewModel} extends the logic of {@link DefaultDropViewModel} by 32 | * wrapping the raw SQL string returned by {@link DefaultDropViewModel#get(DatabaseType)} 33 | * with an SQL entity existence check. 34 | *

35 | * A check is performed to ensure the view exists before execution. 36 | * 37 | * @author Ryan Lewis ryanlewis@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | class SafeDropViewModel extends DefaultDropViewModel { 42 | private static final SQLStatement VIEW_EXISTS_WRAPPER = SQLStatementFactory.create( 43 | [ 44 | ms_sql: """ 45 | IF OBJECT_ID(N'%s', N'V') IS NOT NULL 46 | %s 47 | """, 48 | oracle: """ 49 | DECLARE 50 | v INT; 51 | 52 | BEGIN 53 | SELECT COUNT(*) INTO v FROM user_views WHERE view_name = UPPER('%s'); 54 | 55 | IF v = 1 THEN 56 | EXECUTE IMMEDIATE '%s'; 57 | END IF; 58 | END; 59 | """, 60 | postgres:""" 61 | DO \$\$ 62 | DECLARE 63 | v INT; 64 | 65 | BEGIN 66 | SELECT COUNT(*) INTO v FROM pg_class WHERE relname = LOWER('%s') AND relkind = 'v'; 67 | IF v = 1 THEN 68 | EXECUTE '%s'; 69 | END IF; 70 | END\$\$; 71 | """ 72 | ] 73 | ) 74 | 75 | public SafeDropViewModel(viewName) { 76 | super(viewName) 77 | } 78 | 79 | @Override 80 | public String get(DatabaseType databaseType) { 81 | return SQLStatementFactory.format(VIEW_EXISTS_WRAPPER.get(databaseType), databaseType, viewName, super.get(databaseType)) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeIndexModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultIndexModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | 29 | /** 30 | * {@link SafeIndexModel} extends the logic of {@link DefaultIndexModel} by 31 | * wrapping the raw SQL string returned by {@link DefaultIndexModel#get(DatabaseType)} 32 | * with a SQL entity existence check. 33 | *

34 | * A check is performed to ensure the table exists before execution. 35 | * 36 | * @author Matthew Frost mfrost@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | class SafeIndexModel extends DefaultIndexModel { 41 | @Override 42 | public String get(final DatabaseType databaseType) { 43 | return SQLStatementFactory.format( 44 | SafeSQLStatementWrapper.TABLE_EXISTS.get(databaseType), 45 | databaseType, 46 | super.getTable(databaseType), 47 | super.get(databaseType)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeReferenceModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultReferenceModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | 29 | /** 30 | * {@link SafeReferenceModel} extends the logic of {@link DefaultReferenceModel} by 31 | * wrapping the raw SQL string returned by {@link DefaultReferenceModel#get(DatabaseType)} 32 | * with an SQL entity existence check. 33 | *

34 | * A check is performed to ensure the referencing table (source / table being 35 | * altered) exists before execution. 36 | * 37 | * @author Ryan Lewis ryanlewis@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | public class SafeReferenceModel extends DefaultReferenceModel { 42 | @Override 43 | public String get(final DatabaseType databaseType) { 44 | return SQLStatementFactory.format( 45 | SafeSQLStatementWrapper.TABLE_EXISTS.get(databaseType), 46 | databaseType, 47 | sourceTable, 48 | super.get(databaseType)) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeTableCreationModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultTableCreationModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | import com.vmware.upgrade.sql.SQLStatement 29 | 30 | /** 31 | * {@link SafeTableCreationModel} extends the logic of {@link DefaultTableCreationModel} by 32 | * wrapping the raw SQL string returned by {@link DefaultTableCreationModel#get(DatabaseType)} 33 | * with an SQL entity existence check. 34 | *

35 | * A check is performed to ensure the table being created doesn't already exist. 36 | * 37 | * @author Ryan Lewis ryanlewis@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | public class SafeTableCreationModel extends DefaultTableCreationModel { 42 | private static final SQLStatement TABLE_NOT_EXISTS_WRAPPER = SQLStatementFactory.create( 43 | [ 44 | ms_sql: """ 45 | IF OBJECT_ID(N'%s', N'U') IS NULL 46 | BEGIN 47 | %s 48 | END 49 | """, 50 | oracle: """ 51 | DECLARE 52 | t INT; 53 | 54 | BEGIN 55 | SELECT COUNT(*) INTO t FROM user_tables WHERE table_name = UPPER('%s'); 56 | 57 | IF t = 0 THEN 58 | EXECUTE IMMEDIATE '%s'; 59 | END IF; 60 | END; 61 | """, 62 | postgres:""" 63 | DO \$\$ 64 | DECLARE 65 | t INT; 66 | 67 | BEGIN 68 | SELECT COUNT(*) INTO t FROM pg_class WHERE relname = LOWER('%s') AND relkind = 'r'; 69 | IF t = 0 THEN 70 | EXECUTE '%s'; 71 | END IF; 72 | END\$\$; 73 | """ 74 | ]) 75 | 76 | public SafeTableCreationModel(tableName) { 77 | super(tableName) 78 | } 79 | 80 | @Override 81 | public String get(final DatabaseType databaseType) { 82 | return SQLStatementFactory.format(TABLE_NOT_EXISTS_WRAPPER.get(databaseType), databaseType, super.tableName, super.get(databaseType)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeUnindexModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultUnindexModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | 29 | /** 30 | * {@link SafeUnindexModel} extends the logic of {@link DefaultUnindexModel} by 31 | * wrapping the raw SQL string returned by {@link DefaultUnindexModel#get(DatabaseType)} 32 | * with a SQL entity existence check. 33 | *

34 | * A check is performed to ensure the table exists before execution. 35 | * 36 | * @author Matthew Frost mfrost@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | class SafeUnindexModel extends DefaultUnindexModel { 41 | @Override 42 | public String get(final DatabaseType databaseType) { 43 | return SQLStatementFactory.format( 44 | SafeSQLStatementWrapper.TABLE_EXISTS.get(databaseType), 45 | databaseType, 46 | super.getTable(databaseType), 47 | super.get(databaseType)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/model/safe/SafeUnreferenceModel.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.model.safe 24 | 25 | import com.vmware.upgrade.dsl.sql.model.defaults.DefaultUnreferenceModel 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | 29 | /** 30 | * {@link SafeUnreferenceModel} extends the logic of {@link DefaultUnreferenceModel} by 31 | * wrapping the raw SQL string returned by {@link DefaultUnreferenceModel#get(DatabaseType)} 32 | * with an SQL entity existence check. 33 | *

34 | * A check is performed to ensure the referencing table (aka source / table being 35 | * altered) exists before execution. 36 | * 37 | * @author Ryan Lewis ryanlewis@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | public class SafeUnreferenceModel extends DefaultUnreferenceModel { 42 | @Override 43 | public String get(final DatabaseType databaseType) { 44 | return String.format( 45 | SafeSQLStatementWrapper.TABLE_EXISTS.get(databaseType), 46 | super.sourceTable, 47 | super.get(databaseType)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/CommentSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax 24 | 25 | import com.vmware.upgrade.dsl.sql.model.CommentModel; 26 | 27 | /** 28 | * {@code CommentSyntax} defines the syntax for the {@code comment} keyword. 29 | *

30 | * For a table comment: 31 | * {@code comment "example text" on "table_name"} 32 | *

33 | * For a column comment: 34 | * {@code comment "example text" on "column_name" of "table_name"} 35 | * 36 | * @author Ryan Lewis ryanlewis@vmware.com 37 | * @version 1.0 38 | * @since 1.0 39 | */ 40 | class CommentSyntax { 41 | CommentModel model 42 | 43 | CommentSyntax(CommentModel commentModel, text) { 44 | this.model = commentModel 45 | model.setText(text) 46 | } 47 | 48 | def on(name) { 49 | model.setEntity(name) 50 | 51 | this 52 | } 53 | 54 | def of(tableName) { 55 | model.columnComment(tableName) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/Constraints.groovy: -------------------------------------------------------------------------------- 1 | package com.vmware.upgrade.dsl.sql.syntax 2 | 3 | /** 4 | * Keywords for common constraints. 5 | */ 6 | class Constraints { 7 | public static def cascade = "CASCADE" 8 | public static def no_action = "NO ACTION" 9 | public static def set_null = "SET NULL" 10 | public static def set_default = "SET DEFAULT" 11 | } 12 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/DataType.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax; 24 | 25 | import com.vmware.upgrade.sql.SQLStatement; 26 | 27 | /** 28 | * Interface to represent SQL data types in the DSL 29 | * 30 | * @author Matthew Frost mfrost@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface DataType { 35 | /** 36 | * Returns a SQLStatement used to construct database-specific SQL strings. 37 | * 38 | * @return {@link SQLStatement} 39 | */ 40 | public SQLStatement sql(); 41 | } 42 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/IndexSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax 24 | 25 | import com.vmware.upgrade.dsl.sql.model.IndexModel 26 | import com.vmware.upgrade.dsl.syntax.UnknownKeywordException 27 | 28 | /** 29 | * {@code IndexSyntax} defines the syntax for the {@code index} keyword. 30 | * 31 | * @author Matthew Frost mfrost@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | class IndexSyntax { 36 | IndexModel model 37 | 38 | IndexSyntax(IndexModel model, firstColumn) { 39 | this.model = model 40 | model.addColumn(firstColumn) 41 | } 42 | 43 | def of(tableName) { 44 | model.setTable(tableName) 45 | this 46 | } 47 | 48 | def and(column) { 49 | model.addColumn(column) 50 | this 51 | } 52 | 53 | def propertyMissing(String name) { 54 | String msg 55 | try { 56 | this.getClass().getMethod(name, Object.class) 57 | msg = "Missing keyword following '$name'" 58 | } catch (NoSuchMethodException e) { 59 | msg = "Unknown keyword '$name'" 60 | } 61 | throw new UnknownKeywordException(msg) 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/TableCreationColumnSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax 24 | 25 | import com.vmware.upgrade.dsl.sql.util.ColumnTypeSyntaxUtil 26 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory 27 | import com.vmware.upgrade.sql.DatabaseType 28 | 29 | /** 30 | * {@code TableCreationColumnSyntax} defines the syntax for the table creation 31 | * {@code add} column keyword. 32 | *

33 | * This class isn't an inner class or {@link TableCreationSyntax} because of a 34 | * bug in Groovy that prevents a user-defined propertyMissing method being set 35 | * on one. See {@link http://jira.codehaus.org/browse/GROOVY-4862} 36 | * 37 | * @author Ryan Lewis ryanlewis@vmware.com 38 | * @version 1.0 39 | * @since 1.0 40 | */ 41 | class TableCreationColumnSyntax { 42 | List columns = [] 43 | 44 | private class Column { 45 | def name 46 | def type 47 | 48 | Column(name, type) { 49 | this.name = name 50 | this.type = type 51 | } 52 | 53 | public String get(DatabaseType databaseType) { 54 | return SQLStatementFactory.create(name, " ", type).get(databaseType) 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return name.hashCode() 60 | } 61 | 62 | @Override 63 | public boolean equals(Object obj) { 64 | return (obj instanceof Column && obj.name.equals(name)) 65 | } 66 | } 67 | 68 | def add(column) { 69 | return [storing: { type -> 70 | def columnType = ColumnTypeSyntaxUtil.getColumnType(type) 71 | Column col = new Column(column, columnType) 72 | columns.add(col) 73 | 74 | return ColumnTypeSyntaxUtil.getAdditionalSyntax(columnType) 75 | }] 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/UnindexSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax 24 | 25 | import com.vmware.upgrade.dsl.sql.model.UnindexModel 26 | import com.vmware.upgrade.dsl.syntax.UnknownKeywordException 27 | 28 | /** 29 | * {@code UnindexSyntax} defines the syntax for the {@code unindex} keyword. 30 | * 31 | * @author Matthew Frost mfrost@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | class UnindexSyntax { 36 | UnindexModel model 37 | 38 | UnindexSyntax(UnindexModel model, firstColumnOrName) { 39 | this.model = model 40 | if (firstColumnOrName instanceof String && ((String) firstColumnOrName).startsWith("ix_")) { 41 | model.setIndexName(firstColumnOrName) 42 | } else { 43 | model.addColumn(firstColumnOrName) 44 | } 45 | 46 | } 47 | 48 | def of(tableName) { 49 | model.setTable(tableName) 50 | this 51 | } 52 | 53 | def and(column) { 54 | model.addColumn(column) 55 | this 56 | } 57 | 58 | def propertyMissing(String name) { 59 | String msg 60 | try { 61 | this.getClass().getMethod(name, Object.class) 62 | msg = "Missing keyword following '$name'" 63 | } catch (NoSuchMethodException e) { 64 | msg = "Unknown keyword '$name'" 65 | } 66 | throw new UnknownKeywordException(msg) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/UnreferenceSyntax.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax 24 | 25 | import com.vmware.upgrade.dsl.sql.model.UnreferenceModel; 26 | 27 | /** 28 | * {@code UnreferenceSyntax} defines the syntax for the {@code unreference} keyword. 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | class UnreferenceSyntax { 35 | UnreferenceModel model 36 | 37 | UnreferenceSyntax(UnreferenceModel model, String targetTable) { 38 | this.model = model 39 | model.setTargetTable(targetTable) 40 | } 41 | 42 | def from(sourceTable) { 43 | model.setSourceTable(sourceTable) 44 | 45 | this 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/syntax/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Upgrade Data-Definition Syntax and Models 25 | *

26 | * Currently, {@link com.vmware.upgrade.sql.SQLStatement SQLStatement} 27 | * models have default and safe implementations which generate different SQL 28 | * based on the absence / presence of the {@code safe} upgrade definition 29 | * keyword. 30 | *

31 | * (Package contains Groovy classes.) 32 | * 33 | * @since 1.0 34 | */ 35 | package com.vmware.upgrade.dsl.sql.syntax; 36 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/BasicSqlProcessor.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util 24 | 25 | import com.vmware.upgrade.dsl.Processor 26 | import com.vmware.upgrade.sql.SQLStatement 27 | import com.vmware.upgrade.sql.task.RawSQLTask 28 | import com.vmware.upgrade.sql.task.ScriptTask 29 | 30 | /** 31 | * A {@link Processor} which defines the basic {@code sql} and {@code file} keywords. 32 | * 33 | * @author Zach Shepherd shepherdz@vmware.com 34 | * @version 1.0 35 | * @since 1.0 36 | */ 37 | class BasicSqlProcessor implements Processor { 38 | Map keywordProcessors = [ 39 | "sql" : { arg -> 40 | final String name = getPosition() 41 | 42 | if (arg instanceof String) { 43 | final String rawSql = (String) arg 44 | 45 | addTask name, RawSQLTask, rawSql 46 | } else if (arg instanceof Map) { 47 | final Map rawSqlMap = (Map) arg 48 | 49 | try { 50 | sql SQLStatementFactory.create(rawSqlMap) 51 | } catch (IllegalArgumentException e) { 52 | throw new IllegalArgumentException(e.getMessage() + " (" + getPosition() + ")", e) 53 | } 54 | } else if (arg instanceof SQLStatement) { 55 | final SQLStatement statementModel = (SQLStatement) arg 56 | 57 | addTask name, RawSQLTask, statementModel 58 | } else { 59 | throw new IllegalArgumentException("Expected the argument to the 'sql' keyword to be a String, Map, or SQLStatement at " + name) 60 | } 61 | }, 62 | "file" : { String fileName -> addTask fileName, ScriptTask, fileName } 63 | ] 64 | 65 | @Override 66 | public Map> getKeywordProcessors() { 67 | return keywordProcessors; 68 | } 69 | 70 | @Override 71 | public List getPropertyProcessors() { 72 | return Collections.emptyList(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/ClassUtil.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util 24 | 25 | import java.lang.reflect.Field 26 | import org.codehaus.groovy.reflection.CachedField 27 | 28 | /** 29 | * 30 | * @author Matthew Frost mfrost@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | class ClassUtil { 35 | 36 | /** 37 | * Checks if a {@link Class} has a field matching {@code name} and returns the 38 | * associated field as a {@link MetaProperty} 39 | * 40 | * @param clazz the {@link Class} to check 41 | * @param name the name of the the field to check 42 | * @return a {@link MetaProperty} if a field matching {@code name} is present, 43 | * {@code null} otherwise 44 | */ 45 | public static MetaProperty hasField(Class clazz, String name) { 46 | Field field = clazz.getProperties().get("declaredFields").find { it.getName().equals(name) } 47 | 48 | return (field != null) ? new CachedField(field) : null 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/ColumnTypeSyntaxUtil.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2015-2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util 24 | 25 | import com.vmware.upgrade.dsl.sql.syntax.DataType 26 | 27 | /** 28 | * Utility class for syntax-related classes to perform common operations on a {@link ColumnType} 29 | * 30 | * @author Matthew Frost mfrost@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | class ColumnTypeSyntaxUtil { 35 | 36 | /** 37 | * Checks which interfaces are implemented by {@code type} and calls requisite methods as 38 | * applicable. 39 | * 40 | * @param type any valid column type object, e.g. {@link Map}, {@link String}, {@link ColumnType} 41 | * @return an object representing a column type, this may be a reference to the same object or a 42 | * copy of one (i.e. callers should not assume the returned object references the same one 43 | * passed). 44 | */ 45 | static def getColumnType(type) { 46 | def columnType = type 47 | 48 | if (type in DataType) { 49 | columnType = columnType.sql() 50 | } 51 | 52 | if (type in NullAware) { 53 | columnType = columnType.makeCopy() 54 | } 55 | 56 | return columnType 57 | } 58 | 59 | /** 60 | * Returns a closure with additional column syntax for the appropriate type. 61 | * 62 | * @param type 63 | * @return {@link Closure}, or the passed {@code type} if it is not a {@link HasClosureMap} 64 | */ 65 | static def getAdditionalSyntax(type) { 66 | return (type in HasClosureMap) ? type.getClosureMap(type) : type 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/DefaultAware.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | /** 26 | * Interface to specify a default value for a column. 27 | * 28 | * @author Matthew Frost mfrost@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface DefaultAware extends HasClosureMap { 33 | 34 | public Object setDefaultValue(Object arg); 35 | 36 | public Object getDefaultValue(); 37 | 38 | public DefaultAware makeNoDefaultCopy(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/HasClosureMap.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | import groovy.lang.Closure; 26 | 27 | import java.util.Map; 28 | 29 | /** 30 | * Interface to indicate and provide access to a mapping of keywords to closures. 31 | * 32 | * @author Matthew Frost mfrost@vmware.com 33 | * @version 1.0 34 | * @since 1.0 35 | */ 36 | public interface HasClosureMap { 37 | 38 | public Map> getClosureMap(HasClosureMap type); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/InitialAware.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | /** 26 | * Interface to control an initial value for a column. 27 | * 28 | * @author Matthew Frost mfrost@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface InitialAware extends HasClosureMap { 33 | 34 | public Object setInitialValue(Object arg); 35 | 36 | public Object getInitialValue(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/NullAware.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | /** 26 | * Interface to control whether or not to allow nulls. 27 | * 28 | * @author Matthew Frost mfrost@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface NullAware extends HasClosureMap { 33 | /** 34 | * Set the allowing of null values. 35 | * 36 | * @param arg the {@link Object} used to determine allowing of null values 37 | * @return Object 38 | */ 39 | public Object makeNullable(Object arg); 40 | 41 | /** 42 | * Get the allowing or disallowing of null values. 43 | * 44 | * @return true if nulls are allowed, false otherwise 45 | */ 46 | public boolean isNullable(); 47 | 48 | /** 49 | * Make a copy of this object 50 | * 51 | * @return a copy of this {@link NullAware} 52 | */ 53 | public NullAware makeCopy(); 54 | 55 | /** 56 | * Make a copy of this object that allows nulls, regardless of the nullability 57 | * of the original object. 58 | * 59 | * @return a copy of this {@link NullAware} that will allow nulls 60 | */ 61 | public NullAware makeNullableCopy(); 62 | } 63 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/main/java/com/vmware/upgrade/dsl/sql/util/SqlTaskResolver.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util 24 | 25 | import com.vmware.upgrade.Task 26 | import com.vmware.upgrade.UpgradeContext 27 | import com.vmware.upgrade.dsl.util.BasicTaskResolver 28 | import com.vmware.upgrade.sql.task.RawSQLTask 29 | import com.vmware.upgrade.sql.task.ScriptTask 30 | import com.vmware.upgrade.sql.task.TransactionTask 31 | 32 | class SqlTaskResolver extends BasicTaskResolver { 33 | @Override 34 | public Task resolve(UpgradeContext context, Class taskClass, String name, List args) { 35 | final Task t 36 | switch (taskClass) { 37 | case RawSQLTask: 38 | t = new RawSQLTask(name, context, args[0]) 39 | break 40 | case ScriptTask: 41 | t = ScriptTask.from(context, args[0]) 42 | break 43 | default: 44 | t = super.resolve(context, taskClass, name, args) 45 | break 46 | } 47 | return t 48 | } 49 | 50 | @Override 51 | public Task combine(UpgradeContext context, List tasks, String name) { 52 | return new TransactionTask("Transaction boundary for " + name, super.combine(context, tasks, name), context); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/semantics/DropViewSemanticsTest.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.semantics; 24 | 25 | import java.util.HashMap; 26 | 27 | import com.vmware.upgrade.TestGroups; 28 | import com.vmware.upgrade.dsl.model.UpgradeDefinitionModel; 29 | import com.vmware.upgrade.dsl.sql.util.SQLStatementFactory; 30 | import com.vmware.upgrade.sql.SQLStatement; 31 | 32 | import org.testng.annotations.DataProvider; 33 | import org.testng.annotations.Test; 34 | 35 | public class DropViewSemanticsTest { 36 | @SuppressWarnings("serial") 37 | @DataProvider 38 | public Object[][] dropViewStatements() { 39 | return new Object[][] { 40 | new Object[] { 41 | "drop_view 'some_table'", 42 | SQLStatementFactory.create("DROP VIEW some_table") 43 | }, 44 | new Object[] { 45 | "drop_view oracle: 'some_table', ms_sql: 'different_table', postgres: 'ps_table'", 46 | SQLStatementFactory.create( 47 | new HashMap() {{ 48 | put("ms_sql", "DROP VIEW different_table"); 49 | put("oracle", "DROP VIEW some_table"); 50 | put("postgres", "DROP VIEW ps_table"); 51 | }} 52 | ) 53 | }, 54 | }; 55 | } 56 | 57 | @Test(groups = { TestGroups.UNIT }, dataProvider = "dropViewStatements") 58 | public void compareDropViewStatements(String ddl, SQLStatement expected) { 59 | final UpgradeDefinitionModel upgrade = SemanticTestUtil.createUpgradeModel(ddl); 60 | 61 | SemanticTestUtil.compareModelToSQL(upgrade, expected); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/syntax/DropViewSyntaxTest.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.syntax; 24 | 25 | import com.vmware.upgrade.TestGroups; 26 | import com.vmware.upgrade.dsl.model.UpgradeDefinitionModel; 27 | 28 | import org.testng.annotations.DataProvider; 29 | import org.testng.annotations.Test; 30 | 31 | public class DropViewSyntaxTest { 32 | @DataProvider 33 | public Object[][] validDropViewStatements() { 34 | return new Object[][] { 35 | new Object[] { "drop_view 'some_table'" }, 36 | new Object[] { "drop_view oracle: 'some_table', ms_sql: 'different_table', postgres: 'ps_table'" } 37 | }; 38 | } 39 | 40 | @Test(groups = { TestGroups.UNIT }, dataProvider = "validDropViewStatements") 41 | public void verifyValiDropViewSyntax(String ddl) { 42 | UpgradeDefinitionModel upgrade = SyntaxTestUtil.loadInline(ddl); 43 | 44 | SyntaxTestUtil.basicVerification(upgrade); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/util/ClassUtilTest.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | import groovy.lang.MetaProperty; 26 | 27 | import org.codehaus.groovy.runtime.DefaultGroovyMethods; 28 | import org.testng.annotations.Test; 29 | import org.testng.Assert; 30 | 31 | import com.vmware.upgrade.TestGroups; 32 | 33 | /** 34 | * 35 | * @author Matthew Frost mfrost@vmware.com 36 | * @version 1.0 37 | * @since 1.0 38 | */ 39 | public class ClassUtilTest { 40 | @Test(groups = { TestGroups.UNIT }) 41 | public void hasFieldTest() { 42 | class TestClass { 43 | @SuppressWarnings("unused") 44 | public Object a = new Object(); 45 | } 46 | 47 | Assert.assertTrue(DefaultGroovyMethods.hasProperty(TestClass.class, "a") == null); 48 | Assert.assertTrue(ClassUtil.hasField(TestClass.class, "a") instanceof MetaProperty); 49 | 50 | Assert.assertFalse(ClassUtil.hasField(TestClass.class, "b") instanceof MetaProperty); 51 | Assert.assertTrue(ClassUtil.hasField(TestClass.class, "b") == null); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/util/ConstraintNameUtilTest.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util; 24 | 25 | import com.vmware.upgrade.TestGroups; 26 | import com.vmware.upgrade.dsl.sql.util.ConstraintNameUtil; 27 | 28 | import org.testng.Assert; 29 | import org.testng.annotations.DataProvider; 30 | import org.testng.annotations.Test; 31 | 32 | /** 33 | * A test class to verify the behavior of {@link ReferenceSyntax} and {@link ConstraintNameUtil}. 34 | * 35 | * @author Ryan Lewis ryanlewis@vmware.com 36 | * @version 1.0 37 | * @since 1.0 38 | */ 39 | public class ConstraintNameUtilTest { 40 | @DataProvider 41 | public Object[][] constraints() { 42 | return new Object[][] { 43 | new Object[] { "abc", 0, "" }, 44 | new Object[] { "abc", 1, "a" }, 45 | new Object[] { "a_b_c", 1, "a" }, 46 | new Object[] { "a_b_c", 2, "a" }, 47 | new Object[] { "a_b_c", 3, "a_b" }, 48 | new Object[] { "ab_cd_ef", 2, "ab" }, 49 | new Object[] { "ab_cd_ef", 5, "a_c_e" }, 50 | new Object[] { "abc_def_ghi", 6, "ab_d_g" }, 51 | new Object[] { "abc_def_ghi", 11, "abc_def_ghi" }, 52 | new Object[] { "abc_def_ghi", 12, "abc_def_ghi" }, 53 | new Object[] { "vshield_manager", 13, "vshiel_manage" }, 54 | new Object[] { "vcenter_supported_builds", 13, "vcen_supp_bui" }, 55 | new Object[] { "network_appliance_pvdc_mview", 13, "net_app_pv_mv"}, 56 | new Object[] { "network_appliance_pvdc_m", 13, "net_app_pvd_m"} 57 | }; 58 | } 59 | 60 | @Test(groups = { TestGroups.UNIT }, dataProvider = "constraints") 61 | public void abbreviate(String name, int maxLength, String expected) { 62 | final String abbreviatedName = ConstraintNameUtil.abbreviate(name, maxLength); 63 | 64 | Assert.assertEquals(abbreviatedName, expected); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/util/DefaultTestProcessor.groovy: -------------------------------------------------------------------------------- 1 | 2 | /* **************************************************************************** 3 | * Copyright (c) 2015 VMware, Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * ****************************************************************************/ 23 | 24 | package com.vmware.upgrade.dsl.sql.util 25 | 26 | import static com.vmware.upgrade.dsl.sql.syntax.ColumnType.* 27 | 28 | /** 29 | * A {@link Processor} for testing purposes. 30 | * 31 | * @author Matthew Frost mfrost@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | class DefaultTestProcessor extends AgnosticSqlProcessor { 36 | List propertyProcessors = [new AdditionalColumnTypes()] 37 | 38 | @Override 39 | public Map> getKeywordProcessors() { 40 | return super.getKeywordProcessors() 41 | } 42 | 43 | @Override 44 | public List getPropertyProcessors() { 45 | return super.getPropertyProcessors() + propertyProcessors 46 | } 47 | 48 | class AdditionalColumnTypes { 49 | public static def TEST_VARCHAR = VARCHAR(128) 50 | 51 | public MetaProperty hasProperty(String name) { 52 | return ClassUtil.hasField(AdditionalColumnTypes.class, name) 53 | } 54 | 55 | def propertyMissing(String name) { 56 | try { 57 | return Type.valueOf(name) 58 | } catch (IllegalArgumentException e) { 59 | throw new com.vmware.upgrade.dsl.syntax.UnknownKeywordException("Unknown column type '${name}'") 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/java/com/vmware/upgrade/dsl/sql/util/UpgradeLoader.groovy: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2015 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.dsl.sql.util 24 | 25 | import com.vmware.upgrade.dsl.Processor 26 | import com.vmware.upgrade.dsl.TaskResolver 27 | import com.vmware.upgrade.dsl.model.UpgradeDefinitionModel 28 | 29 | /** 30 | * A test utility for loading upgrade definitions. 31 | * 32 | * @author Zach Shepherd shepherdz@vmware.com 33 | * @version 1.0 34 | * @since 1.0 35 | */ 36 | class UpgradeLoader { 37 | static UpgradeDefinitionModel loadInline(String script, TaskResolver taskResolver = new SqlTaskResolver(), Processor processor = new DefaultTestProcessor()) { 38 | return com.vmware.upgrade.dsl.util.UpgradeLoader.loadInline(script, taskResolver, processor) 39 | } 40 | 41 | static UpgradeDefinitionModel loadDefinitionInline(String script, TaskResolver taskResolver = new SqlTaskResolver(), Processor processor = new DefaultTestProcessor()) { 42 | return com.vmware.upgrade.dsl.util.UpgradeLoader.loadDefinitionInline(script, taskResolver, processor) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /upgrade-framework-sql-dsl/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /upgrade-framework-sql/instructions.bnd: -------------------------------------------------------------------------------- 1 | Bundle-SymbolicName: com.vmware.upgrade.sql 2 | Bundle-RequiredExecutionEnvironment: JavaSE-11 3 | Import-Package: * 4 | Export-Package: * 5 | -------------------------------------------------------------------------------- /upgrade-framework-sql/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | upgrade-framework-sql 8 | 9 | upgrade-framework-sql - SQL support for Upgrade Framework 10 | SQL-aware library to augment core upgrade logic. 11 | 12 | jar 13 | 14 | 15 | com.vmware.vcloud 16 | upgrade-framework-parent 17 | 2.0.0 18 | ../pom.xml 19 | 20 | 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 26 | 27 | 28 | commons-math 29 | commons-math 30 | 31 | 32 | 33 | commons-collections 34 | commons-collections 35 | test 36 | 37 | 38 | 39 | ch.qos.reload4j 40 | reload4j 41 | 42 | 43 | 44 | com.vmware.vcloud 45 | upgrade-framework-core 46 | 47 | 48 | 49 | com.vmware.vcloud 50 | upgrade-framework-core 51 | test-jar 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | maven-compiler-plugin 60 | 61 | javac 62 | 63 | 64 | 65 | 66 | 67 | true 68 | 69 | 70 | 71 | 72 | org.apache.maven.plugins 73 | maven-jar-plugin 74 | 75 | 76 | 77 | org.apache.felix 78 | maven-bundle-plugin 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/DatabaseType.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.sql; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * Tagging interface intended for with {@link DatabasePersistenceContext} in conjunction with 29 | * the extensible enum pattern. 30 | * 31 | * @author Zach Shepherd shepherdz@vmware.com 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | public interface DatabaseType { 36 | 37 | /** 38 | * Returns a representation of the script file identified by the provided file name. 39 | * 40 | * @param scriptName 41 | * Name of the script file 42 | * @return the {@link String} object containing the script 43 | * @throws IOException if an I/O exception has occurred 44 | */ 45 | String load(String scriptName) throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/SQLStatement.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.sql; 24 | 25 | /** 26 | * This object is used to construct a raw SQL string. 27 | *

28 | * The exact string that is returned is dependent on the {@link DatabaseType} 29 | * 30 | * @author Ryan Lewis ryanlewis@vmware.com 31 | * @version 1.0 32 | * @since 1.0 33 | */ 34 | public interface SQLStatement { 35 | /** 36 | * Get the appropriate SQL string for a given {@link DatabaseType}. 37 | * 38 | * @param databaseType {@link DatabaseType} 39 | * @return an SQL string 40 | * @throws IllegalArgumentException if a statement cannot be retrieved for 41 | * the given {@code databaseType} 42 | */ 43 | public String get(final DatabaseType databaseType); 44 | } 45 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * The SQL database-related extensions to the upgrade framework. 25 | *

26 | * This package contains implementations of the core upgrade interfaces (such as 27 | * {@link com.vmware.upgrade.Task} and {@link com.vmware.upgrade.PersistenceContext}) 28 | * specific to operating with SQL databases via JDBC. 29 | * 30 | * @since 1.0 31 | */ 32 | package com.vmware.upgrade.sql; 33 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/script/SQLParsedDataAggregator.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2011-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | package com.vmware.upgrade.sql.script; 24 | 25 | /** 26 | * Simple interface that aggregates parsed SQLs and then return in the chosen type. 27 | * 28 | * @author Ankit Shah ankitsha@vmware.com 29 | * @version 1.0 30 | * @since 1.0 31 | */ 32 | public interface SQLParsedDataAggregator { 33 | /** 34 | * Record a parsed SQL command along with information regarding the file it was parsed from and 35 | * the lines in the file. 36 | * 37 | * @param startLineNo 38 | * line number for start of the SQL in the file 39 | * @param endLineNo 40 | * line number for end of the SQL in the file 41 | * @param input 42 | * the SQL that was parsed 43 | */ 44 | public void append(int startLineNo, int endLineNo, String input); 45 | 46 | /** 47 | * @return Returns the parsed information in the return type of choice 48 | */ 49 | public T getParsedData(); 50 | } 51 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/script/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * Utility classes to assist with the implementation of 25 | * {@link com.vmware.upgrade.sql.DatabasePersistenceContext#parseWithAggregator}. 26 | * 27 | * @since 1.0 28 | */ 29 | package com.vmware.upgrade.sql.script; 30 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/main/java/com/vmware/upgrade/sql/task/package-info.java: -------------------------------------------------------------------------------- 1 | /* **************************************************************************** 2 | * Copyright (c) 2012-2014 VMware, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * ****************************************************************************/ 22 | 23 | /** 24 | * {@link com.vmware.upgrade.Task} implementations which operate on a 25 | * {@link com.vmware.upgrade.sql.DatabasePersistenceContext}. 26 | * 27 | * @since 1.0 28 | */ 29 | package com.vmware.upgrade.sql.task; 30 | -------------------------------------------------------------------------------- /upgrade-framework-sql/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------