Skip to content

Commit

Permalink
Merge pull request #1 from phantomjinx/teiid-8.x-upgrade
Browse files Browse the repository at this point in the history
Teiid 8.x upgrade
  • Loading branch information
blafond committed Jul 26, 2012
2 parents 1e044a9 + 5519405 commit 92c20a8
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 8 deletions.
Expand Up @@ -1059,28 +1059,30 @@ public void labelProviderChanged( final LabelProviderChangedEvent event ) {
boolean modelChanged = false;
final Object[] elements = event.getElements();

if (elements == null) {
if (elements == null || elements.length <= 1) {
return;
}

for (final Object nextElement : elements) {
if (nextElement instanceof EObject && ModelUtilities.areModelResourcesSame((EObject)nextElement, getDiagram())) {
modelChanged = true;
break;
if (nextElement instanceof EObject) {
if (ModelUtilities.areModelResourcesSame((EObject)nextElement, getDiagram())) {
modelChanged = true;
}
} else if (nextElement instanceof IResource && ModelUtilities.isModelFile((IResource)nextElement)) {
ModelResource modelResource = null;
ModelResource diagramModelResource = null;
try {
modelResource = ModelUtil.getModelResource((IFile)nextElement, false);
diagramModelResource = ModelUtil.getModel(getDiagram());
if (getDiagram() != null) {
diagramModelResource = ModelUtil.getModel(getDiagram());
}
} catch (final ModelWorkspaceException e) {
DiagramUiConstants.Util.log(IStatus.ERROR,
e,
"DiagramEditor.labelProviderChanged() ERROR finding ModelResource"); //$NON-NLS-1$
}

if (modelResource != null && diagramModelResource != null
&& modelResource.equals(diagramModelResource)) {
if (modelResource != null && diagramModelResource != null && modelResource.equals(diagramModelResource)) {
modelChanged = true;
break;
}
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.teiid.designer.vdb.VdbEntry.Synchronization;
import org.teiid.designer.vdb.manifest.DataRoleElement;
import org.teiid.designer.vdb.manifest.EntryElement;
import org.teiid.designer.vdb.manifest.ImportVdbElement;
import org.teiid.designer.vdb.manifest.ModelElement;
import org.teiid.designer.vdb.manifest.PropertyElement;
import org.teiid.designer.vdb.manifest.TranslatorElement;
Expand Down Expand Up @@ -121,6 +122,7 @@ public static String getPreviewVdbPrefix( IResource resource ) {
final CopyOnWriteArraySet<VdbEntry> entries = new CopyOnWriteArraySet<VdbEntry>();
final CopyOnWriteArraySet<VdbModelEntry> modelEntries = new CopyOnWriteArraySet<VdbModelEntry>();
final CopyOnWriteArraySet<VdbDataRole> dataPolicyEntries = new CopyOnWriteArraySet<VdbDataRole>();
final CopyOnWriteArraySet<VdbImportVdbEntry> importModelEntries = new CopyOnWriteArraySet<VdbImportVdbEntry>();
final Set<TranslatorOverride> translatorOverrides = new TreeSet<TranslatorOverride>(new Comparator<TranslatorOverride>() {
@Override
public int compare( TranslatorOverride translator1,
Expand Down Expand Up @@ -210,7 +212,12 @@ public void tryToDo() throws Exception {
// Initialize model entry imports only after all model entries have been created
for (final VdbModelEntry entry : modelEntries)
entry.initializeImports();


// Vdb Import entries
for (final ImportVdbElement element : manifest.getImportVdbEntries()) {
importModelEntries.add(new VdbImportVdbEntry(Vdb.this, element));
}

// load translator overrides
for (final TranslatorElement translatorElement : manifest.getTranslators()) {
translatorOverrides.add(new TranslatorOverride(Vdb.this, translatorElement));
Expand Down Expand Up @@ -315,6 +322,22 @@ public final boolean addTranslator( TranslatorOverride translatorOverride,

return false;
}

/**
* Add an import VDB attribute to this VDB.
*
* @param importVdbName
*
* @return whether the import vdb attribute was successfully added
*/
public final boolean addImportVdb(String importVdbName) {
if (this.importModelEntries.add(new VdbImportVdbEntry(this, importVdbName))) {
setModified(this, Event.IMPORT_VDB_ENTRY_ADDED, null, importVdbName);
return true;
}

return false;
}

/**
*
Expand Down Expand Up @@ -382,6 +405,13 @@ public final Set<VdbModelEntry> getModelEntries() {
if (!entry.isBuiltIn()) entries.add(entry);
return Collections.unmodifiableSet(entries);
}

/**
* @return the immutable set of import vdb entries within this VDB
*/
public final Collection<VdbImportVdbEntry> getImportVdbEntries() {
return Collections.unmodifiableSet(importModelEntries);
}

/**
* Method to return the File objects associated with each model in this VDB.
Expand Down Expand Up @@ -516,6 +546,22 @@ public final boolean removeTranslator( TranslatorOverride translatorOverride,
return false;
}

/**
* Remove the given {@link VdbImportVdbEntry entry} from this VDB
*
* @param entry
* @param monitor
* @return whether the entry was successfully removed
*/
public final boolean removeImportVdb( VdbImportVdbEntry entry, IProgressMonitor monitor ) {
if (this.importModelEntries.remove(entry)) {
setModified(this, Event.IMPORT_VDB_ENTRY_REMOVED, entry, null);
return true;
}

return false;
}

/**
* Must not be called unless this VDB has been {@link #isModified() modified}
*
Expand Down Expand Up @@ -721,6 +767,31 @@ public static class Event {
*/
public static final String DATA_POLICY_REMOVED = "dataPolicyRemoved"; //$NON-NLS-1$

/**
* The property name sent in events to {@link #addChangeListener(PropertyChangeListener) change listeners} when VDB
* import VDB entry's {@link VdbImportVdbEntry#getVersion version} changes
*/
public static final String IMPORT_VDB_ENTRY_VERSION = "importVdbEntryVersion"; //$NON-NLS-1$

/**
* The property name sent in events to {@link #addChangeListener(PropertyChangeListener) change listeners} when VDB
* import VDB entry's {@link VdbImportVdbEntry#isImportDataPolicies() data policy flag} changes
*/
public static final String IMPORT_VDB_ENTRY_DATA_POLICY = "importVdbEntryDataPolicies"; //$NON-NLS-1$

/**
* The property name sent in events to {@link #addChangeListener(PropertyChangeListener) change listeners} when an
* import VDB entry is added
*/
public static final String IMPORT_VDB_ENTRY_ADDED = "importVdbEntryAdded"; //$NON-NLS-1$

/**
* The property name sent in events to {@link #addChangeListener(PropertyChangeListener) change listeners} when an
* import VDB entry is removed.
*
*/
public static final String IMPORT_VDB_ENTRY_REMOVED = "importVdbEntryRemoved"; //$NON-NLS-1$

/**
* The property name sent in events to {@link #addChangeListener(PropertyChangeListener) change listeners} when a VDB is
* {@link #close() closed}
Expand Down
@@ -0,0 +1,128 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.vdb;

import java.util.concurrent.atomic.AtomicReference;

import org.teiid.designer.vdb.Vdb.Event;
import org.teiid.designer.vdb.manifest.ImportVdbElement;

/**
*
*
* @since 8.0
*/
public class VdbImportVdbEntry {

private final Vdb vdb;

private String name;

final AtomicReference<Integer> version = new AtomicReference<Integer>();

final AtomicReference<Boolean> importDataPolicies = new AtomicReference<Boolean>();

/**
* @param vdb
* @param importVdbName
*/
public VdbImportVdbEntry(Vdb vdb, String importVdbName) {
this.vdb = vdb;
this.name = importVdbName;
}

/**
* @param vdb
* @param element
*/
VdbImportVdbEntry(Vdb vdb, ImportVdbElement element) {
this(vdb, element.getName());
this.version.set(element.getVersion());
this.importDataPolicies.set(element.isImportDataPolicies());
}

/**
* @return return the name
*/
public String getName() {
return name;
}

/**
* @return return the version
*/
public int getVersion() {
return version.get();
}

/**
* Modify the version attribute
*
* @param version
*/
public void setVersion(int version) {
final int oldVersion = this.version.get();
if (version == oldVersion) return;
this.version.set(version);
vdb.setModified(this, Event.IMPORT_VDB_ENTRY_VERSION, oldVersion, version);
}

/**
* @return the import data policies flag
*/
public boolean isImportDataPolicies() {
return importDataPolicies.get();
}

/**
* Modify the import data policies flag
*
* @param importDataPolicies
*/
public void setImportDataPolicies(boolean importDataPolicies) {
final boolean oldImportDataPolicies = this.importDataPolicies.get();
if (importDataPolicies == oldImportDataPolicies) return;
this.importDataPolicies.set(importDataPolicies);
vdb.setModified(this, Event.IMPORT_VDB_ENTRY_DATA_POLICY, oldImportDataPolicies, importDataPolicies);
}

@SuppressWarnings("javadoc")
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result
+ ((this.vdb == null) ? 0 : this.vdb.hashCode());
return result;
}

@SuppressWarnings("javadoc")
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VdbImportVdbEntry other = (VdbImportVdbEntry) obj;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.vdb == null) {
if (other.vdb != null)
return false;
} else if (!this.vdb.equals(other.vdb))
return false;
return true;
}
}
@@ -0,0 +1,74 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.vdb.manifest;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import org.teiid.designer.vdb.VdbImportVdbEntry;

/**
* @since 8.0
*/
@XmlAccessorType( XmlAccessType.NONE )
@XmlType( name = "" )
public class ImportVdbElement implements Serializable {

private static final long serialVersionUID = 1L;

@XmlAttribute( name = "name", required = true )
private String name;

@XmlAttribute( name = "version", required = true )
private int version = 1;

@XmlAttribute( name = "import-data-policies" )
private boolean importDataPolicies = true;

/**
* Used by JAXB
*/
public ImportVdbElement() {
}

/**
* Used to save a model entry
*
* @param entry
*/
ImportVdbElement( final VdbImportVdbEntry entry ) {
name = entry.getName();
version = entry.getVersion();
importDataPolicies = entry.isImportDataPolicies();
}

/**
* @return name
*/
public String getName() {
return name;
}

/**
* @return version
*/
public int getVersion() {
return version;
}

/**
* @return importDataPolicies
*/
public boolean isImportDataPolicies() {
return importDataPolicies;
}
}

0 comments on commit 92c20a8

Please sign in to comment.