public ProcedureParameter renameParameter(String oldName, String name, Procedure procedure) { if (this.autoCorrectColumnNames) { name = name.replace(AbstractMetadataRecord.NAME_DELIM_CHAR, '_'); } else if (name.indexOf(AbstractMetadataRecord.NAME_DELIM_CHAR) != -1) { throw new MetadataException(DataPlugin.Event.TEIID60008, DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, procedure.getFullName(), name)); } if (procedure.getParameterByName(name) != null) { throw new DuplicateRecordException(DataPlugin.Event.TEIID60016, DataPlugin.Util.gs(DataPlugin.Event.TEIID60016, procedure.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name)); } ProcedureParameter param = procedure.getParameterByName(oldName); if (param == null) { throw new MetadataException(DataPlugin.Event.TEIID60040, DataPlugin.Util.gs(DataPlugin.Event.TEIID60040, procedure.getFullName(), oldName)); } param.setName(name); return param; }
/** * Add a procedure parameter. * @param name * @param type should be one of {@link TypeFacility.RUNTIME_NAMES} * @param parameterType should be one of {@link ProcedureParameter.Type} * @param procedure * @return * @throws MetadataException */ public ProcedureParameter addProcedureParameter(String name, String type, ProcedureParameter.Type parameterType, Procedure procedure) { ProcedureParameter param = new ProcedureParameter(); if (renameAllDuplicates) { name = checkForDuplicate(name, (s)->procedure.getParameterByName(s) != null, "Parameter"); //$NON-NLS-1$ } param.setName(name); setUUID(param); param.setType(parameterType); param.setProcedure(procedure); setDataType(type, param, this.dataTypes, false); if (parameterType == Type.ReturnValue) { procedure.getParameters().add(0, param); for (int i = 0; i < procedure.getParameters().size(); i++) { procedure.getParameters().get(i).setPosition(i+1); //1 based indexing } } else { procedure.getParameters().add(param); param.setPosition(procedure.getParameters().size()); //1 based indexing } return param; }
@Override public void execute(String name, String nameInSource, Property property, boolean array) { String type = getPropertyType(property, array); if (procedure.getParameterByName(nameInSource) == null) { ProcedureParameter param = mf.addProcedureParameter(name, type, Type.In, procedure); param.setProperty(PARAMETER_TYPE, parameter.getIn()); if (property != null && !property.getRequired()) { param.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT); } param.setNullType(NullType.No_Nulls); param.setAnnotation(property!=null?property.getDescription():null); if (!name.equalsIgnoreCase(nameInSource)) { param.setNameInSource(nameInSource); } } } };
public void removeOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } OptionsUtil.removeOption(c,key); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } OptionsUtil.removeOption(p, key); } else { //exception } }
public void removeOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } OptionsUtil.removeOption(c,key); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } OptionsUtil.removeOption(p, key); } else { //exception } }
public void removeOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } OptionsUtil.removeOption(c,key); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } OptionsUtil.removeOption(p, key); } else { //exception } }
@Test public void testCreateProcedure() throws Exception { String ddl = "CREATE DATABASE FOO;" + "USE DATABASE FOO;" + "CREATE FOREIGN DATA WRAPPER postgresql;" + "CREATE SERVER pgsql TYPE 'custom' FOREIGN DATA WRAPPER postgresql OPTIONS (\"jndi-name\" 'jndiname');" + "CREATE SCHEMA test SERVER pgsql;" + "SET SCHEMA test;" + "CREATE FOREIGN PROCEDURE procG1(P1 integer) RETURNS (e1 integer, e2 varchar)"; Database db = helpParse(ddl); Schema s = db.getSchema("test"); Procedure p = s.getProcedure("procG1"); assertNotNull(p); assertEquals(1, p.getParameters().size()); assertNotNull(p.getParameterByName("P1")); assertEquals(2, p.getResultSet().getColumns().size()); assertEquals("e1", p.getResultSet().getColumns().get(0).getName()); }
public void addOrSetOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key, String value, boolean reload) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } c.setProperty(key, value); OptionsUtil.setOptions(c); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } p.setProperty(key, value); OptionsUtil.setOptions(p); } else { //exception } }
public void addOrSetOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key, String value, boolean reload) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } c.setProperty(key, value); OptionsUtil.setOptions(c); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } p.setProperty(key, value); OptionsUtil.setOptions(p); } else { //exception } }
public void addOrSetOption(String recordName, Database.ResourceType type, String childName, Database.ResourceType childType, String key, String value, boolean reload) { if (!assertInEditMode(Mode.SCHEMA)) { return; } key = getCurrentDatabase().resolveNamespaceInPropertyKey(key); AbstractMetadataRecord record = getSchemaRecord(recordName, type); if (record instanceof Table) { Column c = ((Table)record).getColumnByName(childName); if (c == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31248, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31248, childName, recordName)); } c.setProperty(key, value); OptionsUtil.setOptions(c); } else if (record instanceof Procedure) { ProcedureParameter p = ((Procedure)record).getParameterByName(childName); if (p == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31249, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31249, childName, recordName)); } p.setProperty(key, value); OptionsUtil.setOptions(p); } else { //exception } }
public void alterBaseColumn(String objectName, Database.ResourceType type, String childName, ParsedDataType datatype, boolean autoIncrement, boolean notNull) { MetadataFactory factory = DatabaseStore.createMF(this); BaseColumn column = null; if (type == Database.ResourceType.TABLE){ Table table = (Table)getSchemaRecord(objectName, type); assertGrant(Grant.Permission.Privilege.ALTER, Database.ResourceType.TABLE, table); column = table.getColumnByName(childName); if (column == null){ throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_table_column_found", childName, table.getName())); //$NON-NLS-1$ } } else { Procedure proc = (Procedure)getSchemaRecord(objectName, type); assertGrant(Grant.Permission.Privilege.ALTER, Database.ResourceType.PROCEDURE, proc); column = proc.getParameterByName(childName); if (column == null){ throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_proc_column_found", childName, proc.getName())); //$NON-NLS-1$ } } MetadataFactory.setDataType(datatype.getType(), column, factory.getDataTypes(), notNull); SQLParserUtil.setTypeInfo(datatype, column); if (notNull) { column.setNullType(Column.NullType.No_Nulls); } if (type == Database.ResourceType.TABLE){ //must be called after setDataType as that will pull the defaults ((Column)column).setAutoIncremented(autoIncrement); } }
public void alterBaseColumn(String objectName, Database.ResourceType type, String childName, ParsedDataType datatype, boolean autoIncrement, boolean notNull) { MetadataFactory factory = DatabaseStore.createMF(this); BaseColumn column = null; if (type == Database.ResourceType.TABLE){ Table table = (Table)getSchemaRecord(objectName, type); assertGrant(Grant.Permission.Privilege.ALTER, Database.ResourceType.TABLE, table); column = table.getColumnByName(childName); if (column == null){ throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_table_column_found", childName, table.getName())); //$NON-NLS-1$ } } else { Procedure proc = (Procedure)getSchemaRecord(objectName, type); assertGrant(Grant.Permission.Privilege.ALTER, Database.ResourceType.PROCEDURE, proc); column = proc.getParameterByName(childName); if (column == null){ throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_proc_column_found", childName, proc.getName())); //$NON-NLS-1$ } } MetadataFactory.setDataType(datatype.getType(), column, factory.getDataTypes(), notNull); SQLParserUtil.setTypeInfo(datatype, column); if (notNull) { column.setNullType(Column.NullType.No_Nulls); } if (type == Database.ResourceType.TABLE){ //must be called after setDataType as that will pull the defaults ((Column)column).setAutoIncremented(autoIncrement); } }
} else { proc = (Procedure)dbStore.getSchemaRecord(objectName, type); column = proc.getParameterByName(oldName); if (column == null){ {if (true) throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_proc_column_found", oldName, proc.getName()));} //$NON-NLS-1$
} else { proc = (Procedure)dbStore.getSchemaRecord(objectName, type); column = proc.getParameterByName(childName); if (column == null){ {if (true) throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_proc_column_found", childName, proc.getName()));} //$NON-NLS-1$