use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.
the class EmbeddedServer method deployVDBZip.
/**
* Deploy a vdb zip file. The name and version will be derived from the xml.
* @param url
* @throws TranslatorException
* @throws ConnectorManagerException
* @throws VirtualDatabaseException
* @throws URISyntaxException
* @throws IOException
*/
public void deployVDBZip(URL url) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException, URISyntaxException {
VirtualFile root = PureZipFileSystem.mount(url);
VDBMetaData metadata;
// $NON-NLS-1$
VirtualFile vdbMetadata = root.getChild("/META-INF/vdb.xml");
if (vdbMetadata.exists()) {
try {
VDBMetadataParser.validate(vdbMetadata.openStream());
} catch (SAXException e) {
throw new VirtualDatabaseException(e);
}
InputStream is = vdbMetadata.openStream();
try {
metadata = VDBMetadataParser.unmarshell(is);
} catch (XMLStreamException e) {
throw new VirtualDatabaseException(e);
}
} else {
// $NON-NLS-1$
vdbMetadata = root.getChild("/META-INF/vdb.ddl");
DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
metadata = store.getVDBMetadata(ObjectConverterUtil.convertToString(vdbMetadata.openStream()));
}
VDBResources resources = new VDBResources(root, metadata);
deployVDB(metadata, resources);
}
use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.
the class EmbeddedServer method deployVDB.
/**
* Deploy a vdb.xml file. The name and version will be derived from the xml.
* @param is, which will be closed by this deployment
* @param ddl, true if the file contents are DDL
* @throws TranslatorException
* @throws ConnectorManagerException
* @throws VirtualDatabaseException
* @throws IOException
*/
public void deployVDB(InputStream is, boolean ddl) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException {
if (is == null) {
return;
}
byte[] bytes = ObjectConverterUtil.convertToByteArray(is);
VDBMetaData metadata = null;
if (ddl) {
DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
metadata = store.getVDBMetadata(new String(bytes));
} else {
try {
// TODO: find a way to do this off of the stream
VDBMetadataParser.validate(new ByteArrayInputStream(bytes));
} catch (SAXException e) {
throw new VirtualDatabaseException(e);
}
try {
metadata = VDBMetadataParser.unmarshell(new ByteArrayInputStream(bytes));
} catch (XMLStreamException e) {
throw new VirtualDatabaseException(e);
}
}
metadata.setXmlDeployment(true);
deployVDB(metadata, null);
}
use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.
the class VDBParserDeployer method parseVDBDDL.
private VDBMetaData parseVDBDDL(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, boolean xmlDeployment) throws DeploymentUnitProcessingException {
try {
PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
String vdbContents = replacer.replaceProperties(ObjectConverterUtil.convertToString(file.openStream()));
ObjectSerializer serializer = ObjectSerializer.class.cast(phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER).getValue());
DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(vdbRepo);
VDBMetaData vdb = store.getVDBMetadata(vdbContents);
// if there is persisted one, let that be XML version for now.
if (serializer.buildVdbXml(vdb).exists()) {
vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
}
vdb.setStatus(Status.LOADING);
vdb.setXmlDeployment(xmlDeployment);
deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_RUNTIME, "VDB " + file.getName() + " has been parsed.");
return vdb;
} catch (XMLStreamException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
}
}
use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.
the class AbstractVDBDeployer method processVDBDDL.
private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
if (vdb.getStatus() == Status.FAILED) {
return;
}
String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
if (ddl != null) {
final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {
@Override
protected TransformationMetadata getTransformationMetadata() {
return metadata;
}
@Override
public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
ModelMetaData model = vdb.getModel(schemaName);
MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
if (!includeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
}
if (!excludeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
}
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
MetadataRepository metadataRepository;
try {
metadataRepository = getMetadataRepository(serverType);
if (metadataRepository == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
}
} catch (VirtualDatabaseException e1) {
throw new MetadataException(e1);
}
metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
ExecutionFactory ef = null;
Object cf = null;
Exception te = null;
for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
if (te != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
te = null;
}
try {
if (cm != null) {
ef = cm.getExecutionFactory();
cf = cm.getConnectionFactory();
}
} catch (TranslatorException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
}
try {
metadataRepository.loadMetadata(factory, ef, cf);
break;
} catch (Exception e) {
te = e;
factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
}
}
if (te != null) {
if (te instanceof RuntimeException) {
throw (RuntimeException) te;
}
throw new MetadataException(te);
}
}
};
deploymentStore.startEditing(false);
deploymentStore.databaseCreated(database);
deploymentStore.databaseSwitched(database.getName(), database.getVersion());
deploymentStore.setMode(Mode.SCHEMA);
try {
QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
} finally {
deploymentStore.stopEditing();
}
DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
}
}
Aggregations