-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEIIDDES-1739: Refactors the DDL importer
* Separates out the ddl importer into specialised node sub-importers * Node Importers keys against the parser id returned from modeshape * spi plugin provides the node importer registry and extension point
- Loading branch information
Paul Richardson
committed
Jun 10, 2013
1 parent
1165869
commit 65b9194
Showing
28 changed files
with
2,273 additions
and
1,051 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ bin.includes = META-INF/,\ | |
.,\ | ||
OSGI-INF/,\ | ||
OSGI-INF/l10n/,\ | ||
LEGAL.txt | ||
LEGAL.txt,\ | ||
plugin.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.4"?> | ||
<plugin> | ||
<extension | ||
point="org.teiid.designer.ddl.nodeImporter"> | ||
<importer | ||
class="org.teiid.designer.ddl.importer.node.StandardImporter" | ||
dialect="Standard"> | ||
</importer> | ||
<importer | ||
class="org.teiid.designer.ddl.importer.node.OracleImporter" | ||
dialect="Oracle"> | ||
</importer> | ||
<importer | ||
class="org.teiid.designer.ddl.importer.node.DerbyImporter" | ||
dialect="Derby"> | ||
</importer> | ||
<importer | ||
class="org.teiid.designer.ddl.importer.node.PostgresImporter" | ||
dialect="Postgres"> | ||
</importer> | ||
<importer | ||
class="org.teiid.designer.ddl.importer.node.TeiidDdlImporter" | ||
dialect="Teiid"> | ||
</importer> | ||
</extension> | ||
|
||
</plugin> |
1,103 changes: 74 additions & 1,029 deletions
1,103
plugins/org.teiid.designer.ddl.importer/src/org/teiid/designer/ddl/importer/DdlImporter.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...eiid.designer.ddl.importer/src/org/teiid/designer/ddl/importer/node/AbstractImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.designer.ddl.importer.node; | ||
|
||
import org.modeshape.sequencer.ddl.node.AstNode; | ||
import org.teiid.designer.ddl.DdlImporterModel; | ||
import org.teiid.designer.ddl.DdlNodeImporter; | ||
import org.teiid.designer.metamodels.relational.RelationalFactory; | ||
|
||
/** | ||
* | ||
*/ | ||
public abstract class AbstractImporter implements DdlNodeImporter { | ||
|
||
/** | ||
* Entity Not Found Exception | ||
*/ | ||
protected class EntityNotFoundException extends Exception { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* @param message | ||
*/ | ||
public EntityNotFoundException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
private DdlImporterModel importerModel; | ||
|
||
/** | ||
* @param importerModel | ||
*/ | ||
protected void setImporterModel(DdlImporterModel importerModel) { | ||
this.importerModel = importerModel; | ||
} | ||
|
||
/** | ||
* @return the importerModel | ||
*/ | ||
protected DdlImporterModel getImporterModel() { | ||
return this.importerModel; | ||
} | ||
|
||
/** | ||
* @return relational factory | ||
*/ | ||
protected RelationalFactory getFactory() { | ||
return importerModel.getFactory(); | ||
} | ||
|
||
/** | ||
* @param message | ||
*/ | ||
protected void addProgressMessage(String message) { | ||
importerModel.getProgressMessages().add(message); | ||
} | ||
|
||
/** | ||
* Gets boolean value for the provided text string | ||
* | ||
* @param text a text string | ||
* @return 'true' if provided string is "true", otherwise 'false' | ||
*/ | ||
protected boolean isTrue(String text) { | ||
return Boolean.valueOf(text); | ||
} | ||
|
||
/** | ||
* Is given node of the given dialect | ||
* | ||
* @param node | ||
* @param dialectType | ||
* @return true if node has dialect | ||
*/ | ||
protected boolean is(AstNode node, String dialectType) { | ||
return node.hasMixin(dialectType); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...g.teiid.designer.ddl.importer/src/org/teiid/designer/ddl/importer/node/DerbyImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.designer.ddl.importer.node; | ||
|
||
import java.util.List; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.modeshape.sequencer.ddl.StandardDdlLexicon; | ||
import org.modeshape.sequencer.ddl.dialect.derby.DerbyDdlLexicon; | ||
import org.modeshape.sequencer.ddl.node.AstNode; | ||
import org.teiid.designer.metamodels.relational.Column; | ||
import org.teiid.designer.metamodels.relational.Index; | ||
import org.teiid.designer.metamodels.relational.NullableType; | ||
import org.teiid.designer.metamodels.relational.Procedure; | ||
import org.teiid.designer.metamodels.relational.ProcedureParameter; | ||
import org.teiid.designer.metamodels.relational.Schema; | ||
import org.teiid.designer.metamodels.relational.Table; | ||
|
||
/** | ||
* | ||
*/ | ||
public class DerbyImporter extends StandardImporter { | ||
|
||
|
||
@Override | ||
protected Procedure createProcedure(AstNode procedureNode, List<EObject> roots) throws Exception { | ||
Procedure procedure = super.createProcedure(procedureNode, roots); | ||
|
||
for (AstNode child : procedureNode) { | ||
if (! is(child, DerbyDdlLexicon.TYPE_FUNCTION_PARAMETER)) | ||
continue; | ||
|
||
ProcedureParameter prm = getFactory().createProcedureParameter(); | ||
procedure.getParameters().add(prm); | ||
initialize(prm, child); | ||
String datatype = child.getProperty(StandardDdlLexicon.DATATYPE_NAME).toString(); | ||
prm.setNativeType(datatype); | ||
|
||
EObject type = getDataType(datatype); | ||
prm.setType(type); | ||
|
||
Object prop = child.getProperty(StandardDdlLexicon.DATATYPE_LENGTH); | ||
if (prop != null) | ||
prm.setLength(Integer.parseInt(prop.toString())); | ||
|
||
prop = child.getProperty(StandardDdlLexicon.DATATYPE_PRECISION); | ||
if (prop != null) | ||
prm.setPrecision(Integer.parseInt(prop.toString())); | ||
|
||
prop = child.getProperty(StandardDdlLexicon.DATATYPE_SCALE); | ||
if (prop != null) | ||
prm.setScale(Integer.parseInt(prop.toString())); | ||
|
||
prop = child.getProperty(StandardDdlLexicon.NULLABLE); | ||
if (prop != null) | ||
prm.setNullable(prop.toString().equals("NULL") ? NullableType.NULLABLE_LITERAL : NullableType.NO_NULLS_LITERAL); //$NON-NLS-1$ | ||
|
||
prop = child.getProperty(StandardDdlLexicon.DEFAULT_VALUE); | ||
if (prop != null) | ||
prm.setDefaultValue(prop.toString()); | ||
} | ||
|
||
return procedure; | ||
} | ||
|
||
@Override | ||
protected void create(AstNode node, List<EObject> roots, Schema schema) throws Exception { | ||
if (is(node, DerbyDdlLexicon.TYPE_CREATE_INDEX_STATEMENT)) { | ||
Index index = getFactory().createIndex(); | ||
Info info = createInfo(node, roots); | ||
if (info.getSchema() == null) | ||
roots.add(index); | ||
else | ||
info.getSchema().getIndexes().add(index); | ||
|
||
initialize(index, node, info.getName()); | ||
Object prop = node.getProperty(DerbyDdlLexicon.UNIQUE_INDEX); | ||
if (prop != null) | ||
index.setUnique((Boolean) prop); | ||
|
||
prop = node.getProperty(DerbyDdlLexicon.TABLE_NAME); | ||
if (prop == null) | ||
return; | ||
|
||
try { | ||
Table table = find(Table.class, prop.toString(), node, null, roots); | ||
for (AstNode node1 : node) { | ||
// Probably need to check for a simple column reference for Oracle | ||
if (node1.hasMixin(DerbyDdlLexicon.TYPE_INDEX_COLUMN_REFERENCE)) { | ||
try { | ||
index.getColumns().add(find(Column.class, node1, table, roots)); | ||
} catch (EntityNotFoundException error) { | ||
addProgressMessage(error.getMessage()); | ||
} | ||
} | ||
} | ||
} catch (EntityNotFoundException error) { | ||
addProgressMessage(error.getMessage()); | ||
} | ||
} else if (is(node, DerbyDdlLexicon.TYPE_CREATE_PROCEDURE_STATEMENT)) { | ||
createProcedure(node, roots); | ||
} else if (is(node, DerbyDdlLexicon.TYPE_CREATE_FUNCTION_STATEMENT)) { | ||
createProcedure(node, roots).setFunction(true); | ||
} else { | ||
super.create(node, roots, schema); | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...g.teiid.designer.ddl.importer/src/org/teiid/designer/ddl/importer/node/MySQLImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.designer.ddl.importer.node; | ||
|
||
import java.util.List; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.modeshape.sequencer.ddl.dialect.mysql.MySqlDdlLexicon; | ||
import org.modeshape.sequencer.ddl.node.AstNode; | ||
import org.teiid.designer.metamodels.relational.Index; | ||
import org.teiid.designer.metamodels.relational.Schema; | ||
|
||
/** | ||
* | ||
*/ | ||
public class MySQLImporter extends StandardImporter { | ||
|
||
@Override | ||
protected void create(AstNode node, List<EObject> roots, Schema schema) throws Exception { | ||
if (is(node, MySqlDdlLexicon.TYPE_CREATE_INDEX_STATEMENT)) { | ||
Index index = getFactory().createIndex(); | ||
Info info = createInfo(node, roots); | ||
if (info.getSchema() == null) | ||
roots.add(index); | ||
else | ||
info.getSchema().getIndexes().add(index); | ||
|
||
initialize(index, node, info.getName()); | ||
} else if (is(node, MySqlDdlLexicon.TYPE_CREATE_PROCEDURE_STATEMENT)) { | ||
createProcedure(node, roots); | ||
} else if (is(node, MySqlDdlLexicon.TYPE_CREATE_FUNCTION_STATEMENT)) { | ||
createProcedure(node, roots).setFunction(true); | ||
} else | ||
super.create(node, roots, schema); | ||
} | ||
} |
Oops, something went wrong.