Author: shawkins
Date: 2009-11-15 21:17:12 -0500 (Sun, 15 Nov 2009)
New Revision: 1550
Removed:
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/QueryMetadataCache.java
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java
trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ColumnRecordImpl.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/DatatypeRecordImpl.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ModelRecordImpl.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferConfig.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/batch/BatchedUpdatePlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java
trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java
trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/NodeTestUtil.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java
trunk/metadata/src/main/java/org/teiid/metadata/index/TransformationRecordImpl.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBaseDQPService.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java
Log:
TEIID-145 TEIID-869 defaulting to allowing double quoted identifiers (ansi standard). and
further cleaning up metadata
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -280,7 +280,7 @@
.append(".ProcedureParams as p CROSS JOIN ") //$NON-NLS-1$
.append(RUNTIME_MODEL.VIRTUAL_MODEL_NAME)
.append(".VirtualDatabases v WHERE
UCASE(v.Name)").append(LIKE_ESCAPE).append("AND
UCASE(p.ProcedureName)").append(LIKE_ESCAPE).append("AND UCASE(p.Name) LIKE
?") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
- .append(" ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, COLUMN_TYPE, POSITION
OPTION MAKEDEP SystemPhysical.COLUMNS").toString(); //$NON-NLS-1$
+ .append(" ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, COLUMN_TYPE,
POSITION").toString(); //$NON-NLS-1$
private static final String QUERY_SCHEMAS =
new StringBuffer("SELECT Name AS TABLE_SCHEM, NULL AS TABLE_CATALOG")
//$NON-NLS-1$
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -56,6 +56,7 @@
import com.metamatrix.vdb.materialization.ScriptType;
import com.metamatrix.vdb.runtime.BasicModelInfo;
import com.metamatrix.vdb.runtime.BasicVDBDefn;
+import com.metamatrix.vdb.runtime.VDBKey;
/**
* Latest incarnation of the VDBContext, specifically for weeding out
@@ -87,6 +88,8 @@
private Set<String> pathsInArchive = new HashSet<String>();
private boolean open;
+
+ private VDBKey key;
public static VDBArchive loadVDB(URL vdbURL, File deployDirectory) throws IOException {
boolean loadedFromDef = false;
@@ -365,7 +368,7 @@
* @param vdbDef
* @throws IOException
*/
- public void updateConfigurationDef(BasicVDBDefn vdbDef) throws IOException {
+ public synchronized void updateConfigurationDef(BasicVDBDefn vdbDef) throws IOException
{
if (vdbDef == null) {
return;
}
@@ -383,6 +386,7 @@
// update the local copies.
this.def = vdbDef;
appendManifest(this.def);
+ this.key = null;
}
/**
@@ -467,13 +471,6 @@
return this.def.getName();
}
- public void setName(String name) {
- checkOpen();
- if (this.def != null) {
- this.def.setName(name);
- }
- }
-
public String getVersion() {
checkOpen();
return this.def.getVersion();
@@ -564,5 +561,29 @@
}
return this.def.getModel(name);
}
+
+ /**
+ * checks the validity of the VDB
+ * @return true if valid; false otherwise.
+ */
+ public boolean isValid() {
+ if (getVDBValidityErrors() != null) {
+ return false;
+ }
+
+ Collection models = getConfigurationDef().getModels();
+ if (models != null && models.isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public synchronized VDBKey getVDBKey() {
+ if (key == null) {
+ key = new VDBKey(getName(), getVersion());
+ }
+ return key;
+ }
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -70,14 +70,6 @@
}
public String getName() {
- if(this.name == null || this.name.trim().length() == 0) {
- int nmIdx = this.fullName != null ? this.fullName.lastIndexOf(NAME_DELIM_CHAR) : -1;
- if (nmIdx == -1) {
- this.name = this.fullName;
- } else {
- this.name = this.fullName != null ? this.fullName.substring(nmIdx+1) : null;
- }
- }
return name;
}
@@ -89,23 +81,20 @@
int prntIdx = fullName.indexOf(NAME_DELIM_CHAR);
return fullName.substring(0, prntIdx);
}
-
+
public String toString() {
- return uuid + ": " + name; //$NON-NLS-1$
+ StringBuffer sb = new StringBuffer(100);
+ sb.append(getClass().getSimpleName());
+ sb.append(" name="); //$NON-NLS-1$
+ sb.append(getName());
+ sb.append(", nameInSource="); //$NON-NLS-1$
+ sb.append(getNameInSource());
+ sb.append(", uuid="); //$NON-NLS-1$
+ sb.append(getUUID());
+ return sb.toString();
}
/**
- * @deprecated the returned value may be incorrect in the case of an XML element (see
defects #11326 and #11362)
- */
- public String getParentFullName() {
- int prntIdx = getFullName() != null ?
getFullName().lastIndexOf(NAME_DELIM_CHAR+getName()) : -1;
- if (prntIdx <= 0) {
- return ""; //$NON-NLS-1$
- }
- return getFullName().substring(0, prntIdx);
- }
-
- /**
* Return the extension properties for this record - may be null
* if {@link #setProperties(LinkedHashMap)} or {@link #setProperty(String, String)}
* has not been called
@@ -141,7 +130,6 @@
* Compare two records for equality.
*/
public boolean equals(Object obj) {
-
if(obj == this) {
return true;
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ColumnRecordImpl.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ColumnRecordImpl.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ColumnRecordImpl.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -237,16 +237,4 @@
this.nativeType = nativeType;
}
- public String toString() {
- StringBuffer sb = new StringBuffer(100);
- sb.append(getClass().getSimpleName());
- sb.append(" name="); //$NON-NLS-1$
- sb.append(getName());
- sb.append(", nameInSource="); //$NON-NLS-1$
- sb.append(getNameInSource());
- sb.append(", uuid="); //$NON-NLS-1$
- sb.append(getUUID());
- return sb.toString();
- }
-
}
\ No newline at end of file
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/DatatypeRecordImpl.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/DatatypeRecordImpl.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/DatatypeRecordImpl.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -67,19 +67,6 @@
private String primitiveTypeID;
private Variety varietyType;
- public String getName() {
- final String fullName = super.getName();
- int indx = fullName.lastIndexOf(URI_REFERENCE_DELIMITER);
- if (indx > -1) {
- return fullName.substring(indx+1);
- }
- indx = fullName.lastIndexOf(AbstractMetadataRecord.NAME_DELIM_CHAR);
- if (indx > -1) {
- return fullName.substring(indx+1);
- }
- return fullName;
- }
-
public int getLength() {
return this.length;
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ModelRecordImpl.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ModelRecordImpl.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/ModelRecordImpl.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -88,16 +88,4 @@
modelType = i;
}
- public String toString() {
- StringBuffer sb = new StringBuffer(100);
- sb.append(getClass().getSimpleName());
- sb.append(" name="); //$NON-NLS-1$
- sb.append(getName());
- sb.append(", nameInSource="); //$NON-NLS-1$
- sb.append(getNameInSource());
- sb.append(", uuid="); //$NON-NLS-1$
- sb.append(getUUID());
- return sb.toString();
- }
-
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -42,8 +42,6 @@
private int cardinality;
private Type tableType;
- private String materializedTableID;
- private String materializedStageTableID;
private boolean isVirtual;
private boolean isSystem;
private boolean isMaterialized;
@@ -59,8 +57,8 @@
private String insertPlan;
private String updatePlan;
private String deletePlan;
- private String materializedStageTableName;
- private String materializedTableName;
+ private TableRecordImpl materializedStageTable;
+ private TableRecordImpl materializedTable;
//XML specific
private List<String> bindings;
@@ -110,14 +108,6 @@
return tableType;
}
- public String getMaterializedStageTableID() {
- return this.materializedStageTableID;
- }
-
- public String getMaterializedTableID() {
- return this.materializedTableID;
- }
-
public boolean supportsUpdate() {
return supportsUpdate;
}
@@ -165,22 +155,6 @@
isSystem = b;
}
- /**
- * @param materializedStageTableID The materializedStageTableID to set.
- * @since 4.2
- */
- public void setMaterializedStageTableID(String materializedStageTableID) {
- this.materializedStageTableID = materializedStageTableID;
- }
-
- /**
- * @param materializedTableID The materializedTableID to set.
- * @since 4.2
- */
- public void setMaterializedTableID(String materializedTableID) {
- this.materializedTableID = materializedTableID;
- }
-
public String getInsertPlan() {
return insertPlan;
}
@@ -253,20 +227,20 @@
this.selectTransformation = selectTransformation;
}
- public String getMaterializedStageTableName() {
- return this.materializedStageTableName;
- }
+ public TableRecordImpl getMaterializedStageTable() {
+ return materializedStageTable;
+ }
- public String getMaterializedTableName() {
- return this.materializedTableName;
- }
+ public TableRecordImpl getMaterializedTable() {
+ return materializedTable;
+ }
- public void setMaterializedStageTableName(String materializedStageTableName) {
- this.materializedStageTableName = materializedStageTableName;
+ public void setMaterializedStageTable(TableRecordImpl materializedStageTable) {
+ this.materializedStageTable = materializedStageTable;
}
- public void setMaterializedTableName(String materializedTableName) {
- this.materializedTableName = materializedTableName;
+ public void setMaterializedTable(TableRecordImpl materializedTable) {
+ this.materializedTable = materializedTable;
}
public void setResourcePath(String resourcePath) {
@@ -289,16 +263,4 @@
return keys;
}
- public String toString() {
- StringBuffer sb = new StringBuffer(100);
- sb.append(getClass().getSimpleName());
- sb.append(" name="); //$NON-NLS-1$
- sb.append(getName());
- sb.append(", nameInSource="); //$NON-NLS-1$
- sb.append(getNameInSource());
- sb.append(", uuid="); //$NON-NLS-1$
- sb.append(getUUID());
- return sb.toString();
- }
-
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferConfig.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferConfig.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferConfig.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -32,7 +32,8 @@
*/
public class BufferConfig {
- public static int DEFAULT_CONNECTOR_BATCH_SIZE = 1000;
+ public static int DEFAULT_CONNECTOR_BATCH_SIZE = 2000;
+ public static int DEFAULT_PROCESSOR_BATCH_SIZE = 2000;
// Configuration
private long totalAvailableMemory = 100000000;
@@ -40,8 +41,7 @@
private int activeMemoryThreshold = 75;
private int managementInterval = 500;
private int connectorBatchSize = DEFAULT_CONNECTOR_BATCH_SIZE;
- //private int processorBatchSize = 500;
- private int processorBatchSize = 100;
+ private int processorBatchSize = DEFAULT_PROCESSOR_BATCH_SIZE;
private String bufferStorageDirectory = "../buffer"; //$NON-NLS-1$
private int logStatInterval = 0;
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -54,6 +54,8 @@
*/
public URL getSystemVdb();
+ public File getWorkDir();
+
/**
* Get DQP properties
* @return Properties - properties
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/batch/BatchedUpdatePlanner.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/batch/BatchedUpdatePlanner.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/batch/BatchedUpdatePlanner.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -40,6 +40,7 @@
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
import com.metamatrix.query.optimizer.relational.RelationalPlanner;
+import com.metamatrix.query.optimizer.relational.rules.CapabilitiesUtil;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.batch.BatchedUpdatePlan;
import com.metamatrix.query.processor.relational.BatchedUpdateNode;
@@ -138,7 +139,7 @@
batchLoop: for (int batchIndex = commandIndex+1; batchIndex <
numCommands; batchIndex++) {
Command batchingCandidate =
(Command)updateCommands.get(batchIndex);
// If this command updates the same model, and is eligible for
batching, add it to the batch
- if (canBeAddedToBatch(batchingCandidate, batchModelID, metadata))
{
+ if (canBeAddedToBatch(batchingCandidate, batchModelID, metadata,
capFinder)) {
batch.add(batchingCandidate);
if (allContexts != null) {
contexts.add(allContexts.get(batchIndex));
@@ -222,20 +223,18 @@
* @param command an update command
* @param batchModelID the model ID for the batch concerned
* @param metadata
+ * @param capFinder
* @return true if this command can be place in a batch associated with the model ID;
false otherwise
* @throws QueryMetadataException
* @throws MetaMatrixComponentException
* @since 4.2
*/
- private static boolean canBeAddedToBatch(Command command, Object batchModelID,
QueryMetadataInterface metadata) throws QueryMetadataException,
MetaMatrixComponentException {
+ private static boolean canBeAddedToBatch(Command command, Object batchModelID,
QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws
QueryMetadataException, MetaMatrixComponentException {
// If it's eligible ...
if (isEligibleForBatching(command, metadata)) {
Object modelID =
metadata.getModelID(getUpdatedGroup(command).getMetadataID());
- // ... and it updates a group in the same model ...
- if (modelID.equals(batchModelID)) {
- // ... then it can be added to the batch.
- return true;
- }
+
+ return CapabilitiesUtil.isSameConnector(modelID, batchModelID, metadata,
capFinder);
}
return false;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -36,6 +36,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.common.buffer.impl.BufferConfig;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.QueryPlugin;
@@ -78,11 +79,6 @@
public static final float UNKNOWN_VALUE = -1;
- // These batch size should generally not be used as they should be retrieved from the
- // command context, however they might be used in test scenarios where that is
undefined
- static final int DEFAULT_PROCESSOR_BATCH_SIZE = 2000;
- static final int DEFAULT_CONNECTOR_BATCH_SIZE = 2000;
-
// the following variables are used to hold cost estimates (roughly in milliseconds)
private final static float compareTime = .05f; //TODO: a better estimate would be
based upon the number of conjuncts
private final static float readTime = .001f; //TODO: should come from the connector
@@ -908,7 +904,7 @@
float numberComparisons = merge?(leftChildCardinality +
rightChildCardinality):(leftChildCardinality * rightChildCardinality);
- float connectorBatchSize = DEFAULT_CONNECTOR_BATCH_SIZE;
+ float connectorBatchSize = BufferConfig.DEFAULT_CONNECTOR_BATCH_SIZE;
if(context != null) {
connectorBatchSize = context.getConnectorBatchSize();
}
@@ -969,8 +965,8 @@
return UNKNOWN_VALUE;
}
- float connectorBatchSize = DEFAULT_CONNECTOR_BATCH_SIZE;
- float processorBatchSize = DEFAULT_PROCESSOR_BATCH_SIZE;
+ float connectorBatchSize = BufferConfig.DEFAULT_CONNECTOR_BATCH_SIZE;
+ float processorBatchSize = BufferConfig.DEFAULT_PROCESSOR_BATCH_SIZE;
if(context != null) {
connectorBatchSize = context.getConnectorBatchSize();
processorBatchSize = context.getProcessorBatchSize();
Modified: trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -36,8 +36,8 @@
// This gets set according to the current clause
public boolean aggregatesAllowed = false;
- // treat a double quoted variable as variable insted of string
- public boolean allowDoubleQuotedVariable=false;
+ // treat a double quoted variable as variable instead of string
+ public boolean allowDoubleQuotedVariable=true;
public ParseInfo() { }
Modified: trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -225,7 +225,6 @@
Object[] params = new Object[] { id };
throw new
ParseException(QueryPlugin.Util.getString("SQLParser.Invalid_id", params));
//$NON-NLS-1$
}
- id = id.replace('/', '.');
id = id.replaceAll("\"", ""); //$NON-NLS-1$
//$NON-NLS-2$
return id;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -30,6 +30,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryProcessingException;
+import com.metamatrix.common.buffer.impl.BufferConfig;
import com.metamatrix.core.util.ArgCheck;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.eval.SecurityFunctionEvaluator;
@@ -54,9 +55,9 @@
/** Identify a group of related commands, which typically get cleaned up together */
private String connectionID;
- private int processorBatchSize = 2000;
+ private int processorBatchSize = BufferConfig.DEFAULT_PROCESSOR_BATCH_SIZE;
- private int connectorBatchSize = 2000;
+ private int connectorBatchSize = BufferConfig.DEFAULT_CONNECTOR_BATCH_SIZE;
private String userName;
Modified: trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -131,7 +131,6 @@
*/
public ColumnRecordImpl findElement(String elementName) throws QueryMetadataException {
- ColumnRecordImpl result = null;
if (StringUtil.startsWithIgnoreCase(elementName,UUID.PROTOCOL)) {
for (MetadataStore store : this.metadataStores) {
for (TableRecordImpl table : store.getTables().values()) {
@@ -154,10 +153,7 @@
}
}
}
- if (result == null) {
- throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
- }
- return result;
+ throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
}
public Collection<TableRecordImpl> getXMLTempGroups(TableRecordImpl tableRecord)
throws QueryMetadataException {
Modified: trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -225,10 +225,10 @@
public Object getGroupIDForElementID(final Object elementID) throws
MetaMatrixComponentException, QueryMetadataException {
if(elementID instanceof ColumnRecordImpl) {
ColumnRecordImpl columnRecord = (ColumnRecordImpl) elementID;
- return this.getGroupID(columnRecord.getParentFullName());
+ return this.getGroupID(getGroupName(columnRecord.getFullName()));
} else if(elementID instanceof ProcedureParameterRecordImpl){
ProcedureParameterRecordImpl columnRecord = (ProcedureParameterRecordImpl)
elementID;
- return this.getGroupID(columnRecord.getParentFullName());
+ return this.getGroupID(getGroupName(columnRecord.getFullName()));
} else {
throw createInvalidRecordTypeException(elementID);
}
@@ -675,7 +675,7 @@
ArgCheck.isInstanceOf(TableRecordImpl.class, groupID);
TableRecordImpl tableRecord = (TableRecordImpl) groupID;
if(tableRecord.isMaterialized()) {
- return this.getGroupID(tableRecord.getMaterializedTableName());
+ return tableRecord.getMaterializedTable();
}
return null;
}
@@ -689,7 +689,7 @@
ArgCheck.isInstanceOf(TableRecordImpl.class, groupID);
TableRecordImpl tableRecord = (TableRecordImpl) groupID;
if(tableRecord.isMaterialized()) {
- return this.getGroupID(tableRecord.getMaterializedStageTableName());
+ return tableRecord.getMaterializedStageTable();
}
return null;
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -802,17 +802,17 @@
}
public void testInsert() {
- helpPlan("Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values
(\"MyString\", 1)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ helpPlan("Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values
('MyString', 1)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] { "INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES
('MyString', 1)"} ); //$NON-NLS-1$
}
public void testUpdate1() {
- helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM(\"MyString\"),
pm1.g1.e2= 1 where pm1.g1.e3= \"true\"",
FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM('MyString'), pm1.g1.e2=
1 where pm1.g1.e3= 'true'", FakeMetadataFactory.example1Cached(),
//$NON-NLS-1$
new String[] { "UPDATE pm1.g1 SET pm1.g1.e1 = 'MyString', pm1.g1.e2 = 1
WHERE pm1.g1.e3 = TRUE"} ); //$NON-NLS-1$
}
public void testUpdate2() {
- helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM(\"MyString\"),
pm1.g1.e2= 1 where pm1.g1.e2= convert(pm1.g1.e4, integer)",
FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM('MyString'), pm1.g1.e2=
1 where pm1.g1.e2= convert(pm1.g1.e4, integer)",
FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] { "UPDATE pm1.g1 SET pm1.g1.e1 = 'MyString', pm1.g1.e2 = 1
WHERE pm1.g1.e2 = convert(pm1.g1.e4, integer)"} ); //$NON-NLS-1$
}
@@ -3639,7 +3639,7 @@
ProcessorPlan plan = helpPlan(
"SELECT VDBName PKVDB, PKGroupFullName, PKElementName, VDBName
FKVDB,FKGroupFullName, FKElementName, convert(FKPosition, short) As FKPosition, FKKeyName,
PKKeyName " + //$NON-NLS-1$
- "FROM System.ReferenceKeyElements WHERE PKKeyType = 'Primary'
AND FKKeyType = 'Foreign' AND FKGroupFullName =
\"PartsOracle.SUPPLIER_PARTS\"", //$NON-NLS-1$
+ "FROM System.ReferenceKeyElements WHERE PKKeyType = 'Primary'
AND FKKeyType = 'Foreign' AND FKGroupFullName =
'PartsOracle.SUPPLIER_PARTS'", //$NON-NLS-1$
FakeMetadataFactory.exampleSystemPhysical(),
null, capFinder,
new String[] {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -138,7 +138,7 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1=\"false\" and
INPUT.e1=1)\n"; //$NON-NLS-1$
+ procedure = procedure + "if(CHANGING.e1='false' and
INPUT.e1=1)\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select pm1.g1.e2, Input.e2 from pm1.g1;\n";
//$NON-NLS-1$
procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 =
INPUT.e2;\n"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -2070,15 +2070,15 @@
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
select.addSymbol(a);
- Expression constant = new Constant("value"); //$NON-NLS-1$
- Criteria crit = new CompareCriteria(a, CompareCriteria.NE, constant);
+ Expression ex = new ElementSymbol("value"); //$NON-NLS-1$
+ Criteria crit = new CompareCriteria(a, CompareCriteria.NE, ex);
Query query = new Query();
query.setSelect(select);
query.setFrom(from);
query.setCriteria(crit);
helpTest("SELECT a from db.g where a <> \"value\"",
//$NON-NLS-1$
- "SELECT a FROM db.g WHERE a <> 'value'", //$NON-NLS-1$
+ "SELECT a FROM db.g WHERE a <> value", //$NON-NLS-1$
query);
}
@@ -2099,7 +2099,7 @@
query.setSelect(select);
query.setFrom(from);
query.setCriteria(crit);
- helpTest("SELECT a from db.g where a != \"value\"",
//$NON-NLS-1$
+ helpTest("SELECT a from db.g where a != 'value'",
//$NON-NLS-1$
"SELECT a FROM db.g WHERE a <> 'value'",
//$NON-NLS-1$
query);
}
@@ -5316,7 +5316,7 @@
}
public void testUnicode3() {
- String sql = "SELECT \"\u05e0\""; //$NON-NLS-1$
+ String sql = "SELECT '\u05e0'"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -6461,54 +6461,7 @@
"SELECT fooKey AS fooAlias FROM x.y.z", //$NON-NLS-1$
query, info);
}
-
- public void testFullyQualifiedElementWithSlashes() throws Exception {
- GroupSymbol g = new GroupSymbol("x.y.z"); //$NON-NLS-1$
- From from = new From();
- from.addGroup(g);
-
- Select select = new Select();
- select.addSymbol(new ElementSymbol("x.y.z.fooKey")); //$NON-NLS-1$
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
-
- helpTest("SELECT \"x/y\".z.fooKey FROM \"x/y\".z",
//$NON-NLS-1$
- "SELECT x.y.z.fooKey FROM x.y.z", //$NON-NLS-1$
- query);
- }
-
- public void testFullyQualifiedVaribleWithSlashes() throws Exception {
- GroupSymbol g = new GroupSymbol("x.y.z"); //$NON-NLS-1$
- From from = new From();
- from.addGroup(g);
-
- Select select = new Select();
- select.addSymbol(new ElementSymbol("x.y.z.fooKey")); //$NON-NLS-1$
- AliasSymbol alias = new AliasSymbol("key", new
ElementSymbol("x.y.z.key2")); //$NON-NLS-1$ //$NON-NLS-2$
- select.addSymbol(alias);
-
- Criteria crit = new CompareCriteria(new ElementSymbol("x.y.z.fooKey"),
SubqueryCompareCriteria.GT, new Constant(new Integer(10))); //$NON-NLS-1$
-
- OrderBy orderby = new OrderBy();
- orderby.addVariable(new ElementSymbol("x.y.z.fooKey"), true); //$NON-NLS-1$
-
- GroupBy groupby = new GroupBy();
- groupby.addSymbol(new ElementSymbol("key")); //$NON-NLS-1$
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(crit);
- query.setOrderBy(orderby);
- query.setGroupBy(groupby);
-
- helpTest("SELECT x/y.z.fooKey, x/y.z.key2 as 'key' FROM x/y.z where
x/y.z.fooKey > 10 group by key order by x/y.z.fooKey", //$NON-NLS-1$
- "SELECT x.y.z.fooKey, x.y.z.key2 AS key FROM x.y.z WHERE
x.y.z.fooKey > 10 GROUP BY key ORDER BY x.y.z.fooKey", //$NON-NLS-1$
- query);
- }
-
/** QUERY Tool Format*/
public void testQueryWithQuotes_MSQuery() throws Exception {
QueryParser.getQueryParser().parseCommand("SELECT \"PART_COLOR\",
\"PART_ID\", \"PART_NAME\", \"PART_WEIGHT\" FROM
\"VirtualParts/base\".\"Parts\""); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -3989,7 +3989,7 @@
@Test public void testInsert() {
// Create query
- String sql = "Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values
(\"MyString\", 1)"; //$NON-NLS-1$
+ String sql = "Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values
('MyString', 1)"; //$NON-NLS-1$
// Create expected results
List[] expected = new List[] {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/NodeTestUtil.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/NodeTestUtil.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/NodeTestUtil.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -42,12 +42,6 @@
* @since 4.2
*/
public class NodeTestUtil {
- static BufferManager getTestBufferManager(long bytesAvailable) {
- // Get the properties for BufferManager
- Properties bmProps = new Properties();
- bmProps.setProperty(BufferManagerPropertyNames.MEMORY_AVAILABLE, "" +
bytesAvailable); //$NON-NLS-1$
- return createBufferManager(bmProps);
- }
static BufferManager getTestBufferManager(long bytesAvailable, int procBatchSize, int
connectorBatchSize) {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -57,7 +57,7 @@
public static final int INT_BATCH_SIZE = TestSortNode.getIntBatchSize(); //the size
of 100 integers
private void helpTestSort(long bytesInMemory, List elements, List[] data, List
sortElements, List sortTypes, List[] expected, Set blockOn, Mode mode) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
- BufferManager mgr = NodeTestUtil.getTestBufferManager(bytesInMemory);
+ BufferManager mgr = NodeTestUtil.getTestBufferManager(bytesInMemory, BATCH_SIZE,
BATCH_SIZE);
TestableBufferManagerImpl impl = (TestableBufferManagerImpl) mgr;
impl.setBlockOn(blockOn);
impl.getConfig().setTotalAvailableMemory(bytesInMemory);
Modified: trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -1630,7 +1630,7 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1=\"false\" and
INPUT.e1=1)\n"; //$NON-NLS-1$
+ procedure = procedure + "if(CHANGING.e1='false' and
INPUT.e1=1)\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select pm1.g1.e2, Input.e2 from pm1.g1;\n";
//$NON-NLS-1$
procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 =
INPUT.e2;\n"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -833,7 +833,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\",
1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -860,7 +860,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\",
1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -888,7 +888,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\",
1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -911,7 +911,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\",
1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -929,13 +929,13 @@
String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"false\")\n";
//$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = 'false')\n";
//$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select e1 from vm1.g1 where HAS = CRITERIA ON
(vm1.g1.e2);\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 =
10"; //$NON-NLS-1$
+ String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 =
10"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -952,12 +952,12 @@
String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n";
//$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 =
10"; //$NON-NLS-1$
+ String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 =
10"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -974,13 +974,13 @@
String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n";
//$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON
(vm1.g1.e2);\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 =
10"; //$NON-NLS-1$
+ String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 =
10"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -998,13 +998,13 @@
String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n";
//$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON
(vm1.g1.e2) with (vm1.g1.e2 = convert(sqrt(pm1.g1.e2), integer));\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 =
10"; //$NON-NLS-1$
+ String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 =
10"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -1794,7 +1794,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values
(\"String\", 1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
QueryMetadataInterface metadata =
FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.INSERT_PROCEDURE,
procedure);
@@ -1821,7 +1821,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values
(\"String\", 1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
@@ -1843,7 +1843,7 @@
procedure = procedure + "Select count(*) from pm1.g1;\n";
//$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- String userQuery = "Insert into vm1.g1 (e1, e2) values
(\"String\", 1)"; //$NON-NLS-1$
+ String userQuery = "Insert into vm1.g1 (e1, e2) values ('String',
1)"; //$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
Modified:
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -1092,10 +1092,10 @@
QueryNode vspqn59 = new QueryNode("vsp59", "CREATE VIRTUAL
PROCEDURE BEGIN SELECT * INTO #temp FROM pm5.g3;INSERT INTO #temp (e1, e2)
VALUES('integer',1); END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp59 = createVirtualProcedure("pm5.vsp59", pm6,
Arrays.asList(new FakeMetadataObject[] { vspp1 }), vspqn59); //$NON-NLS-1$
- QueryNode vspqn60 = new QueryNode("vsp60", "CREATE VIRTUAL
PROCEDURE BEGIN create local temporary table temp_table (column1 string);insert into
temp_table (column1) values (\"First\");insert into temp_table (column1) values
(\"Second\");insert into temp_table (column1) values
(\"Third\");select * from temp_table; END"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode vspqn60 = new QueryNode("vsp60", "CREATE VIRTUAL
PROCEDURE BEGIN create local temporary table temp_table (column1 string);insert into
temp_table (column1) values ('First');insert into temp_table (column1) values
('Second');insert into temp_table (column1) values ('Third');select * from
temp_table; END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp60 = createVirtualProcedure("pm1.vsp60", pm1,
Arrays.asList(new FakeMetadataObject[] { vspp1 }), vspqn60); //$NON-NLS-1$
- QueryNode vspqn61 = new QueryNode("vsp61", "CREATE VIRTUAL
PROCEDURE BEGIN create local temporary table temp_table (column1 string);insert into
temp_table (column1) values (\"First\");drop table temp_table;create local
temporary table temp_table (column1 string);insert into temp_table (column1) values
(\"First\");insert into temp_table (column1) values
(\"Second\");insert into temp_table (column1) values
(\"Third\");select * from temp_table; END"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode vspqn61 = new QueryNode("vsp61", "CREATE VIRTUAL
PROCEDURE BEGIN create local temporary table temp_table (column1 string);insert into
temp_table (column1) values ('First');drop table temp_table;create local temporary
table temp_table (column1 string);insert into temp_table (column1) values
('First');insert into temp_table (column1) values ('Second');insert into
temp_table (column1) values ('Third');select * from temp_table; END");
//$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp61 = createVirtualProcedure("pm1.vsp61", pm1,
Arrays.asList(new FakeMetadataObject[] { vspp1 }), vspqn61); //$NON-NLS-1$
QueryNode vspqn62 = new QueryNode("vsp62", "CREATE VIRTUAL
PROCEDURE BEGIN create local temporary table temp_table (column1 string); select e1 as
column1 into temp_table from pm1.g1;select * from temp_table; END"); //$NON-NLS-1$
//$NON-NLS-2$
@@ -1920,7 +1920,7 @@
QueryNode vm1g2n1 = new QueryNode("vm1.g2", "SELECT pm1.g2.e1,
pm1.g2.e2, pm1.g2.e3 FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vm1g2 = createUpdatableVirtualGroup("vm1.g2", vm1,
vm1g2n1); //$NON-NLS-1$
- QueryNode vm1g3n1 = new QueryNode("vm1.g3", "SELECT CONCAT(e1,
\"m\") as x, (e2 +1) as y, Count(*) as e3, e4*50 as e4 FROM pm1.g1");
//$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode vm1g3n1 = new QueryNode("vm1.g3", "SELECT CONCAT(e1,
'm') as x, (e2 +1) as y, Count(*) as e3, e4*50 as e4 FROM pm1.g1");
//$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vm1g3 = createUpdatableVirtualGroup("vm1.g3", vm1,
vm1g3n1); //$NON-NLS-1$
QueryNode vm1g4n1 = new QueryNode("vm1.g4", "SELECT * FROM
pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
===================================================================
---
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -62,6 +63,7 @@
private Index[] indexes;
private Map<String, DatatypeRecordImpl> datatypeCache;
private Map<String, KeyRecord> primaryKeyCache = new HashMap<String,
KeyRecord>();
+ private Map<String, TableRecordImpl> tableCache = new HashMap<String,
TableRecordImpl>();
private MetadataStore store = new MetadataStore();
public IndexMetadataFactory(MetadataSource source) throws IOException {
@@ -91,77 +93,93 @@
}
public void getTables() {
- Collection<TableRecordImpl> records =
findMetadataRecords(MetadataConstants.RECORD_TYPE.TABLE, null, false);
- for (TableRecordImpl tableRecord : records) {
- List<ColumnRecordImpl> columns = new
ArrayList<ColumnRecordImpl>(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.COLUMN));
- for (ColumnRecordImpl columnRecordImpl : columns) {
-
columnRecordImpl.setDatatype(getDatatypeCache().get(columnRecordImpl.getDatatypeUUID()));
- }
- Collections.sort(columns);
- tableRecord.setColumns(columns);
- tableRecord.setAccessPatterns(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.ACCESS_PATTERN));
- Map<String, ColumnRecordImpl> uuidColumnMap = new HashMap<String,
ColumnRecordImpl>();
- for (ColumnRecordImpl columnRecordImpl : columns) {
- uuidColumnMap.put(columnRecordImpl.getUUID(), columnRecordImpl);
- }
- for (KeyRecord columnSetRecordImpl : tableRecord.getAccessPatterns()) {
- loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
- columnSetRecordImpl.setTable(tableRecord);
- }
- tableRecord.setForiegnKeys(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.FOREIGN_KEY));
- for (ForeignKeyRecordImpl foreignKeyRecord : tableRecord.getForeignKeys()) {
-
foreignKeyRecord.setPrimaryKey(getPrimaryKey(foreignKeyRecord.getUniqueKeyID()));
- loadColumnSetRecords(foreignKeyRecord, uuidColumnMap);
- foreignKeyRecord.setTable(tableRecord);
- }
- tableRecord.setUniqueKeys(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.UNIQUE_KEY));
- for (KeyRecord columnSetRecordImpl : tableRecord.getUniqueKeys()) {
- loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
- columnSetRecordImpl.setTable(tableRecord);
- }
- tableRecord.setIndexes(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.INDEX));
- for (KeyRecord columnSetRecordImpl : tableRecord.getIndexes()) {
- loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
- columnSetRecordImpl.setTable(tableRecord);
- }
- if (tableRecord.getPrimaryKey() != null) {
- KeyRecord primaryKey = getPrimaryKey(tableRecord.getPrimaryKey().getUUID());
- loadColumnSetRecords(primaryKey, uuidColumnMap);
- primaryKey.setTable(tableRecord);
- tableRecord.setPrimaryKey(primaryKey);
- }
- String groupName = tableRecord.getFullName();
- if (tableRecord.isVirtual()) {
- TransformationRecordImpl update =
(TransformationRecordImpl)getRecordByType(groupName,
MetadataConstants.RECORD_TYPE.UPDATE_TRANSFORM,false);
- if (update != null) {
- tableRecord.setUpdatePlan(update.getTransformation());
+ for (ModelRecordImpl model : store.getModels().values()) {
+ List<TableRecordImpl> records =
findMetadataRecords(MetadataConstants.RECORD_TYPE.TABLE, model.getName() +
IndexConstants.NAME_DELIM_CHAR + IndexConstants.RECORD_STRING.MATCH_CHAR, true);
+ //load non-materialized first, so that the uuid->table cache is populated
+ Collections.sort(records, new Comparator<TableRecordImpl>() {
+ @Override
+ public int compare(TableRecordImpl o1, TableRecordImpl o2) {
+ if (!o1.isMaterialized()) {
+ return -1;
+ }
+ if (!o2.isMaterialized()) {
+ return 1;
+ }
+ return 0;
+ }
+ });
+ for (TableRecordImpl tableRecord : records) {
+ tableCache.put(tableRecord.getUUID(), tableRecord);
+ List<ColumnRecordImpl> columns = new
ArrayList<ColumnRecordImpl>(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.COLUMN));
+ for (ColumnRecordImpl columnRecordImpl : columns) {
+
columnRecordImpl.setDatatype(getDatatypeCache().get(columnRecordImpl.getDatatypeUUID()));
+ }
+ Collections.sort(columns);
+ tableRecord.setColumns(columns);
+ tableRecord.setAccessPatterns(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.ACCESS_PATTERN));
+ Map<String, ColumnRecordImpl> uuidColumnMap = new HashMap<String,
ColumnRecordImpl>();
+ for (ColumnRecordImpl columnRecordImpl : columns) {
+ uuidColumnMap.put(columnRecordImpl.getUUID(), columnRecordImpl);
+ }
+ for (KeyRecord columnSetRecordImpl : tableRecord.getAccessPatterns()) {
+ loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
+ columnSetRecordImpl.setTable(tableRecord);
+ }
+ tableRecord.setForiegnKeys(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.FOREIGN_KEY));
+ for (ForeignKeyRecordImpl foreignKeyRecord : tableRecord.getForeignKeys()) {
+
foreignKeyRecord.setPrimaryKey(getPrimaryKey(foreignKeyRecord.getUniqueKeyID()));
+ loadColumnSetRecords(foreignKeyRecord, uuidColumnMap);
+ foreignKeyRecord.setTable(tableRecord);
+ }
+ tableRecord.setUniqueKeys(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.UNIQUE_KEY));
+ for (KeyRecord columnSetRecordImpl : tableRecord.getUniqueKeys()) {
+ loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
+ columnSetRecordImpl.setTable(tableRecord);
+ }
+ tableRecord.setIndexes(findChildRecords(tableRecord,
MetadataConstants.RECORD_TYPE.INDEX));
+ for (KeyRecord columnSetRecordImpl : tableRecord.getIndexes()) {
+ loadColumnSetRecords(columnSetRecordImpl, uuidColumnMap);
+ columnSetRecordImpl.setTable(tableRecord);
+ }
+ if (tableRecord.getPrimaryKey() != null) {
+ KeyRecord primaryKey = getPrimaryKey(tableRecord.getPrimaryKey().getUUID());
+ loadColumnSetRecords(primaryKey, uuidColumnMap);
+ primaryKey.setTable(tableRecord);
+ tableRecord.setPrimaryKey(primaryKey);
}
- TransformationRecordImpl insert =
(TransformationRecordImpl)getRecordByType(groupName,
MetadataConstants.RECORD_TYPE.INSERT_TRANSFORM,false);
- if (insert != null) {
- tableRecord.setInsertPlan(insert.getTransformation());
+ String groupUUID = tableRecord.getUUID();
+ if (tableRecord.isVirtual()) {
+ TransformationRecordImpl update =
(TransformationRecordImpl)getRecordByType(groupUUID,
MetadataConstants.RECORD_TYPE.UPDATE_TRANSFORM,false);
+ if (update != null) {
+ tableRecord.setUpdatePlan(update.getTransformation());
+ }
+ TransformationRecordImpl insert =
(TransformationRecordImpl)getRecordByType(groupUUID,
MetadataConstants.RECORD_TYPE.INSERT_TRANSFORM,false);
+ if (insert != null) {
+ tableRecord.setInsertPlan(insert.getTransformation());
+ }
+ TransformationRecordImpl delete =
(TransformationRecordImpl)getRecordByType(groupUUID,
MetadataConstants.RECORD_TYPE.DELETE_TRANSFORM,false);
+ if (delete != null) {
+ tableRecord.setDeletePlan(delete.getTransformation());
+ }
+ TransformationRecordImpl select =
(TransformationRecordImpl)getRecordByType(groupUUID,
MetadataConstants.RECORD_TYPE.SELECT_TRANSFORM,false);
+ // this group may be an xml document
+ if(select == null) {
+ select = (TransformationRecordImpl)getRecordByType(groupUUID,
MetadataConstants.RECORD_TYPE.MAPPING_TRANSFORM,false);
+ }
+ if (select != null) {
+ tableRecord.setSelectTransformation(select.getTransformation());
+ tableRecord.setBindings(select.getBindings());
+ tableRecord.setSchemaPaths(select.getSchemaPaths());
+ tableRecord.setResourcePath(select.getResourcePath());
+ }
}
- TransformationRecordImpl delete =
(TransformationRecordImpl)getRecordByType(groupName,
MetadataConstants.RECORD_TYPE.DELETE_TRANSFORM,false);
- if (delete != null) {
- tableRecord.setDeletePlan(delete.getTransformation());
+ if (tableRecord.isMaterialized()) {
+
tableRecord.setMaterializedStageTable(tableCache.get(tableRecord.getMaterializedStageTable().getUUID()));
+
tableRecord.setMaterializedTable(tableCache.get(tableRecord.getMaterializedTable().getUUID()));
}
- TransformationRecordImpl select =
(TransformationRecordImpl)getRecordByType(groupName,
MetadataConstants.RECORD_TYPE.SELECT_TRANSFORM,false);
- // this group may be an xml document
- if(select == null) {
- select = (TransformationRecordImpl)getRecordByType(groupName,
MetadataConstants.RECORD_TYPE.MAPPING_TRANSFORM,false);
- }
- if (select != null) {
- tableRecord.setSelectTransformation(select.getTransformation());
- tableRecord.setBindings(select.getBindings());
- tableRecord.setSchemaPaths(select.getSchemaPaths());
- tableRecord.setResourcePath(select.getResourcePath());
- }
- }
- if (tableRecord.isMaterialized()) {
-
tableRecord.setMaterializedStageTableName(((TableRecordImpl)getRecordByType(tableRecord.getMaterializedStageTableID(),
MetadataConstants.RECORD_TYPE.TABLE)).getFullName());
-
tableRecord.setMaterializedTableName(((TableRecordImpl)getRecordByType(tableRecord.getMaterializedTableID(),
MetadataConstants.RECORD_TYPE.TABLE)).getFullName());
- }
- this.store.addTable(tableRecord);
- }
+ store.addTable(tableRecord);
+ }
+ }
}
private KeyRecord getPrimaryKey(String uuid) {
@@ -215,39 +233,41 @@
}
public void getProcedures() {
- Collection<ProcedureRecordImpl> procedureRecordImpls =
findMetadataRecords(MetadataConstants.RECORD_TYPE.CALLABLE, null, false);
- for (ProcedureRecordImpl procedureRecord : procedureRecordImpls) {
- procedureRecord.setParameters(new
ArrayList<ProcedureParameterRecordImpl>(procedureRecord.getParameterIDs().size()));
-
- // get the parameter metadata info
- for (String paramID : procedureRecord.getParameterIDs()) {
- ProcedureParameterRecordImpl paramRecord = (ProcedureParameterRecordImpl)
this.getRecordByType(paramID, MetadataConstants.RECORD_TYPE.CALLABLE_PARAMETER);
-
paramRecord.setDatatype(getDatatypeCache().get(paramRecord.getDatatypeUUID()));
- procedureRecord.getParameters().add(paramRecord);
- }
-
- String resultID = procedureRecord.getResultSetID();
- if(resultID != null) {
- ColumnSetRecordImpl resultRecord = (ColumnSetRecordImpl)
getRecordByType(resultID, MetadataConstants.RECORD_TYPE.RESULT_SET, false);
- if (resultRecord != null) {
- loadColumnSetRecords(resultRecord, null);
- procedureRecord.setResultSet(resultRecord);
- }
- //it is ok to be null here. it will happen when a
- //virtual stored procedure is created from a
- //physical stored procedrue without a result set
- //TODO: find a better fix for this
- }
-
- // if this is a virtual procedure get the procedure plan
- if(procedureRecord.isVirtual()) {
- TransformationRecordImpl transformRecord =
(TransformationRecordImpl)getRecordByType(procedureRecord.getFullName(),
MetadataConstants.RECORD_TYPE.PROC_TRANSFORM, false);
- if(transformRecord != null) {
- procedureRecord.setQueryPlan(transformRecord.getTransformation());
- }
- }
- this.store.addProcedure(procedureRecord);
- }
+ for (ModelRecordImpl model : store.getModels().values()) {
+ Collection<ProcedureRecordImpl> procedureRecordImpls =
findMetadataRecords(MetadataConstants.RECORD_TYPE.CALLABLE, model.getName() +
IndexConstants.NAME_DELIM_CHAR + IndexConstants.RECORD_STRING.MATCH_CHAR, true);
+ for (ProcedureRecordImpl procedureRecord : procedureRecordImpls) {
+ procedureRecord.setParameters(new
ArrayList<ProcedureParameterRecordImpl>(procedureRecord.getParameterIDs().size()));
+
+ // get the parameter metadata info
+ for (String paramID : procedureRecord.getParameterIDs()) {
+ ProcedureParameterRecordImpl paramRecord = (ProcedureParameterRecordImpl)
this.getRecordByType(paramID, MetadataConstants.RECORD_TYPE.CALLABLE_PARAMETER);
+
paramRecord.setDatatype(getDatatypeCache().get(paramRecord.getDatatypeUUID()));
+ procedureRecord.getParameters().add(paramRecord);
+ }
+
+ String resultID = procedureRecord.getResultSetID();
+ if(resultID != null) {
+ ColumnSetRecordImpl resultRecord = (ColumnSetRecordImpl)
getRecordByType(resultID, MetadataConstants.RECORD_TYPE.RESULT_SET, false);
+ if (resultRecord != null) {
+ loadColumnSetRecords(resultRecord, null);
+ procedureRecord.setResultSet(resultRecord);
+ }
+ //it is ok to be null here. it will happen when a
+ //virtual stored procedure is created from a
+ //physical stored procedure without a result set
+ //TODO: find a better fix for this
+ }
+
+ // if this is a virtual procedure get the procedure plan
+ if(procedureRecord.isVirtual()) {
+ TransformationRecordImpl transformRecord =
(TransformationRecordImpl)getRecordByType(procedureRecord.getUUID(),
MetadataConstants.RECORD_TYPE.PROC_TRANSFORM, false);
+ if(transformRecord != null) {
+ procedureRecord.setQueryPlan(transformRecord.getTransformation());
+ }
+ }
+ store.addProcedure(procedureRecord);
+ }
+ }
}
/**
@@ -277,10 +297,10 @@
}
}
- private Collection findMetadataRecords(final char recordType,
+ private List findMetadataRecords(final char recordType,
final String entityName, final boolean isPartialName) {
IEntryResult[] results = queryIndex(recordType, entityName, isPartialName);
- Collection<AbstractMetadataRecord> records = loadRecords(results);
+ List<AbstractMetadataRecord> records = loadRecords(results);
return records;
}
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java 2009-11-12
19:47:07 UTC (rev 1549)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -438,9 +438,13 @@
if(includeMaterializationFlag(indexVersion)) {
// The next token are the UUIDs for the materialized table ID
- table.setMaterializedTableID((String)tokens.get(tokenIndex++));
+ TableRecordImpl matTable = new TableRecordImpl();
+ matTable.setUUID((String)tokens.get(tokenIndex++));
+ table.setMaterializedTable(matTable);
// The next token are the UUID for the materialized stage table ID
- table.setMaterializedStageTableID((String)tokens.get(tokenIndex++));
+ matTable = new TableRecordImpl();
+ matTable.setUUID((String)tokens.get(tokenIndex++));
+ table.setMaterializedStageTable(matTable);
}
// The next tokens are footer values
@@ -1002,7 +1006,7 @@
* be the order of the arguments in method signature.
*/
private static void setRecordHeaderValues(final AbstractMetadataRecord record, final
String recordType,
- final String upperName, final String
objectID, final String fullName,
+ final String upperName, final String
objectID, String fullName,
final String nameInSource,
final String parentObjectID) {
Modified:
trunk/metadata/src/main/java/org/teiid/metadata/index/TransformationRecordImpl.java
===================================================================
---
trunk/metadata/src/main/java/org/teiid/metadata/index/TransformationRecordImpl.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/metadata/src/main/java/org/teiid/metadata/index/TransformationRecordImpl.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -127,16 +127,4 @@
resourcePath = path;
}
- public String toString() {
- StringBuffer sb = new StringBuffer(100);
- sb.append(getClass().getSimpleName());
- sb.append(" name="); //$NON-NLS-1$
- sb.append(getName());
- sb.append(", nameInSource="); //$NON-NLS-1$
- sb.append(getNameInSource());
- sb.append(", uuid="); //$NON-NLS-1$
- sb.append(getUUID());
- return sb.toString();
- }
-
}
\ No newline at end of file
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBaseDQPService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBaseDQPService.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBaseDQPService.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -22,7 +22,6 @@
package com.metamatrix.dqp.embedded.services;
-import java.util.Collection;
import java.util.Properties;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -30,12 +29,8 @@
import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
-import com.metamatrix.common.vdb.api.VDBArchive;
-import com.metamatrix.common.vdb.api.VDBDefn;
-import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
import com.metamatrix.dqp.service.ConfigurationService;
import com.metamatrix.dqp.service.DQPServiceNames;
-import com.metamatrix.vdb.runtime.VDBKey;
/**
@@ -115,39 +110,4 @@
return started;
}
- protected VDBKey vdbId(VDBArchive vdb) {
- return new VDBKey(vdb.getName(),vdb.getVersion());
- }
-
- protected VDBKey vdbId(String name, String version) {
- return new VDBKey(name, version);
- }
-
- /**
- * checks the validity of the VDB
- * @param vdb
- * @return true if valid; false otherwise.
- */
- protected boolean isValidVDB(VDBArchive vdb) {
-
- // check if vdb has validity errors. If so log it..
- if (vdb.getVDBValidityErrors() != null) {
- String[] errors = vdb.getVDBValidityErrors();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < errors.length; i++) {
- sb.append("-").append(errors[i]).append(";");
//$NON-NLS-1$ //$NON-NLS-2$
- } // for
- DQPEmbeddedPlugin.logError("VDBService.validityErrors", new
Object[] {vdb.getName(), sb}); //$NON-NLS-1$
- return false;
- }
-
- VDBDefn def = vdb.getConfigurationDef();
- Collection models = def.getModels();
- if (models != null && models.isEmpty()) {
- DQPEmbeddedPlugin.logError("VDBService.vdb_missing_models", new
Object[] {vdb.getName(), vdb.getVersion()}); //$NON-NLS-1$
- return false;
- }
-
- return true;
- }
}
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -271,7 +271,7 @@
*/
public VDBArchive getVDB(String vdbName, String vdbVersion)
throws MetaMatrixComponentException {
- return loadedVDBs.get(vdbId(vdbName, vdbVersion));
+ return loadedVDBs.get(new VDBKey(vdbName, vdbVersion));
}
/**
@@ -338,7 +338,7 @@
}
// make sure we match up the connector binding based on user preferences
- URL vdbFile = availableVDBFiles.get(vdbId(srcVdb));
+ URL vdbFile = availableVDBFiles.get(srcVdb.getVDBKey());
if (vdbFile == null) {
vdbFile = getNewVDBLocation(srcVdb);
VDBConfigurationWriter.write(srcVdb, vdbFile);
@@ -352,7 +352,7 @@
private VDBArchive loadVDB(VDBArchive vdb, boolean replaceBindings) throws
MetaMatrixComponentException {
// check if this is a valid VDB
- if (!isValidVDB(vdb)) {
+ if (!vdb.isValid()) {
throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("EmbeddedConfigurationService.invalid_vdb",
vdb.getName())); //$NON-NLS-1$
}
@@ -485,7 +485,7 @@
try {
- URL vdbFile = availableVDBFiles.remove(vdbId(vdb));
+ URL vdbFile = availableVDBFiles.remove(vdb.getVDBKey());
Assertion.isNotNull(vdbFile);
@@ -496,7 +496,7 @@
notifyVDBUnLoad(vdb.getName(), vdb.getVersion());
// remove from local references.
- loadedVDBs.remove(vdbId(vdb));
+ loadedVDBs.remove(vdb.getVDBKey());
VDBDefn def = vdb.getConfigurationDef();
@@ -1128,8 +1128,8 @@
private void deployVDB(URL vdbURL, VDBArchive vdb) {
// add vdb to loaded VDBS
- loadedVDBs.put(vdbId(vdb), vdb);
- availableVDBFiles.put(vdbId(vdb), vdbURL);
+ loadedVDBs.put(vdb.getVDBKey(), vdb);
+ availableVDBFiles.put(vdb.getVDBKey(), vdbURL);
DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.loaded_vdb", new
Object[] {vdbURL}); //$NON-NLS-1$
}
@@ -1338,7 +1338,7 @@
return
Boolean.valueOf(getUserPreferences().getProperty(DQPEmbeddedProperties.DQP_BUFFER_USEDISK,
"true")).booleanValue(); //$NON-NLS-1$
}
- private File getWorkDir() {
+ public File getWorkDir() {
String workDirectory =
getUserPreferences().getProperty(DQPEmbeddedProperties.DQP_WORKDIR);
File workDir = new File(workDirectory);
return workDir;
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -22,39 +22,211 @@
package com.metamatrix.dqp.embedded.services;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.teiid.connector.metadata.runtime.DatatypeRecordImpl;
+import org.teiid.connector.metadata.runtime.MetadataStore;
import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.TransformationMetadata;
+import org.teiid.metadata.index.IndexMetadataFactory;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.application.ApplicationEnvironment;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.vdb.api.VDBArchive;
+import com.metamatrix.core.CoreConstants;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.dqp.DQPPlugin;
import com.metamatrix.dqp.service.ConfigurationService;
import com.metamatrix.dqp.service.DQPServiceNames;
import com.metamatrix.dqp.service.DataService;
import com.metamatrix.dqp.service.MetadataService;
import com.metamatrix.dqp.service.VDBLifeCycleListener;
import com.metamatrix.dqp.service.VDBService;
+import com.metamatrix.dqp.util.LogConstants;
+import com.metamatrix.metadata.runtime.api.MetadataSource;
+import com.metamatrix.vdb.runtime.VDBKey;
/**
* @since 4.3
*/
public class EmbeddedMetadataService extends EmbeddedBaseDQPService implements
MetadataService {
-
- private QueryMetadataCache metadataCache = null;
+
private VDBLifeCycleListener listener = new VDBLifeCycleListener() {
public void loaded(String vdbName, String vdbVersion) {
}
public void unloaded(String vdbName, String vdbVersion) {
- metadataCache.removeFromCache(vdbName, vdbVersion);
+ LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {"QueryMetadataCache
Removing vdb from cache", vdbName, vdbVersion}); //$NON-NLS-1$
+ if(vdbName != null && vdbVersion != null) {
+ final VDBKey vdbID = toVdbID(vdbName, vdbVersion);
+ vdbToQueryMetadata.remove(vdbID);
+ }
}
};
+
+ private static class QueryMetadataHolder {
+ TransformationMetadata qmi;
+ }
+
+ // vdbID to QueryMetadataInterfaceHolder map
+ private Map<VDBKey, QueryMetadataHolder> vdbToQueryMetadata =
Collections.synchronizedMap(new HashMap<VDBKey, QueryMetadataHolder>());
+ // RuntimeIndexSelector for the system vdb
+ private VDBArchive systemVDBSelector;
+ // boolean for the cache being valid
+ private boolean isCacheValid = true;
+ private MetadataStore systemMetadataStore;
+
+ /**
+ * Look up metadata for the given vdbName, version at the given filecontent.
+ * @throws MetaMatrixComponentException
+ */
+ private TransformationMetadata lookupMetadata(final String vdbName, final String
vdbVersion, MetadataSource iss, DataService dataService) throws
MetaMatrixComponentException {
+ assertIsValidCache();
+ VDBKey vdbID = toVdbID(vdbName, vdbVersion);
+ QueryMetadataHolder qmiHolder = null;
+ // Enter a synchronized block to find the holder of a QueryMetadataInterface for
a VDB
+ synchronized(vdbToQueryMetadata) {
+ qmiHolder = vdbToQueryMetadata.get(vdbID);
+ if ( qmiHolder == null ) {
+ qmiHolder = new QueryMetadataHolder();
+ vdbToQueryMetadata.put(vdbID, qmiHolder);
+ }
+ }
+ synchronized (qmiHolder) {
+ if (qmiHolder.qmi == null) {
+ qmiHolder.qmi = loadMetadata(vdbID, iss, dataService);
+ }
+ }
+ return qmiHolder.qmi;
+ }
+
+ private void assertIsValidCache() {
+ if(!this.isCacheValid) {
+ throw new
MetaMatrixRuntimeException(DQPPlugin.Util.getString("QueryMetadataCache.cache_not_valid"));
//$NON-NLS-1$
+ }
+ }
+
+ private TransformationMetadata loadMetadata(final VDBKey vdbID, final MetadataSource
runtimeSelector, DataService dataService) throws MetaMatrixComponentException {
+ // check cache status
+ assertIsValidCache();
+
+ List<MetadataStore> metadataStores = new ArrayList<MetadataStore>();
+ try {
+ metadataStores.add(loadMetadataStore(runtimeSelector));
+ Set<String> modelNames =
runtimeSelector.getConnectorMetadataModelNames();
+ if (!modelNames.isEmpty()) {
+ for (String modelName : modelNames) {
+ MetadataStore connectorMetadata = null;
+ String savedMetadata = "/runtime-inf/" + modelName.toLowerCase() +
".ser"; //$NON-NLS-1$ //$NON-NLS-2$
+ if (runtimeSelector.cacheConnectorMetadata()) {
+ connectorMetadata = loadMetadataStore(runtimeSelector, savedMetadata);
+ }
+ if (connectorMetadata == null) {
+ connectorMetadata = dataService.getConnectorMetadata(vdbID.getName(),
vdbID.getVersion(), modelName, runtimeSelector.getModelInfo(modelName).getProperties());
+ }
+ if (runtimeSelector.cacheConnectorMetadata()) {
+ saveMetadataStore(runtimeSelector, connectorMetadata, savedMetadata);
+ }
+ metadataStores.add(connectorMetadata);
+ }
+ }
+ metadataStores.add(systemMetadataStore);
+ } catch (IOException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ // build a composite selector for the runtimeselectors of this vdb and system
vdb
+ CompositeMetadataStore composite = new CompositeMetadataStore(metadataStores,
runtimeSelector);
+ return new TransformationMetadata(composite);
+ }
+
+ public void updateCostMetadata(String vdbName, String vdbVersion, String modelName)
throws MetaMatrixComponentException {
+ CompositeMetadataStore store = getMetadataObjectSource(vdbName, vdbVersion);
+ //...
+ }
+
+ public void updateCostMetadata(String vdbName, String vdbVersion, String objectName,
String propertyName, String value) {
+
+ }
+
+ private void saveMetadataStore(final MetadataSource runtimeSelector,
+ MetadataStore connectorMetadata, String savedMetadata)
+ throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(connectorMetadata);
+ oos.close();
+ runtimeSelector.saveFile(new ByteArrayInputStream(baos.toByteArray()), savedMetadata);
+ }
+
+ private MetadataStore loadMetadataStore(final MetadataSource vdb) throws IOException {
+ String savedMetadata = "/runtime-inf/" + vdb.getName().toLowerCase() +
".vdb.ser"; //$NON-NLS-1$ //$NON-NLS-2$
+ MetadataStore store = loadMetadataStore(vdb, savedMetadata);
+ if (store == null) {
+ store = new IndexMetadataFactory(vdb).getMetadataStore();
+ saveMetadataStore(vdb, store, savedMetadata);
+ }
+ return store;
+ }
+
+ private MetadataStore loadMetadataStore(final MetadataSource runtimeSelector, String
savedMetadata) throws IOException {
+ File f = runtimeSelector.getFile(savedMetadata);
+ if (f != null) {
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream(new FileInputStream(f));
+ return (MetadataStore)ois.readObject();
+ } catch (Exception e) {
+
+ } finally {
+ if (ois != null) {
+ ois.close();
+ }
+ }
+ }
+ return null;
+ }
+
+ public Map<String, DatatypeRecordImpl> getBuiltinDatatypes() {
+ Collection<DatatypeRecordImpl> datatypes =
this.systemMetadataStore.getDatatypes();
+ Map<String, DatatypeRecordImpl> datatypeMap = new HashMap<String,
DatatypeRecordImpl>();
+ for (Class<?> typeClass : DataTypeManager.getAllDataTypeClasses()) {
+ for (DatatypeRecordImpl datatypeRecordImpl : datatypes) {
+ if (datatypeRecordImpl.getJavaClassName().equals(typeClass.getName())) {
+ datatypeMap.put(DataTypeManager.getDataTypeName(typeClass), datatypeRecordImpl);
+ break;
+ }
+ }
+ }
+ return datatypeMap;
+ }
+
+ /**
+ * Return unique id for a vdb
+ */
+ private VDBKey toVdbID(final String vdbName, final String vdbVersion) {
+ return new VDBKey(vdbName, vdbVersion);
+ }
+
+
/**
* @see
com.metamatrix.dqp.embedded.services.EmbeddedBaseDQPService#initializeService(java.util.Properties)
* @since 4.3
@@ -69,10 +241,11 @@
public void startService(ApplicationEnvironment environment) throws
ApplicationLifecycleException {
try {
ConfigurationService configSvc = this.getConfigurationService();
- this.metadataCache = new QueryMetadataCache(configSvc.getSystemVdb());
+ this.systemVDBSelector = VDBArchive.loadVDB(configSvc.getSystemVdb(),
configSvc.getWorkDir());
+ this.systemMetadataStore = loadMetadataStore(this.systemVDBSelector);
configSvc.register(listener);
- } catch (MetaMatrixComponentException e) {
- throw new ApplicationLifecycleException(e);
+ } catch (IOException e) {
+ throw new ApplicationLifecycleException(e,
DQPPlugin.Util.getString("QueryMetadataCache.Failed_creating_Runtime_Index_Selector._4",
CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
}
}
@@ -82,7 +255,17 @@
*/
public void stopService() throws ApplicationLifecycleException {
getConfigurationService().unregister(this.listener);
- this.metadataCache.clearCache();
+ LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {"QueryMetadataCache
Clearing VDB cache"}); //$NON-NLS-1$
+ // mark cache invalid
+ isCacheValid = false;
+ // Clear the holders ...
+ vdbToQueryMetadata.clear();
+
+ // Clean up the directory for the System VDB ...
+ if (this.systemVDBSelector != null) {
+ // selector should no longer be used
+ this.systemVDBSelector.close();
+ }
}
/**
@@ -93,7 +276,7 @@
throws MetaMatrixComponentException {
VDBService vdbService = ((VDBService)lookupService(DQPServiceNames.VDB_SERVICE));
DataService dataService =
((DataService)lookupService(DQPServiceNames.DATA_SERVICE));
- return this.metadataCache.lookupMetadata(vdbName, vdbVersion,
vdbService.getVDB(vdbName, vdbVersion), dataService);
+ return lookupMetadata(vdbName, vdbVersion, vdbService.getVDB(vdbName, vdbVersion),
dataService);
}
@@ -101,10 +284,4 @@
return lookupMetadata(vdbName, vdbVersion).getMetadataStore();
}
- @Override
- public Map<String, DatatypeRecordImpl> getBuiltinDatatypes()
- throws MetaMatrixComponentException {
- return this.metadataCache.getBuiltinDatatypes();
- }
-
}
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -243,20 +243,22 @@
if (status != currentStatus) {
// Change the VDB's status
- if (currentStatus != VDBStatus.ACTIVE
- && (status == VDBStatus.ACTIVE || status ==
VDBStatus.ACTIVE_DEFAULT) ) {
- if (!isValidVDB(vdb) ||
!getConfigurationService().isFullyConfiguredVDB(vdb)) {
+ if (status == VDBStatus.ACTIVE || status == VDBStatus.ACTIVE_DEFAULT) {
+ if (!vdb.isValid()) {
+ throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("EmbeddedConfigurationService.invalid_vdb",
vdb.getName())); //$NON-NLS-1$
+ }
+ if (!getConfigurationService().isFullyConfiguredVDB(vdb)) {
throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("VDBService.vdb_missing_bindings",
new Object[] {vdb.getName(), vdb.getVersion()})); //$NON-NLS-1$
}
+ if (status == VDBStatus.ACTIVE_DEFAULT) {
+ //only 1 can be set as active default
+ VDBArchive latestActive = getVDB(vdbName, null);
+ if (latestActive.getStatus() == VDBStatus.ACTIVE_DEFAULT) {
+ latestActive.setStatus(VDBStatus.ACTIVE);
+ getConfigurationService().saveVDB(latestActive,
latestActive.getVersion());
+ }
+ }
}
- if (status == VDBStatus.ACTIVE_DEFAULT) {
- //only 1 can be set as active default
- VDBArchive latestActive = getVDB(vdbName, null);
- if (latestActive.getStatus() == VDBStatus.ACTIVE_DEFAULT) {
- latestActive.setStatus(VDBStatus.ACTIVE);
- getConfigurationService().saveVDB(latestActive,
latestActive.getVersion());
- }
- }
vdb.setStatus((short)status);
// make sure we got what we asked for
Deleted:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/QueryMetadataCache.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/QueryMetadataCache.java 2009-11-12
19:47:07 UTC (rev 1549)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/QueryMetadataCache.java 2009-11-16
02:17:12 UTC (rev 1550)
@@ -1,225 +0,0 @@
-/*
- * 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 com.metamatrix.dqp.embedded.services;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.teiid.connector.metadata.runtime.DatatypeRecordImpl;
-import org.teiid.connector.metadata.runtime.MetadataStore;
-import org.teiid.metadata.CompositeMetadataStore;
-import org.teiid.metadata.TransformationMetadata;
-import org.teiid.metadata.index.IndexMetadataFactory;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.vdb.api.VDBArchive;
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.dqp.DQPPlugin;
-import com.metamatrix.dqp.service.DataService;
-import com.metamatrix.dqp.util.LogConstants;
-import com.metamatrix.metadata.runtime.api.MetadataSource;
-import com.metamatrix.vdb.runtime.VDBKey;
-
-
-/**
- * This caches QueryMetadataInterface implementations for all vdbs, each implementation
has access to
- * metadata for a given vdb and the system vdb.
- * @since 4.2
- */
-public class QueryMetadataCache {
-
- private static class QueryMetadataHolder {
- TransformationMetadata qmi;
- }
-
- // vdbID to QueryMetadataInterfaceHolder map
- private Map<VDBKey, QueryMetadataHolder> vdbToQueryMetadata =
Collections.synchronizedMap(new HashMap<VDBKey, QueryMetadataHolder>());
- // RuntimeIndexSelector for the system vdb
- private final VDBArchive systemVDBSelector;
-
- // boolean for the cache being valid
- private boolean isCacheValid = true;
- private MetadataStore systemMetadataStore;
-
- /**
- * Constructor given a URL to a system vdb.
- * @since 4.2
- */
- public QueryMetadataCache(final URL systemVdbUrl) throws MetaMatrixComponentException
{
- try {
- this.systemVDBSelector = new VDBArchive(systemVdbUrl.openStream());
- this.systemMetadataStore = new
IndexMetadataFactory(this.systemVDBSelector).getMetadataStore();
- } catch(IOException e) {
- throw new MetaMatrixComponentException(e,
DQPPlugin.Util.getString("QueryMetadataCache.Failed_creating_Runtime_Index_Selector._4",
CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
- }
- }
-
- /**
- * Look up metadata for the given vdbName, version at the given filecontent.
- * @throws MetaMatrixComponentException
- */
- public TransformationMetadata lookupMetadata(final String vdbName, final String
vdbVersion, MetadataSource iss, DataService dataService) throws
MetaMatrixComponentException {
- assertIsValidCache();
- VDBKey vdbID = toVdbID(vdbName, vdbVersion);
- QueryMetadataHolder qmiHolder = null;
- // Enter a synchronized block to find the holder of a QueryMetadataInterface for
a VDB
- synchronized(vdbToQueryMetadata) {
- qmiHolder = vdbToQueryMetadata.get(vdbID);
- if ( qmiHolder == null ) {
- qmiHolder = new QueryMetadataHolder();
- vdbToQueryMetadata.put(vdbID, qmiHolder);
- }
- }
- synchronized (qmiHolder) {
- if (qmiHolder.qmi == null) {
- qmiHolder.qmi = loadMetadata(vdbID, iss, dataService);
- }
- }
- return qmiHolder.qmi;
- }
-
- private void assertIsValidCache() {
- if(!this.isCacheValid) {
- throw new
MetaMatrixRuntimeException(DQPPlugin.Util.getString("QueryMetadataCache.cache_not_valid"));
//$NON-NLS-1$
- }
- }
-
- private TransformationMetadata loadMetadata(final VDBKey vdbID, final MetadataSource
runtimeSelector, DataService dataService) throws MetaMatrixComponentException {
- // check cache status
- assertIsValidCache();
-
- List<MetadataStore> metadataStores = new ArrayList<MetadataStore>();
- try {
- metadataStores.add(new IndexMetadataFactory(runtimeSelector).getMetadataStore());
- Set<String> modelNames =
runtimeSelector.getConnectorMetadataModelNames();
- if (!modelNames.isEmpty()) {
- for (String modelName : modelNames) {
- MetadataStore connectorMetadata = null;
- String savedMetadata = "/META-INF/" + modelName.toLowerCase() +
".ser"; //$NON-NLS-1$ //$NON-NLS-2$
- if (runtimeSelector.cacheConnectorMetadata()) {
- File f = runtimeSelector.getFile(savedMetadata);
- if (f != null) {
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(new FileInputStream(f));
- connectorMetadata = (MetadataStore)ois.readObject();
- } catch (Exception e) {
-
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
- }
- if (connectorMetadata == null) {
- connectorMetadata = dataService.getConnectorMetadata(vdbID.getName(),
vdbID.getVersion(), modelName, runtimeSelector.getModelInfo(modelName).getProperties());
- }
- if (runtimeSelector.cacheConnectorMetadata()) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(connectorMetadata);
- oos.close();
- runtimeSelector.saveFile(new ByteArrayInputStream(baos.toByteArray()),
savedMetadata);
- }
- metadataStores.add(connectorMetadata);
- }
- }
- metadataStores.add(systemMetadataStore);
- } catch (IOException e) {
- throw new MetaMatrixComponentException(e);
- }
- // build a composite selector for the runtimeselectors of this vdb and system
vdb
- CompositeMetadataStore composite = new CompositeMetadataStore(metadataStores,
runtimeSelector);
- return new TransformationMetadata(composite);
- }
-
- public Map<String, DatatypeRecordImpl> getBuiltinDatatypes() {
- Collection<DatatypeRecordImpl> datatypes =
this.systemMetadataStore.getDatatypes();
- Map<String, DatatypeRecordImpl> datatypeMap = new HashMap<String,
DatatypeRecordImpl>();
- for (Class<?> typeClass : DataTypeManager.getAllDataTypeClasses()) {
- for (DatatypeRecordImpl datatypeRecordImpl : datatypes) {
- if (datatypeRecordImpl.getJavaClassName().equals(typeClass.getName())) {
- datatypeMap.put(DataTypeManager.getDataTypeName(typeClass), datatypeRecordImpl);
- break;
- }
- }
- }
- return datatypeMap;
- }
-
- /**
- * Clears all state on this cache and also deletes any indexfiles
- * associated with the cache.
- * @since 4.2
- */
- public void clearCache() {
- LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {"QueryMetadataCache
Clearing VDB cache"}); //$NON-NLS-1$
- // mark cache invalid
- isCacheValid = false;
- // Clear the holders ...
- vdbToQueryMetadata.clear();
-
- // Clean up the directory for the System VDB ...
- if (this.systemVDBSelector != null) {
- // selector should no longer be used
- this.systemVDBSelector.close();
- }
- }
-
- /**
- * Remove cache for a given vdb, called when a vdb is actually deleted.
- * Also deletes any temp files associated with the vdb.
- */
- public void removeFromCache(final String vdbName, final String vdbVersion) {
- LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {"QueryMetadataCache
Removing vdb from cache", vdbName, vdbVersion}); //$NON-NLS-1$
- if(vdbName != null && vdbVersion != null) {
- final VDBKey vdbID = toVdbID(vdbName, vdbVersion);
- vdbToQueryMetadata.remove(vdbID);
- }
- }
-
- /**
- * Return unique id for a vdb
- */
- private VDBKey toVdbID(final String vdbName, final String vdbVersion) {
- return new VDBKey(vdbName, vdbVersion);
- }
-
-}