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
  • Loading branch information
rareddy committed Aug 28, 2015
1 parent 3892fdf commit 9cb549c
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 8 deletions.
21 changes: 13 additions & 8 deletions runtime/src/main/java/org/teiid/deployers/VDBRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class VDBRepository implements Serializable{
private static final String LIFECYCLE_CONTEXT = LogConstants.CTX_RUNTIME + ".VDBLifeCycleListener"; //$NON-NLS-1$
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 @@ -95,15 +96,21 @@ public void addVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<S
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40143, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40143, vdb));
}

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 @@ -280,9 +287,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
Original file line number Diff line number Diff line change
@@ -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 9cb549c

Please sign in to comment.