Skip to content

Commit

Permalink
TEIID-5007 making systemfunctionmanager state non-static
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Aug 23, 2017
1 parent 78acae2 commit 15e8761
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 61 deletions.
Expand Up @@ -74,7 +74,7 @@
* flag after calling deep copy not supported", this is copy of WholeRowIterator
*/
public class EvaluatorIterator extends WrappingIterator {
private static final SystemFunctionManager SFM = new SystemFunctionManager();
private static final SystemFunctionManager SFM = SystemMetadata.getInstance().getSystemFunctionManager();
public static final String QUERYSTRING = "QUERYSTRING"; //$NON-NLS-1$
public static final String TABLE = "TABLE";//$NON-NLS-1$
public static final String DDL = "DDL";//$NON-NLS-1$
Expand Down
Expand Up @@ -26,40 +26,30 @@
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.metadata.FunctionMetadataValidator;
import org.teiid.query.function.source.SystemSource;
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.query.validator.ValidatorReport;


public class SystemFunctionManager {

private static volatile FunctionTree systemFunctionTree;
private FunctionTree systemFunctionTree;
private Map<String, Datatype> types;

/**
* Provide access to system functions - can only be used after SystemMetadata has been initialized
*/
public SystemFunctionManager() {
this.types = SystemMetadata.getInstance().getRuntimeTypeMap();
}

public SystemFunctionManager(Map<String, Datatype> typeMap) {
this.types = typeMap;
// Create the system source and add it to the source list
SystemSource systemSource = new SystemSource();
// Validate the system source - should never fail
ValidatorReport report = new ValidatorReport("Function Validation"); //$NON-NLS-1$
Collection<FunctionMethod> functionMethods = systemSource.getFunctionMethods();
FunctionMetadataValidator.validateFunctionMethods(functionMethods,report, types);
if(report.hasItems()) {
// Should never happen as SystemSourcTe doesn't change
System.err.println(QueryPlugin.Util.getString("ERR.015.001.0005", report)); //$NON-NLS-1$
}
systemFunctionTree = new FunctionTree(CoreConstants.SYSTEM_MODEL, systemSource, true);
}

public FunctionTree getSystemFunctions() {
if(systemFunctionTree == null) {
// Create the system source and add it to the source list
SystemSource systemSource = new SystemSource();
// Validate the system source - should never fail
ValidatorReport report = new ValidatorReport("Function Validation"); //$NON-NLS-1$
Collection<FunctionMethod> functionMethods = systemSource.getFunctionMethods();
FunctionMetadataValidator.validateFunctionMethods(functionMethods,report, types);
if(report.hasItems()) {
// Should never happen as SystemSourcTe doesn't change
System.err.println(QueryPlugin.Util.getString("ERR.015.001.0005", report)); //$NON-NLS-1$
}
systemFunctionTree = new FunctionTree(CoreConstants.SYSTEM_MODEL, systemSource, true);
}
return systemFunctionTree;
}

Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.teiid.metadata.Database.ResourceType;
import org.teiid.metadata.Grant.Permission.Privilege;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.parser.OptionsUtil;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.symbol.GroupSymbol;
Expand All @@ -53,7 +52,6 @@ public static enum Mode {ANY, DOMAIN, SCHEMA, DATABASE_STRUCTURE}
private boolean strict;

public abstract Map<String, Datatype> getRuntimeTypes();
public abstract SystemFunctionManager getSystemFunctionManager();

public void startEditing(boolean persist) {
if (this.persist) {
Expand Down
Expand Up @@ -113,8 +113,8 @@ public SystemMetadata() {
vdb.setName("System"); //$NON-NLS-1$
vdb.setVersion(1);
Properties p = new Properties();
QueryParser parser = new QueryParser();
this.systemFunctionManager = new SystemFunctionManager(typeMap);
QueryParser parser = new QueryParser();
systemStore = loadSchema(vdb, p, "SYS", parser).asMetadataStore(); //$NON-NLS-1$
systemStore.addDataTypes(typeMap);
loadSchema(vdb, p, "SYSADMIN", parser).mergeInto(systemStore); //$NON-NLS-1$
Expand Down Expand Up @@ -175,4 +175,8 @@ public Map<String, Datatype> getRuntimeTypeMap() {
public MetadataStore getSystemStore() {
return systemStore;
}

public SystemFunctionManager getSystemFunctionManager() {
return systemFunctionManager;
}
}
15 changes: 3 additions & 12 deletions engine/src/main/java/org/teiid/query/parser/QueryParser.java
Expand Up @@ -40,7 +40,6 @@
import org.teiid.metadata.Parser;
import org.teiid.metadata.Server;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.DatabaseStore;
import org.teiid.query.metadata.DatabaseStore.Mode;
Expand All @@ -62,24 +61,17 @@ public class QueryParser implements Parser {

private static final class SingleSchemaDatabaseStore extends DatabaseStore {
private final MetadataFactory factory;
private SystemFunctionManager systemFunctionManager;
private TransformationMetadata transformationMetadata;

private SingleSchemaDatabaseStore(MetadataFactory factory, SystemFunctionManager systemFunctionManager) {
private SingleSchemaDatabaseStore(MetadataFactory factory) {
this.factory = factory;
this.systemFunctionManager = systemFunctionManager;
}

@Override
public Map<String, Datatype> getRuntimeTypes() {
return factory.getDataTypes();
}

@Override
public SystemFunctionManager getSystemFunctionManager() {
return systemFunctionManager;
}

@Override
protected TransformationMetadata getTransformationMetadata() {
return transformationMetadata;
Expand Down Expand Up @@ -509,7 +501,7 @@ public void parseDDL(MetadataFactory factory, String ddl) {
}

public void parseDDL(final MetadataFactory factory, Reader ddl) {
SingleSchemaDatabaseStore store = new SingleSchemaDatabaseStore(factory, new SystemFunctionManager(factory.getDataTypes()));
SingleSchemaDatabaseStore store = new SingleSchemaDatabaseStore(factory);

store.startEditing(true);
Database db = new Database(factory.getVdbName(), factory.getVdbVersion());
Expand All @@ -531,8 +523,7 @@ public void parseDDL(final MetadataFactory factory, Reader ddl) {

//with the schema created, create the TransformationMetadata
CompositeMetadataStore cms = new CompositeMetadataStore(db.getMetadataStore());
TransformationMetadata qmi = new TransformationMetadata(DatabaseUtil.convert(db), cms, null,
store.getSystemFunctionManager().getSystemFunctions(), null);
TransformationMetadata qmi = new TransformationMetadata(DatabaseUtil.convert(db), cms, null, null, null);

store.setTransformationMetadata(qmi);

Expand Down
Expand Up @@ -37,7 +37,7 @@

@SuppressWarnings("nls")
public class TestMetadataValidator {
public static final SystemFunctionManager SFM = new SystemFunctionManager();
public static final SystemFunctionManager SFM = SystemMetadata.getInstance().getSystemFunctionManager();
private VDBMetaData vdb = new VDBMetaData();
private MetadataStore store = new MetadataStore();

Expand Down
Expand Up @@ -796,10 +796,6 @@ public static Database helpParse(String ddl, DatabaseStore.Mode mode) {
public Map<String, Datatype> getRuntimeTypes() {
return dataTypes;
}
@Override
public SystemFunctionManager getSystemFunctionManager() {
return new SystemFunctionManager();
}
@Override
protected TransformationMetadata getTransformationMetadata() {
Database database = getCurrentDatabase();
Expand All @@ -808,7 +804,7 @@ protected TransformationMetadata getTransformationMetadata() {
//grants are already stored on the VDBMetaData
store.getGrants().clear();
return new TransformationMetadata(DatabaseUtil.convert(database), store, null,
getSystemFunctionManager().getSystemFunctions(), null);
null, null);
}
};
store.startEditing(true);
Expand Down
Expand Up @@ -57,7 +57,7 @@
@SuppressWarnings("nls")
public class RealMetadataFactory {

public static final SystemFunctionManager SFM = new SystemFunctionManager();
public static final SystemFunctionManager SFM = SystemMetadata.getInstance().getSystemFunctionManager();

private static TransformationMetadata CACHED_EXAMPLE1 = example1();
private static TransformationMetadata CACHED_BQT = exampleBQT();
Expand Down
Expand Up @@ -102,6 +102,7 @@
import org.teiid.net.socket.AuthenticationType;
import org.teiid.query.ObjectReplicator;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.replication.jgroups.JGroupsObjectReplicator;
import org.teiid.runtime.MaterializationManager;
import org.teiid.runtime.NodeTracker;
Expand Down Expand Up @@ -258,7 +259,7 @@ public TranslatorRepository getValue() throws IllegalStateException, IllegalArgu
final ConnectorManagerRepository connectorManagerRepo = buildConnectorManagerRepository(translatorRepo);

// system function tree
SystemFunctionManager systemFunctionManager = new SystemFunctionManager();
SystemFunctionManager systemFunctionManager = SystemMetadata.getInstance().getSystemFunctionManager();

// VDB repository
final VDBRepository vdbRepository = new VDBRepository();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.teiid.query.function.UDFSource;
import org.teiid.query.metadata.BasicQueryMetadataWrapper;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.SystemMetadata;


/**
Expand Down Expand Up @@ -110,7 +111,7 @@ public void addUDF(String schema, Collection<FunctionMethod> methods) {
return;
}
this.functions.add(new FunctionTree(schema, new UDFSource(methods)));
SystemFunctionManager sfm = new SystemFunctionManager();
SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
functionLibrary = new FunctionLibrary(sfm.getSystemFunctions(), this.functions.toArray(new FunctionTree[this.functions.size()]));
}

Expand Down
Expand Up @@ -79,7 +79,7 @@ public static TransformationMetadata getVDBMetadata(String vdbName, URL vdbURL,
methods = FunctionMetadataReader.loadFunctionMethods(udfFile.openStream());
trees = Arrays.asList(new FunctionTree(schema, new UDFSource(methods), true));
}
SystemFunctionManager sfm = new SystemFunctionManager();
SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
vdbmetadata = new TransformationMetadata(vdb, new CompositeMetadataStore(Arrays.asList(SystemMetadata.getInstance().getSystemStore(), imf.store)), imf.resources.getEntriesPlusVisibilities(), sfm.getSystemFunctions(), trees);
VDB_CACHE.put(vdbURL, vdbmetadata);
return vdbmetadata;
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.teiid.deployers.VDBRepository;
import org.teiid.metadata.Database;
import org.teiid.metadata.Datatype;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.DatabaseStore;
import org.teiid.query.metadata.DatabaseUtil;
import org.teiid.query.parser.QueryParser;
Expand All @@ -53,11 +52,6 @@ protected boolean shouldValidateDatabaseBeforeDeploy() {
return false;
}

@Override
public SystemFunctionManager getSystemFunctionManager() {
return vdbRepo.getSystemFunctionManager();
}

public VDBMetaData getVDBMetadata(String contents) {
StringReader reader = new StringReader(contents);
try {
Expand Down
Expand Up @@ -54,7 +54,6 @@
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.VDBResource;
import org.teiid.metadatastore.DeploymentBasedDatabaseStore;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.*;
import org.teiid.query.metadata.DatabaseStore.Mode;
import org.teiid.query.parser.QueryParser;
Expand Down Expand Up @@ -191,10 +190,6 @@ protected void loadMetadata(VDBMetaData vdb, ConnectorManagerRepository cmr,
public Map<String, Datatype> getRuntimeTypes() {
return getVDBRepository().getRuntimeTypeMap();
}
@Override
public SystemFunctionManager getSystemFunctionManager() {
return getVDBRepository().getSystemFunctionManager();
}
};
dbStore.startEditing(true);
dbStore.databaseCreated(new Database("x", "1")); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
Expand Up @@ -111,9 +111,9 @@
import org.teiid.net.ServerConnection;
import org.teiid.net.socket.ObjectChannel;
import org.teiid.query.ObjectReplicator;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.DDLStringVisitor;
import org.teiid.query.metadata.PureZipFileSystem;
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.metadata.VDBResources;
import org.teiid.query.sql.lang.Command;
Expand Down Expand Up @@ -562,7 +562,7 @@ public void finishedDeployment(String name, CompositeVDB vdb) {
public void beforeRemove(String name, CompositeVDB vdb) {
}
});
this.repo.setSystemFunctionManager(new SystemFunctionManager());
this.repo.setSystemFunctionManager(SystemMetadata.getInstance().getSystemFunctionManager());
this.repo.start();
}

Expand Down

0 comments on commit 15e8761

Please sign in to comment.