Skip to content

Commit

Permalink
TEIIDDES-1403
Browse files Browse the repository at this point in the history
- Modified JDBC Importer to create VDB source model when teiid connection
- VDB editor changes to detect/change import vdbs on sync, add/remove models
- changes to model read-only framework to also check for "locked" property, even if file is "writable"
  • Loading branch information
blafond authored and elvisisking committed Sep 17, 2012
1 parent 221dbf5 commit 42f49a5
Show file tree
Hide file tree
Showing 37 changed files with 1,060 additions and 610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public void save( final IProgressMonitor progress,
return;
}

if (ModelUtil.isIResourceReadOnly(file)) {
if (! ModelUtil.isLockedSourceObject(file) && ModelUtil.isIResourceReadOnly(file)) {
final String pathInProj = this.file.getProject().getName() + IPath.SEPARATOR + this.file.getProjectRelativePath();
final Object[] params = new Object[] {pathInProj};
throw new ModelWorkspaceException(ModelerCore.Util.getString("ModelBufferImpl.Model_is_readonly", params)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public boolean isReadOnly() {
// There are never errors if not opened ...
return true;
}
if( this.isLoaded() && ModelUtil.isVdbSourceObject(this)) {
if( this.isLoaded() && ModelUtil.isLockedSourceObject(this)) {
return true;
}
return ModelUtil.isIResourceReadOnly(getResource());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class ModelUtil {
*/
private static String VDB_NAME_KEY = "core:vdb-name"; //$NON-NLS-1$

private static String LOCKED_NAME_KEY = "core:locked"; //$NON-NLS-1$

private static final String[] EXTENSIONS = new String[] {EXTENSION_XML, EXTENSION_XMI};

private static XmiHeaderCache cache;
Expand Down Expand Up @@ -627,7 +629,7 @@ private static boolean isIndexFileLastModifiedAfterResourceFile( final ModelReso
* @return true if resource is read-only
*/
public static boolean isIResourceReadOnly( final IResource iResource ) {
if(ModelUtil.isVdbSourceObject(iResource)) {
if(ModelUtil.isLockedSourceObject(iResource)) {
return true;
}
final ResourceAttributes attributes = iResource.getResourceAttributes();
Expand Down Expand Up @@ -821,6 +823,37 @@ public static boolean isVdbSourceObject( final Object obj) {

return false;
}

/**
* Returns whether or not
* @param obj the target object
* @return true if the source object is within a vdb source model or is a source model
*/
public static boolean isLockedSourceObject( final Object obj) {
ModelResource mr = null;
if( obj instanceof EObject ) {
mr = ModelerCore.getModelEditor().findModelResource((EObject)obj);
} else if( obj instanceof ModelResource ) {
mr = (ModelResource)obj;
} else if( obj instanceof IFile ) {
try {
mr = ModelUtil.getModelResource((IFile)obj, true);

} catch (ModelWorkspaceException ex) {
// Do nothing
}
}
if( mr != null && mr.isLoaded()) {
try {
String lockedValue = ModelUtil.getModelAnnotationPropertyValue((IFile)mr.getUnderlyingResource(), LOCKED_NAME_KEY);
return lockedValue != null;
} catch (ModelWorkspaceException ex) {
CoreMetamodelPlugin.Util.log(IStatus.ERROR, ex, ex.getMessage());
}
}

return false;
}

/**
* Return the virtual model state of the specified model object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ public void save( IProgressMonitor pm,
((ModelBufferImpl)buf).refresh(pm); // refresh and update mod stamp here
}
}

/**
* Needed an special save method for JDBC Importer in order to create and save a model with the "locked" property in it.
*
* @param pm the process monitor
* @throws ModelWorkspaceException throws exception
*/
public void forceSave( IProgressMonitor pm) throws ModelWorkspaceException {
ModelBuffer buf = getBuffer();
if (buf != null) { // some Openables (like a JavaProject) don't have a buffer
buf.save(pm, true); // can't refresh inside this (threading issues)
this.makeConsistent(pm); // update the element info of this element
((ModelBufferImpl)buf).refresh(pm); // refresh and update mod stamp here
}
}

// /**
// * Find enclosing package fragment root if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public final class JdbcImporter implements ModelerJdbcRelationalConstants {
private JdbcSource src;
private JdbcSource updateSrc;
private JdbcDatabase db;
private boolean isVdbSourceModel;
private String vdbSourceModelName;

/**
/**
* @since 4.0
*/
public JdbcDatabase getDatabase() {
Expand Down Expand Up @@ -227,4 +229,33 @@ public IStatus importModel( final IProgressMonitor monitor ) throws ModelWorkspa
final IStatus status = processor.execute(this.updatedModel, this.db, this.updateSrc.getImportSettings(), monitor);
return status;
}

/**
* @return the isVdbSourceModel
*/
public boolean isVdbSourceModel() {
return this.isVdbSourceModel;
}

/**
* @param isVdbSourceModel the isVdbSourceModel to set
*/
public void setIsVdbSourceModel(boolean isVdbSourceModel) {
this.isVdbSourceModel = isVdbSourceModel;
}

/**
* @return the vdb source model name. may be null
*/
public String getVdbSourceModelName() {
return vdbSourceModelName;
}

/**
* @param name the vdb source model name
*/
public void setVdbSourceModelName(String name) {
this.vdbSourceModelName = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ JdbcSourceSelectionPage.processorComboTooltip =\
\n\nDesigner will attempt to auto-select a processor for you based on your \
connection profile selected above.

JdbcSourceSelectionPage.teiidProfileOptionsGroupLabel=Teiid VDB Source Options
JdbcSourceSelectionPage.isVdbSourceModelCheckboxLabel = Import as VDB source model
JdbcSourceSelectionPage.isVdbSourceModelCheckboxLabel.message = A JDBC connection to a deployed VDB allows creating a \
read-only VDB source model that you can use in your view transformations.\n\n\
If checked, only one schema in your VDB can be selected for import at a time.
JdbcSourceSelectionPage.isVdbSourceModelCheckboxTooltip = \
VDBs containing these view models will reference an import to the original deployed VDB and \
will not contain the metadata from your read-only VDB source model.\n\n\
If checked, only one schema in your VDB can be selected for import at a time.
#=================================================================================================================================
# JdbcSourceWizard

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.teiid.designer.jdbc.JdbcSource;
import org.teiid.designer.jdbc.metadata.Includes;
import org.teiid.designer.jdbc.metadata.JdbcDatabase;
import org.teiid.designer.jdbc.relational.JdbcImporter;
import org.teiid.designer.jdbc.ui.util.JdbcUiUtil;
import org.teiid.designer.ui.UiConstants;
import org.teiid.designer.ui.common.InternalUiConstants;
Expand All @@ -60,6 +61,8 @@ final class JdbcImportMetadataPage extends WizardPage implements InternalUiConst
private static final String I18N_PREFIX = I18nUtil.getPropertyPrefix(JdbcImportMetadataPage.class);

private static final String TITLE = getString("title"); //$NON-NLS-1$

private static final String TITLE_WITH_VDB_SOURCE = TITLE + " (VDB source model)"; //$NON-NLS-1$

private static final String APPROXIMATIONS_BUTTON = getString("approximationsButton"); //$NON-NLS-1$
private static final String FOREIGN_KEYS_BUTTON = getString("foreignKeysButton"); //$NON-NLS-1$
Expand Down Expand Up @@ -107,6 +110,8 @@ private static String getString(final String id, final String parameter1, final
private ListPanel listPanel;
private Map enableMap;
private boolean initd;

private JdbcImporter importer;

//============================================================================================================================
// Constructors
Expand All @@ -128,6 +133,7 @@ private static String getString(final String id, final String parameter1, final
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
* @since 4.0
*/
@SuppressWarnings("unused")
@Override
public void createControl(final Composite parent) {
// Create page
Expand All @@ -139,7 +145,7 @@ public void createControl(final Composite parent) {
{
this.foreignKeysCheckBox = WidgetFactory.createCheckBox(checkBoxPanel);
this.foreignKeysCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
@Override
public void widgetSelected(final SelectionEvent event) {
foreignKeysCheckBoxSelected();
}
Expand Down Expand Up @@ -252,7 +258,13 @@ public void setVisible(final boolean visible) {
}
}
setMessage(INITIAL_MESSAGE);
if( this.importer.isVdbSourceModel() ) {
this.setTitle(TITLE_WITH_VDB_SOURCE);
} else {
this.setTitle(TITLE);
}
super.setVisible(visible);

}

void initializeInTransaction() {
Expand Down Expand Up @@ -543,6 +555,13 @@ void uniqueCheckBoxSelected() {

}

/**
* @param importer the importer to set
*/
public void setImporter(JdbcImporter importer) {
this.importer = importer;
}

//============================================================================================================================
// Utility Methods

Expand Down Expand Up @@ -577,4 +596,6 @@ private void validatePage() {
WizardUtil.setPageComplete(this, INVALID_PAGE_MESSAGE, ERROR);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import org.teiid.designer.jdbc.data.ResultsMetadata.ColumnMetadata;
import org.teiid.designer.jdbc.metadata.JdbcDatabase;
import org.teiid.designer.jdbc.metadata.JdbcNode;
import org.teiid.designer.jdbc.metadata.JdbcSchema;
import org.teiid.designer.jdbc.relational.JdbcImporter;
import org.teiid.designer.jdbc.ui.ModelerJdbcUiConstants;
import org.teiid.designer.jdbc.ui.ModelerJdbcUiPlugin;
import org.teiid.designer.jdbc.ui.util.JdbcUiUtil;
Expand All @@ -88,6 +90,8 @@ public class JdbcImportObjectsPage extends WizardPage
private static final String I18N_PREFIX = I18nUtil.getPropertyPrefix(JdbcImportObjectsPage.class);

private static final String TITLE = getString("title"); //$NON-NLS-1$

private static final String TITLE_WITH_VDB_SOURCE = TITLE + " (VDB source model)"; //$NON-NLS-1$

private static final int COLUMN_COUNT = 1;

Expand All @@ -98,6 +102,8 @@ public class JdbcImportObjectsPage extends WizardPage
private static final String SHOW_SELECTED_SCHEMAS_ID = "showSelectedSchemasValue"; //$NON-NLS-1$

private static final String INVALID_PAGE_MESSAGE = getString("invalidPageMessage"); //$NON-NLS-1$

private static final String TOO_MANY_SCHEMA_MESSAGE = getString("tooManySchemaSelectedMessage"); //$NON-NLS-1$

private static final String NO_OBJECTS = getString("noObjects"); //$NON-NLS-1$

Expand Down Expand Up @@ -138,8 +144,10 @@ private static String getString( final String id,
Button showSelectedSchemasButton;
private JdbcNode selectedNode;
private Map counts;

private JdbcImporter importer;

/**
/**
* @param pageName
* @since 4.0
*/
Expand Down Expand Up @@ -315,6 +323,11 @@ public void setVisible( final boolean visible ) {
refresh();
}
super.setVisible(visible);
if( this.importer.isVdbSourceModel() ) {
this.setTitle(TITLE_WITH_VDB_SOURCE);
} else {
this.setTitle(TITLE);
}
}

/**
Expand Down Expand Up @@ -622,6 +635,7 @@ private void updateCounts( final JdbcNode[] nodes ) throws JdbcException {
* @since 4.0
*/
protected void validatePage( final TreeItem[] items ) {
boolean isOK = true;
try {
// Recalculate node type selection counts
this.counts.clear();
Expand Down Expand Up @@ -654,10 +668,34 @@ protected void validatePage( final TreeItem[] items ) {
} else {
this.statusLabel.setText(getString(STATUS_LABEL_ID, NO_OBJECTS));
WizardUtil.setPageComplete(this, INVALID_PAGE_MESSAGE, ERROR);
isOK = false;
}
} catch (final JdbcException err) {
JdbcUiUtil.showAccessError(err);
}

// If is a vdb source model, then need to validate to insure that only ONE schema is selected
if (isOK && this.importer.isVdbSourceModel()) {
JdbcNode[] selectedNodes = getSelectedChildren();
if (selectedNodes != null && selectedNodes.length > 0) {
int nSchema = 0;
String schemaName = null;
for (JdbcNode node : selectedNodes) {
if (node instanceof JdbcSchema) {
nSchema++;
schemaName = node.getName();
}
if (nSchema > 1) {
WizardUtil.setPageComplete(this, TOO_MANY_SCHEMA_MESSAGE,ERROR);
break;
}
}
if(nSchema == 1 ) {
this.importer.setVdbSourceModelName(schemaName);
}
}

}

if (getSelectedChildren().length == 0) showSelectedSchemasButton.setEnabled(false);
else showSelectedSchemasButton.setEnabled(true);
Expand Down Expand Up @@ -689,6 +727,13 @@ protected void restoreWidgetValues() {
showSelectedSchemasButton.setSelection(showSelectedSchemas);
}

/**
* @param importer the importer to set
*/
public void setImporter(JdbcImporter importer) {
this.importer = importer;
}

/**
* @return The TreeContentProvider used by this page.
* @since 4.3
Expand Down

0 comments on commit 42f49a5

Please sign in to comment.