public static String pg_get_indexdef(CommandContext cc, int index_oid, short column_no, boolean pretty_bool) throws TeiidSQLException, SQLException { //TODO: account for function based index try (Connection c = cc.getConnection(); PreparedStatement ps = c.prepareStatement("select indkey_names[?] from pg_index where indexrelid = ?")) { //$NON-NLS-1$ ps.setShort(1, column_no); ps.setInt(2, index_oid); ps.execute(); ResultSet rs = ps.getResultSet(); String result = null; if (rs.next()) { result = rs.getString(1); } return result; } }
/** * The {@link Session} for the event or null if one has not been established. * @return */ public Session getSession() { if (this.commandContext != null) { return this.commandContext.getSession(); } return session; }
private void validateEntitlements(DataPolicy.PermissionType actionCode, Context auditContext, Map<String, ? extends LanguageObject> nameToSymbolMap) { if (nameToSymbolMap.isEmpty()) { return; } Collection<String> inaccessibleResources = getInaccessibleResources(actionCode, nameToSymbolMap.keySet(), auditContext); if(inaccessibleResources.isEmpty()) { return; } List<LanguageObject> inaccessibleSymbols = new ArrayList<LanguageObject>(inaccessibleResources.size()); for (String name : inaccessibleResources) { inaccessibleSymbols.add(nameToSymbolMap.get(name)); } // CASE 2362 - do not include the names of the elements for which the user // is not authorized in the exception message handleValidationError( QueryPlugin.Util.getString("ERR.018.005.0095", commandContext.getUserName(), actionCode), //$NON-NLS-1$ inaccessibleSymbols); }
private void handleInsert() throws TranslatorException { Insert insert = (Insert)command; ExpressionValueSource evs = (ExpressionValueSource)insert.getValueSource(); Row row = nextRow(); Sheet sheet = null; if (row == null) { sheet = workbook.getSheet(this.visitor.getSheetName()); } else { sheet = row.getSheet(); } int last = sheet.getLastRowNum(); Row newRow = sheet.createRow(last+1); List<Integer> cols = this.visitor.getProjectedColumns(); for (int i = 0; i < cols.size(); i++) { int index = cols.get(i); setValue(newRow, index-1, ((Literal)evs.getValues().get(i)).getValue()); } if (executionContext.getCommandContext().isReturnAutoGeneratedKeys()) { GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] {ExcelMetadataProcessor.ROW_ID}, new Class<?>[] {TypeFacility.RUNTIME_TYPES.INTEGER}); keys.addKey(Arrays.asList(last+1)); } result++; writeXLSFile(); }
public AuditEnitity(AuditMessage msg) { this.context = msg.getContext(); this.activity = msg.getActivity(); this.resources = StringUtil.toString(msg.getResources()); if (msg.getCommandContext() != null) { this.requestId = msg.getCommandContext().getRequestId(); this.principal = msg.getCommandContext().getUserName(); this.vdbName = msg.getCommandContext().getVdbName(); this.vdbVersion = msg.getCommandContext().getVdbVersion(); this.sessionId = msg.getCommandContext().getSession().getSessionId(); this.applicationName = msg.getCommandContext().getSession().getApplicationName(); } else if (msg.getLogonInfo() != null) { this.authType = msg.getLogonInfo().getAuthType(); this.userName = msg.getLogonInfo().getUserName(); this.clientHostName = msg.getLogonInfo().getClientHostName(); this.clientIpAddress = msg.getLogonInfo().getClientIpAddress(); this.clientMac = msg.getLogonInfo().getClientMac(); this.passThrough = msg.getLogonInfo().isPassThrough(); } }
@Override public int[] getUpdateCounts() throws DataNotAvailableException, TranslatorException { if (this.visitor.getMethod().equals("DELETE")) { //$NON-NLS-1$ //DELETE return (this.response != null)?new int[]{1}:new int[]{0}; } else if(this.visitor.getMethod().equals("PUT")) { //$NON-NLS-1$ // UPDATE; // conflicting implementation found where some sent 200 with content; other with 204 no-content return (this.response != null)?new int[]{1}:new int[]{0}; } else if (this.visitor.getMethod().equals("POST")) { //$NON-NLS-1$ //INSERT if (this.response != null && this.response.hasRow()) { if (this.executionContext.getCommandContext().isReturnAutoGeneratedKeys()) { addAutoGeneretedKeys(); } return new int[]{1}; } } return new int[] {0}; }
private void addAutoGeneretedKeys(WriteResult result) throws TranslatorException { Table table = this.visitor.mongoDoc.getTargetTable(); int cols = table.getPrimaryKey().getColumns().size(); if (cols != 1) { //restrict to only primary keys based upon id return; } Class<?>[] columnDataTypes = new Class<?>[cols]; String[] columnNames = new String[cols]; //this is typically expected to be an int/long, but we'll be general here. we may eventual need the type logic off of the metadata importer for (int i = 0; i < cols; i++) { columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType(); columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName(); } if (!columnNames[0].equals(MongoDBMetadataProcessor.ID)) { return; } GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes); List<Object> vals = new ArrayList<Object>(columnDataTypes.length); for (int i = 0; i < columnDataTypes.length; i++) { Object value = this.executionFactory.retrieveValue(result.getUpsertedId(), columnDataTypes[i], this.mongoDB, columnNames[i], columnNames[i]); vals.add(value); } generatedKeys.addKey(vals); } }
@Override public boolean validateCommand(CommandContext commandContext) { return !commandContext.getVdb().getDataPolicies().isEmpty(); }
@Override public boolean hasRole(String roleName, CommandContext context) { return context.getAllowedDataPolicies().containsKey(roleName); }
public String toString() { StringBuffer msg = new StringBuffer(); if (this.commandContext != null) { msg.append( this.commandContext.getRequestId()); } msg.append(" ["); //$NON-NLS-1$ if (this.logonInfo != null) { msg.append(this.logonInfo); } else { msg.append( getPrincipal() ); } msg.append("] <"); //$NON-NLS-1$ msg.append( getContext() ); msg.append('.'); msg.append( getActivity() ); msg.append("> "); //$NON-NLS-1$ if (resources != null) { msg.append( Arrays.toString(resources) ); } return msg.toString(); }
Class<?>[] keyColumnDataTypes = null; String[] keyColumnNames = null; if (command instanceof Insert && context.getCommandContext().isReturnAutoGeneratedKeys() && executionFactory.supportsGeneratedKeys(context, command)) { Insert insert = (Insert)command; NamedTable nt = insert.getTable(); try { ResultSet keys = statement.getGeneratedKeys(); GeneratedKeys generatedKeys = context.getCommandContext().returnGeneratedKeys(keyColumnNames, keyColumnDataTypes);
@Override public int[] getUpdateCounts() throws DataNotAvailableException, TranslatorException { if (this.visitor.getOperationType() == OperationType.DELETE) { return new int[]{this.updateCount.get()}; } else if(this.visitor.getOperationType() == OperationType.UPDATE) { return new int[]{this.updateCount.get()}; } else if (this.visitor.getOperationType() == OperationType.INSERT) { if (this.createdEntity != null) { if (this.executionContext.getCommandContext().isReturnAutoGeneratedKeys()) { addAutoGeneretedKeys(this.visitor.getODataQuery().getRootDocument().getTable(), this.createdEntity); } } return new int[]{1}; } return new int[] {0}; }
private void addAutoGeneretedKeys() { OEntity entity = this.response.getResultsIter().next().getEntity(); Table table = this.visitor.getEnityTable(); int cols = table.getPrimaryKey().getColumns().size(); Class<?>[] columnDataTypes = new Class<?>[cols]; String[] columnNames = new String[cols]; //this is typically expected to be an int/long, but we'll be general here. we may eventual need the type logic off of the metadata importer for (int i = 0; i < cols; i++) { columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType(); columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName(); } GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes); List<Object> vals = new ArrayList<Object>(columnDataTypes.length); for (int i = 0; i < columnDataTypes.length; i++) { OProperty<?> prop = entity.getProperty(columnNames[i]); Object value = this.translator.retrieveValue(prop.getValue(), columnDataTypes[i]); vals.add(value); } generatedKeys.addKey(vals); } }
@Override public boolean validateCommand(CommandContext commandContext) { return !commandContext.getVdb().getDataPolicies().isEmpty(); }
@Override public boolean hasRole(String roleName, CommandContext context) { return context.getAllowedDataPolicies().containsKey(roleName); }
if (this.executionContext.getCommandContext().isReturnAutoGeneratedKeys()) { addAutoGeneretedKeys(executionResults.get(0));
.returnGeneratedKeys(columnNames, columnDataTypes);
public static String formatType(org.teiid.CommandContext cc, int oid, int typmod) throws SQLException { Connection c = cc.getConnection(); try { PreparedStatement ps = c.prepareStatement("select typname from pg_catalog.pg_type where oid = ?"); //$NON-NLS-1$
@Override public boolean validateCommand(CommandContext commandContext) { return !commandContext.getVdb().getDataPolicies().isEmpty(); }
private void validateEntitlements(DataPolicy.PermissionType actionCode, Context auditContext, Map<String, ? extends LanguageObject> nameToSymbolMap) { if (nameToSymbolMap.isEmpty()) { return; } Collection<String> inaccessibleResources = getInaccessibleResources(actionCode, nameToSymbolMap.keySet(), auditContext); if(inaccessibleResources.isEmpty()) { return; } List<LanguageObject> inaccessibleSymbols = new ArrayList<LanguageObject>(inaccessibleResources.size()); for (String name : inaccessibleResources) { inaccessibleSymbols.add(nameToSymbolMap.get(name)); } // CASE 2362 - do not include the names of the elements for which the user // is not authorized in the exception message handleValidationError( QueryPlugin.Util.getString("ERR.018.005.0095", commandContext.getUserName(), actionCode), //$NON-NLS-1$ inaccessibleSymbols); }