Skip to content

Commit

Permalink
TEIID-3658: Adding code to always add PG system metadata tables irres…
Browse files Browse the repository at this point in the history
…pective of the PG transport availability, flags added to default to previous functionality

Conflicts:
	runtime/src/main/java/org/teiid/deployers/VDBRepository.java
  • Loading branch information
rareddy authored and johnathonlee committed Sep 21, 2015
1 parent 29698bd commit e0a7cf5
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 17 deletions.
61 changes: 52 additions & 9 deletions admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
Expand Up @@ -47,11 +47,11 @@ public class ModelMetaData extends AdminObjectImpl implements Model {
protected String modelType = Type.PHYSICAL.name();
protected String description;
protected String path;
protected Boolean visible = true;
protected boolean visible = true;
protected List<Message> messages;
protected transient List<Message> runtimeMessages;
protected String schemaSourceType;
protected String schemaText;
protected List<String> sourceMetadataType = new ArrayList<String>();
protected List<String> sourceMetadataText = new ArrayList<String>();
protected MetadataStatus metadataStatus = MetadataStatus.LOADING;

@Override
Expand Down Expand Up @@ -120,7 +120,7 @@ public void setMetadataStatus(Model.MetadataStatus status) {
this.metadataStatus = status;
}

void setMetadataStatus(String status) {
public void setMetadataStatus(String status) {
if (status != null) {
this.metadataStatus = Model.MetadataStatus.valueOf(status);
}
Expand All @@ -130,7 +130,7 @@ public String toString() {
return getName() + this.sources;
}

public void setVisible(Boolean value) {
public void setVisible(boolean value) {
this.visible = value;
}

Expand Down Expand Up @@ -327,21 +327,64 @@ public boolean equals(Object obj) {
return true;
}
}

public void addSourceMetadata(String type, String text) {
this.sourceMetadataType.add(type);
this.sourceMetadataText.add(text);
}

/**
* @see #getSourceMetadataType()
*/
@Deprecated
public String getSchemaSourceType() {
return schemaSourceType;
if (!sourceMetadataType.isEmpty()) {
return sourceMetadataType.get(0);
}
return null;
}

/**
* @see #addSourceMetadata(String, String)
*/
@Deprecated
public void setSchemaSourceType(String schemaSourceType) {
this.schemaSourceType = schemaSourceType;
if (!sourceMetadataType.isEmpty()) {
sourceMetadataType.set(0, schemaSourceType);
} else {
sourceMetadataType.add(schemaSourceType);
}
}

/**
* @see #getSourceMetadataText()
*/
@Deprecated
public String getSchemaText() {
return schemaText;
if (!sourceMetadataText.isEmpty()) {
return sourceMetadataText.get(0);
}
return null;
}

/**
* @see #addSourceMetadata(String, String)
*/
@Deprecated
public void setSchemaText(String schemaText) {
this.schemaText = schemaText;
if (!sourceMetadataText.isEmpty()) {
sourceMetadataText.set(0, schemaText);
} else {
sourceMetadataText.add(schemaText);
}
}

public List<String> getSourceMetadataType() {
return sourceMetadataType;
}

public List<String> getSourceMetadataText() {
return sourceMetadataText;
}

@Override
Expand Down
21 changes: 13 additions & 8 deletions runtime/src/main/java/org/teiid/deployers/VDBRepository.java
Expand Up @@ -66,6 +66,7 @@
public class VDBRepository implements Serializable{
private static final long serialVersionUID = 312177538191772674L;
private static final int DEFAULT_TIMEOUT_MILLIS = PropertiesUtils.getIntProperty(System.getProperties(), "org.teiid.clientVdbLoadTimeoutMillis", 300000); //$NON-NLS-1$
private static final boolean LOAD_PG_METADATA_ON_PG_TRANSPORT = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.loadPgMetadataOnPgTransport", false); //$NON-NLS-1$

private NavigableMap<VDBKey, CompositeVDB> vdbRepo = new ConcurrentSkipListMap<VDBKey, CompositeVDB>();
private NavigableMap<VDBKey, VDBMetaData> pendingDeployments = new ConcurrentSkipListMap<VDBKey, VDBMetaData>();
Expand All @@ -87,15 +88,21 @@ public void addVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<S
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40022, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40022));
}

if (this.odbcEnabled && odbcStore == null) {
this.odbcStore = getODBCMetadataStore();
boolean pgMetadataEnabled = true;
// check to make sure old default behavior is honored
if (LOAD_PG_METADATA_ON_PG_TRANSPORT) {
pgMetadataEnabled = this.odbcEnabled;
}
String excludePgMetadata = vdb.getPropertyValue("exclude-pg-metadata");
if (excludePgMetadata != null) {
pgMetadataEnabled = !Boolean.parseBoolean(excludePgMetadata);
}

MetadataStore[] stores = null;
if (this.odbcStore == null) {
stores = new MetadataStore[] {this.systemStore};
if (pgMetadataEnabled) {
stores = new MetadataStore[] {this.systemStore, odbcStore};
} else {
stores = new MetadataStore[] {this.systemStore, odbcStore};
stores = new MetadataStore[] {this.systemStore};
}
CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this, stores);
lock.lock();
Expand Down Expand Up @@ -270,9 +277,7 @@ public Map<String, Datatype> getRuntimeTypeMap() {

// this is called by mc
public void start() {
if (this.odbcEnabled) {
this.odbcStore = getODBCMetadataStore();
}
this.odbcStore = getODBCMetadataStore();
}

public void finishDeployment(String name, int version, boolean reload) {
Expand Down
@@ -0,0 +1,98 @@
/*
* JBoss, Home of Professional Open Source.
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
package org.teiid.systemmodel;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.adminapi.Model.Type;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.deployers.VirtualDatabaseException;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.jdbc.AbstractMMQueryTestCase;
import org.teiid.jdbc.FakeServer;
import org.teiid.translator.TranslatorException;

public class TestPGMetadata extends AbstractMMQueryTestCase {
static FakeServer server = null;

@BeforeClass
public static void setup() {
server = new FakeServer(true);
}

@AfterClass
public static void teardown() {
server.stop();
}

private static VDBMetaData buildVDB(String name)
throws ConnectorManagerException, VirtualDatabaseException,
TranslatorException {
VDBMetaData vdb = new VDBMetaData();
vdb.setName(name);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.addSourceMetadata("DDL", "create view v as select 1");
mmd.setModelType(Type.VIRTUAL);
vdb.addModel(mmd);
return vdb;
}

@Test
public void test_PG_MetadataOFF() throws Exception {
VDBMetaData vdb = buildVDB("x");
vdb.addProperty("exclude-pg-metadata", "true");
server.deployVDB(vdb);
this.internalConnection = server.createConnection("jdbc:teiid:x"); //$NON-NLS-1$ //$NON-NLS-2$
try {
execute("select * FROM pg_am"); //$NON-NLS-1$
Assert.fail("there should be no PG metadata");
} catch (Exception e) {
}
}
@Test
public void test_PG_Metadata_ON() throws Exception {
VDBMetaData vdb = buildVDB("y");
vdb.addProperty("exclude-pg-metadata", "false");
server.deployVDB(vdb);
this.internalConnection = server.createConnection("jdbc:teiid:y"); //$NON-NLS-1$ //$NON-NLS-2$
try {
execute("select * FROM pg_am"); //$NON-NLS-1$
} catch (Exception e) {
Assert.fail("there should be PG metadata");
}
}
@Test
public void test_PG_Metadata_DEFAULT() throws Exception {
VDBMetaData vdb = buildVDB("z");
server.deployVDB(vdb);
this.internalConnection = server.createConnection("jdbc:teiid:z"); //$NON-NLS-1$ //$NON-NLS-2$
try {
execute("select * FROM pg_am"); //$NON-NLS-1$
} catch (Exception e) {
Assert.fail("there should be PG metadata");
}
}
}

0 comments on commit e0a7cf5

Please sign in to comment.