use of org.teiid.query.sql.lang.Drop in project teiid by teiid.
the class TempTableResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
if (command.getType() == Command.TYPE_CREATE) {
Create create = (Create) command;
GroupSymbol group = create.getTable();
// assuming that all temp table creates are local, the user must use a local name
if (group.getName().indexOf(Symbol.SEPARATOR) != -1) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30117, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30117, group.getName()));
}
// this will only check non-temp groups
Collection exitsingGroups = metadata.getMetadata().getGroupsForPartialName(group.getName());
if (!exitsingGroups.isEmpty()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
if (metadata.getMetadata().hasProcedure(group.getName())) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
// now we will be more specific for temp groups
TempMetadataID id = metadata.getMetadataStore().getTempGroupID(group.getName());
if (id != null && !metadata.isTemporaryTable(id)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
// if we get here then either the group does not exist or has already been defined as a temp table
// if it has been defined as a temp table, that's ok we'll use this as the new definition and throw an
// exception at runtime if the user has not dropped the previous table yet
TempMetadataID tempTable = ResolverUtil.addTempTable(metadata, group, create.getColumnSymbols());
ResolverUtil.resolveGroup(create.getTable(), metadata);
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(create.getTable());
ResolverVisitor.resolveLanguageObject(command, groups, metadata);
addAdditionalMetadata(create, tempTable);
tempTable.setOriginalMetadataID(create.getTableMetadata());
if (create.getOn() != null) {
Object mid = null;
try {
mid = metadata.getModelID(create.getOn());
} catch (QueryMetadataException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31134, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31134, create.getOn()));
}
if (mid != null && (metadata.isVirtualModel(mid) || !(mid instanceof Schema))) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31135, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31135, create.getOn()));
}
create.getTableMetadata().setParent((Schema) mid);
tempTable.getTableData().setModel(mid);
}
} else if (command.getType() == Command.TYPE_DROP) {
ResolverUtil.resolveGroup(((Drop) command).getTable(), metadata);
}
}
use of org.teiid.query.sql.lang.Drop in project teiid by teiid.
the class TestDrop method testEquivalence.
public void testEquivalence() {
Drop c1 = sample1();
Drop c2 = sample1();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, c1, c2);
}
use of org.teiid.query.sql.lang.Drop in project teiid by teiid.
the class TestDrop method sample1.
// ################################## TEST HELPERS ################################
public static final Drop sample1() {
Drop Drop = new Drop();
// $NON-NLS-1$
Drop.setTable(new GroupSymbol("temp_table"));
List elements = new ArrayList();
// $NON-NLS-1$
elements.add(new ElementSymbol("a"));
// $NON-NLS-1$
elements.add(new ElementSymbol("b"));
return Drop;
}
use of org.teiid.query.sql.lang.Drop in project teiid by teiid.
the class TestDrop method testNonEquivalence.
public void testNonEquivalence() {
Drop c1 = sample1();
Drop c2 = sample2();
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, c1, c2);
}
use of org.teiid.query.sql.lang.Drop in project teiid by teiid.
the class TestCreateDrop method testDropTable.
@Test
public void testDropTable() {
Drop drop = new Drop();
// $NON-NLS-1$
drop.setTable(new GroupSymbol("tempTable"));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("DROP table tempTable", "DROP TABLE tempTable", drop);
}
Aggregations