Skip to content

Commit

Permalink
TEIIDDES-1604 Added if/else logic to detect difference between 7.7.x …
Browse files Browse the repository at this point in the history
…mergeVDB() call and 8.x adding importVdb elements to project vdb.
  • Loading branch information
blafond committed Feb 26, 2013
1 parent 989913d commit b53b359
Showing 1 changed file with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public void done( IJobChangeEvent event ) {
* {@inheritDoc}
*
* @see org.teiid.designer.runtime.preview.PreviewContext#ensureConnectionInfoIsValid(org.teiid.designer.vdb.Vdb,
* org.teiid.designer.runtime.TeiidServer)
* org.teiid.designer.runtime.spi.ITeiidServer)
*/
@Override
public IStatus ensureConnectionInfoIsValid( Vdb previewVdb,
Expand Down Expand Up @@ -638,14 +638,20 @@ private IFile getFile( IPath path ) {
}

private String getFullDeployedVdbName(ITeiidVdb deployedVdb) {
String fullVdbName = deployedVdb.getPropertyValue("deployment-name");;
String fullVdbName = deployedVdb.getPropertyValue("deployment-name"); //$NON-NLS-1$
if (!fullVdbName.endsWith(Vdb.FILE_EXTENSION)) {
fullVdbName = fullVdbName + Vdb.FILE_EXTENSION;
}
return fullVdbName;

}

/**
* @param model the model file
* @param jndiName the jndi name
* @return the ITeiidDataSource instance
* @throws Exception if issues result from getting data source
*/
public ITeiidDataSource getOrCreateDataSource( IFile model, String jndiName ) throws Exception {
TeiidDataSourceFactory factory = new TeiidDataSourceFactory();
return factory.createDataSource(getPreviewServer(), model, jndiName, true, this.passwordProvider);
Expand Down Expand Up @@ -1180,6 +1186,11 @@ public void preferenceChange( PreferenceChangeEvent event ) {
}
}

/**
* @param objectToPreview the object to preview
* @param monitor the progress monitor
* @throws Exception if issues with setting up preview vdbs for project
*/
@SuppressWarnings( "unused" )
public void previewSetup( final Object objectToPreview,
IProgressMonitor monitor ) throws Exception {
Expand Down Expand Up @@ -1266,7 +1277,7 @@ public void previewSetup( final Object objectToPreview,
}

// collection for PVDBs that will be deployed and merged into the project PVDB
List<IFile> pvdbsToRemove = new ArrayList<IFile>(projectPvdbsToDeploy.size());
List<IFile> affectedPreviewVDBs = new ArrayList<IFile>(projectPvdbsToDeploy.size());

// deploy any project PVDBs if necessary
for (IFile projectPvdbFile : projectPvdbsToDeploy) {
Expand All @@ -1293,7 +1304,7 @@ public void previewSetup( final Object objectToPreview,
throw new CoreException(status);
}

pvdbsToRemove.add(projectPvdbFile);
affectedPreviewVDBs.add(projectPvdbFile);
}

if (!error) {
Expand Down Expand Up @@ -1332,7 +1343,7 @@ public void previewSetup( final Object objectToPreview,
}

// make sure this PVDB does not get merged since it didn't get deployed
pvdbsToRemove.remove(projectPvdbFile);
affectedPreviewVDBs.remove(projectPvdbFile);
}

if (monitor.isCanceled()) {
Expand All @@ -1354,28 +1365,56 @@ public void previewSetup( final Object objectToPreview,
}
}

localPreviewVdbs.removeAll(pvdbsToRemove);
localPreviewVdbs.removeAll(affectedPreviewVDBs);

// merge into project PVDB
MERGE_TASK: {
monitor.subTask(NLS.bind(Messages.PreviewSetupMergeTask, projectPreviewVdbName));

if (projectVdbIFile != null) {
ITeiidVdb deployedProjectVdb = getPreviewServer().getVdb(projectPreviewVdbName);
Vdb localProjectVdb = new Vdb(projectVdbIFile, new NullProgressMonitor());
localProjectVdb.removeAllImportVdbs();
// Add imports for all preview vdbs under project
addPreviewVdbImports(localProjectVdb, localPreviewVdbs);
// Add imports for all VDB source models within this project
addPreviewSourceVdbImports(localProjectVdb, currentModelProject);

if( deployedProjectVdb != null ) {
String fullProjectVdbName = getFullDeployedVdbName(deployedProjectVdb);
getPreviewServer().undeployVdb(fullProjectVdbName);
}
localProjectVdb.save(null);
localProjectVdb.getFile().refreshLocal(IResource.DEPTH_INFINITE, null);
getPreviewServer().deployVdb(localProjectVdb.getFile());
if( getPreviewServer().getServerVersion().isSevenServer()) {
VERSION_7_7_MERGE: {
// merge into project PVDB
affectedPreviewVDBs.add(pvdbFile); // add in model being previewed

for (IFile pvdbToMerge : affectedPreviewVDBs) {
String name = getResourceNameForPreviewVdb(pvdbToMerge);
monitor.subTask(NLS.bind(Messages.PreviewSetupMergeTask, name));

// REMOVE the .vdb extension for the source vdb
String sourceVdbName = pvdbToMerge.getFullPath().removeFileExtension().lastSegment().toString();
String projectPreviewVdbName = getPreviewProjectVdbName(modelToPreview.getProject());

if (!sourceVdbName.equals(projectPreviewVdbName)) {
getPreviewServer().mergeVdbs(sourceVdbName, PreviewManager.getPreviewVdbVersion(pvdbToMerge), projectPreviewVdbName, 1);
}

monitor.worked(1);

if (monitor.isCanceled()) {
throw new InterruptedException();
}
}
}
} else {
VERSION_8_8_DEPLOY : {
if (projectVdbIFile != null) {
ITeiidVdb deployedProjectVdb = getPreviewServer().getVdb(projectPreviewVdbName);
Vdb localProjectVdb = new Vdb(projectVdbIFile, new NullProgressMonitor());
localProjectVdb.removeAllImportVdbs();
// Add imports for all preview vdbs under project
addPreviewVdbImports(localProjectVdb, localPreviewVdbs);
// Add imports for all VDB source models within this project
addPreviewSourceVdbImports(localProjectVdb, currentModelProject);

if( deployedProjectVdb != null ) {
String fullProjectVdbName = getFullDeployedVdbName(deployedProjectVdb);
getPreviewServer().undeployVdb(fullProjectVdbName);
}
localProjectVdb.save(null);
localProjectVdb.getFile().refreshLocal(IResource.DEPTH_INFINITE, null);
getPreviewServer().deployVdb(localProjectVdb.getFile());
}
}
}

monitor.worked(1);
Expand Down Expand Up @@ -1504,6 +1543,9 @@ private void setNeedsToBeDeployedStatus( IPath pvdbPath,
}
}

/**
* @param passwordProvider the password provider
*/
public void setPasswordProvider( IPasswordProvider passwordProvider ) {
this.passwordProvider = passwordProvider;
}
Expand Down Expand Up @@ -1594,6 +1636,7 @@ public String getPreviewVdbJndiName( IPath pvdbPath ) {
* Shutdowns the <code>PreviewManager</code>. This will remove any Preview VDBs from the default Teiid server.
*
* @param monitor the progress monitor (may be <code>null</code>)
* @throws Exception if issues result from shutting down this class
*/
public void shutdown( IProgressMonitor monitor ) throws Exception {
try {
Expand Down

0 comments on commit b53b359

Please sign in to comment.