Skip to content

Commit

Permalink
TEIID-2964 allowing naming convention to override version
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed May 27, 2014
1 parent 16219ee commit 57e748d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Expand Up @@ -45,6 +45,7 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBMetadataParser;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.StringUtil;
import org.teiid.deployers.UDFMetaData;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
Expand All @@ -69,7 +70,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws Deployment
VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

if (TeiidAttachments.isVDBXMLDeployment(deploymentUnit)) {
parseVDBXML(file, deploymentUnit, phaseContext).setXmlDeployment(true);
parseVDBXML(file, deploymentUnit, phaseContext, true);
}
else {
// scan for different files
Expand All @@ -94,7 +95,7 @@ public boolean accepts(VirtualFile file) {
if (childFiles.size() != 1) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50101, deploymentUnit, childFiles.size()));
}
parseVDBXML(childFiles.get(0), deploymentUnit, phaseContext);
parseVDBXML(childFiles.get(0), deploymentUnit, phaseContext, false);

mergeMetaData(deploymentUnit);

Expand All @@ -104,7 +105,7 @@ public boolean accepts(VirtualFile file) {
}
}

private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, boolean xmlDeployment) throws DeploymentUnitProcessingException {
try {
VDBMetadataParser.validate(file.openStream());
PropertyResolver propertyResolver = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_RESOLVER);
Expand All @@ -117,6 +118,21 @@ private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit,
vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
}
vdb.setStatus(Status.LOADING);
if (xmlDeployment) {
vdb.setXmlDeployment(true);
} else {
String name = deploymentUnit.getName();
String fileName = StringUtil.getLastToken(name, "/"); //$NON-NLS-1$
String[] parts = fileName.split("\\."); //$NON-NLS-1$
if (parts[0].equalsIgnoreCase(vdb.getName()) && parts.length >= 3) {
try {
int fileVersion = Integer.parseInt(parts[parts.length - 2]);
vdb.setVersion(fileVersion);
} catch (NumberFormatException e) {

}
}
}
deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
LogManager.logDetail(LogConstants.CTX_RUNTIME,"VDB "+file.getName()+" has been parsed."); //$NON-NLS-1$ //$NON-NLS-2$
return vdb;
Expand Down
Expand Up @@ -31,7 +31,12 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
Expand Down Expand Up @@ -122,6 +127,10 @@ public void testVDBDeployment() throws Exception {
admin.deleteDataSource("Oracle11_PushDS");
vdb = admin.getVDB("bqt", 1);
assertFalse(vdb.isValid());

admin.deploy("bqt.2.vdb",new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));
vdb = admin.getVDB("bqt", 2);
assertEquals(2, vdb.getVersion());
}

@Test
Expand Down

0 comments on commit 57e748d

Please sign in to comment.