private String MysqlString(String listcolumns) { /* handle forbiden char like ' */ String ReturnString = ""; String[] split = listcolumns.split(","); for (int i = 0; i < split.length; i++) { if (ReturnString.equals("")) ReturnString = "`" + Const.trim(split[i]) + "`"; else ReturnString = ReturnString + ", `" + Const.trim(split[i]) + "`"; } return ReturnString; }
/** Get a list of columns, comma separated, allow the user to select from it. */ private void getListColumns() { if (!Const.isEmpty(wTablename.getText())) { DatabaseMeta databaseMeta = jobMeta.findDatabase(wConnection.getText()); if (databaseMeta != null) { Database database = new Database(loggingObject, databaseMeta); database.shareVariablesWith(jobMeta); try { database.connect(); String schemaTable = databaseMeta.getQuotedSchemaTableCombination( wSchemaname.getText(), wTablename.getText()); RowMetaInterface row = database.getTableFields(schemaTable); String[] available = row.getFieldNames(); String[] source = wListattribut.getText().split(","); for (int i = 0; i < source.length; i++) { source[i] = Const.trim(source[i]); } int[] idxSource = Const.indexsOfStrings(source, available); EnterSelectionDialog dialog = new EnterSelectionDialog( shell, available, BaseMessages.getString(PKG, "JobMysqlBulkLoad.SelectColumns.Title"), BaseMessages.getString(PKG, "JobMysqlBulkLoad.SelectColumns.Message")); dialog.setMulti(true); dialog.setAvoidQuickSearch(); dialog.setSelectedNrs(idxSource); if (dialog.open() != null) { String columns = ""; int[] idx = dialog.getSelectionIndeces(); for (int i = 0; i < idx.length; i++) { if (i > 0) { columns += ", "; } columns += available[idx[i]]; } wListattribut.setText(columns); } } catch (KettleDatabaseException e) { new ErrorDialog( shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobMysqlBulkLoad.ConnectionError2.DialogMessage"), e); } finally { database.disconnect(); } } } }
private Object[] getOneRow() throws KettleException { if (!openNextFile()) { return null; } // Build an empty row based on the meta-data Object[] outputRowData = buildEmptyRow(); try { // Create new row or clone if (meta.getIsInFields()) System.arraycopy(data.readrow, 0, outputRowData, 0, data.readrow.length); // Read fields... for (int i = 0; i < data.nrInputFields; i++) { // Get field LoadFileInputField loadFileInputField = meta.getInputFields()[i]; String o = null; switch (loadFileInputField.getElementType()) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: // DO Trimming! switch (loadFileInputField.getTrimType()) { case LoadFileInputField.TYPE_TRIM_LEFT: data.filecontent = Const.ltrim(data.filecontent); break; case LoadFileInputField.TYPE_TRIM_RIGHT: data.filecontent = Const.rtrim(data.filecontent); break; case LoadFileInputField.TYPE_TRIM_BOTH: data.filecontent = Const.trim(data.filecontent); break; default: break; } o = data.filecontent; break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf(data.fileSize); break; default: break; } int indexField = data.totalpreviousfields + i; // Do conversions // ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(indexField); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(indexField); outputRowData[indexField] = targetValueMeta.convertData(sourceValueMeta, o); // Do we need to repeat this field if it is null? if (loadFileInputField.isRepeated()) { if (data.previousRow != null && o == null) { outputRowData[indexField] = data.previousRow[indexField]; } } } // End of loop over fields... int rowIndex = data.totalpreviousfields + data.nrInputFields; // See if we need to add the filename to the row... if (meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0) { outputRowData[rowIndex++] = data.filename; } // See if we need to add the row number to the row... if (meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0) { outputRowData[rowIndex++] = new Long(data.rownr); } // Possibly add short filename... if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) { outputRowData[rowIndex++] = data.shortFilename; } // Add Extension if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) { outputRowData[rowIndex++] = data.extension; } // add path if (meta.getPathField() != null && meta.getPathField().length() > 0) { outputRowData[rowIndex++] = data.path; } // add Hidden if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) { outputRowData[rowIndex++] = new Boolean(data.hidden); } // Add modification date if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) { outputRowData[rowIndex++] = data.lastModificationDateTime; } // Add Uri if (meta.getUriField() != null && meta.getUriField().length() > 0) { outputRowData[rowIndex++] = data.uriName; } // Add RootUri if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : (Object[]) irow.cloneRow(outputRowData); // copy it to make // surely the next step doesn't change it in between... incrementLinesInput(); data.rownr++; } catch (Exception e) { throw new KettleException("Impossible de charger le fichier", e); } return outputRowData; }
private void getInfo(JobEntryTrans jet) throws KettleException { jet.setName(wName.getText()); if (rep != null) { specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME; } else { specificationMethod = ObjectLocationSpecificationMethod.FILENAME; } jet.setSpecificationMethod(specificationMethod); switch (specificationMethod) { case FILENAME: jet.setFileName(wPath.getText()); if (jet.getFilename().isEmpty()) { throw new KettleException( BaseMessages.getString(PKG, "JobTrans.Dialog.Exception.NoValidMappingDetailsFound")); } jet.setDirectory(null); jet.setTransname(null); jet.setTransObjectId(null); break; case REPOSITORY_BY_NAME: String transPath = wPath.getText(); String transName = transPath; String directory = ""; int index = transPath.lastIndexOf("/"); if (index != -1) { transName = transPath.substring(index + 1); directory = transPath.substring(0, index); } jet.setDirectory(directory); if (jet.getDirectory().isEmpty()) { throw new KettleException( BaseMessages.getString( PKG, "JobTrans.Dialog.Exception.UnableToFindRepositoryDirectory")); } jet.setTransname(transName); jet.setFileName(null); jet.setTransObjectId(null); break; default: break; } int nritems = wFields.nrNonEmpty(); int nr = 0; for (int i = 0; i < nritems; i++) { String arg = wFields.getNonEmpty(i).getText(1); if (arg != null && arg.length() != 0) { nr++; } } jet.arguments = new String[nr]; nr = 0; for (int i = 0; i < nritems; i++) { String arg = wFields.getNonEmpty(i).getText(1); if (arg != null && arg.length() != 0) { jet.arguments[nr] = arg; nr++; } } // Do the parameters nritems = wParameters.nrNonEmpty(); nr = 0; for (int i = 0; i < nritems; i++) { String param = wParameters.getNonEmpty(i).getText(1); if (param != null && param.length() != 0) { nr++; } } jet.parameters = new String[nr]; jet.parameterFieldNames = new String[nr]; jet.parameterValues = new String[nr]; nr = 0; for (int i = 0; i < nritems; i++) { String param = wParameters.getNonEmpty(i).getText(1); String fieldName = wParameters.getNonEmpty(i).getText(2); String value = wParameters.getNonEmpty(i).getText(3); jet.parameters[nr] = param; if (!Utils.isEmpty(Const.trim(fieldName))) { jet.parameterFieldNames[nr] = fieldName; } else { jet.parameterFieldNames[nr] = ""; } if (!Utils.isEmpty(Const.trim(value))) { jet.parameterValues[nr] = value; } else { jet.parameterValues[nr] = ""; } nr++; } jet.setPassingAllParameters(wPassParams.getSelection()); jet.logfile = wLogfile.getText(); jet.logext = wLogext.getText(); if (wLoglevel.getSelectionIndex() >= 0) { jet.logFileLevel = LogLevel.values()[wLoglevel.getSelectionIndex()]; } else { jet.logFileLevel = LogLevel.BASIC; } jet.argFromPrevious = wPrevious.getSelection(); jet.paramsFromPrevious = wPrevToParams.getSelection(); jet.execPerRow = wEveryRow.getSelection(); jet.setLogfile = wSetLogfile.getSelection(); jet.addDate = wAddDate.getSelection(); jet.addTime = wAddTime.getSelection(); jet.clearResultRows = wClearRows.getSelection(); jet.clearResultFiles = wClearFiles.getSelection(); jet.setClustering(wCluster.getSelection()); jet.setLoggingRemoteWork(wLogRemoteWork.getSelection()); jet.createParentFolder = wCreateParentFolder.getSelection(); jet.setRemoteSlaveServerName(wSlaveServer.getText()); jet.setAppendLogfile = wAppendLogfile.getSelection(); jet.setWaitingToFinish(wWaitingToFinish.getSelection()); jet.setFollowingAbortRemotely(wFollowingAbortRemotely.getSelection()); }
protected void pickFileVFS() { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterExtensions(Const.STRING_TRANS_FILTER_EXT); dialog.setFilterNames(Const.getTransformationFilterNames()); String prevName = jobMeta.environmentSubstitute(wPath.getText()); String parentFolder = null; try { parentFolder = KettleVFS.getFilename( KettleVFS.getFileObject(jobMeta.environmentSubstitute(jobMeta.getFilename())) .getParent()); } catch (Exception e) { // not that important } if (!Utils.isEmpty(prevName)) { try { if (KettleVFS.fileExists(prevName)) { dialog.setFilterPath( KettleVFS.getFilename(KettleVFS.getFileObject(prevName).getParent())); } else { if (!prevName.endsWith(".ktr")) { prevName = getEntryName(Const.trim(wPath.getText()) + ".ktr"); } if (KettleVFS.fileExists(prevName)) { specificationMethod = ObjectLocationSpecificationMethod.FILENAME; wPath.setText(prevName); return; } else { // File specified doesn't exist. Ask if we should create the file... // MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION); mb.setMessage( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Message")); mb.setText( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Title")); // Sorry! int answer = mb.open(); if (answer == SWT.YES) { Spoon spoon = Spoon.getInstance(); spoon.newTransFile(); TransMeta transMeta = spoon.getActiveTransformation(); transMeta.initializeVariablesFrom(jobEntry); transMeta.setFilename(jobMeta.environmentSubstitute(prevName)); wPath.setText(prevName); specificationMethod = ObjectLocationSpecificationMethod.FILENAME; spoon.saveFile(); return; } } } } catch (Exception e) { dialog.setFilterPath(parentFolder); } } else if (!Utils.isEmpty(parentFolder)) { dialog.setFilterPath(parentFolder); } String fname = dialog.open(); if (fname != null) { File file = new File(fname); String name = file.getName(); String parentFolderSelection = file.getParentFile().toString(); if (!Utils.isEmpty(parentFolder) && parentFolder.equals(parentFolderSelection)) { wPath.setText(getEntryName(name)); } else { wPath.setText(fname); } } }
private Object[] buildRow() throws KettleException { // Create new row... Object[] outputRowData = null; if (data.readrow != null) outputRowData = data.readrow.clone(); else outputRowData = buildEmptyRow(); // Read fields... for (int i = 0; i < data.nrInputFields; i++) { // Get field JsonInputField field = meta.getInputFields()[i]; // get json array for field JSONArray jsona = data.resultList.get(i).getJSONArray(); String nodevalue = null; if (jsona != null) { Object jo = (Object) jsona.get(data.recordnr); if (jo != null) { nodevalue = jo.toString(); } } // Do trimming switch (field.getTrimType()) { case JsonInputField.TYPE_TRIM_LEFT: nodevalue = Const.ltrim(nodevalue); break; case JsonInputField.TYPE_TRIM_RIGHT: nodevalue = Const.rtrim(nodevalue); break; case JsonInputField.TYPE_TRIM_BOTH: nodevalue = Const.trim(nodevalue); break; default: break; } if (meta.isInFields()) { // Add result field to input stream outputRowData = RowDataUtil.addValueData(outputRowData, data.totalpreviousfields + i, nodevalue); } // Do conversions // ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i); outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, nodevalue); // Do we need to repeat this field if it is null? if (meta.getInputFields()[i].isRepeated()) { if (data.previousRow != null && Const.isEmpty(nodevalue)) { outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i]; } } } // End of loop over fields... // When we have an input stream // the row index take care of previous fields int rowIndex = data.totalpreviousfields + data.nrInputFields; // See if we need to add the filename to the row... if (meta.includeFilename() && !Const.isEmpty(meta.getFilenameField())) { outputRowData[rowIndex++] = data.filename; } // See if we need to add the row number to the row... if (meta.includeRowNumber() && !Const.isEmpty(meta.getRowNumberField())) { outputRowData[rowIndex++] = new Long(data.rownr); } // Possibly add short filename... if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) { outputRowData[rowIndex++] = data.shortFilename; } // Add Extension if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) { outputRowData[rowIndex++] = data.extension; } // add path if (meta.getPathField() != null && meta.getPathField().length() > 0) { outputRowData[rowIndex++] = data.path; } // Add Size if (meta.getSizeField() != null && meta.getSizeField().length() > 0) { outputRowData[rowIndex++] = new Long(data.size); } // add Hidden if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) { outputRowData[rowIndex++] = new Boolean(data.path); } // Add modification date if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) { outputRowData[rowIndex++] = data.lastModificationDateTime; } // Add Uri if (meta.getUriField() != null && meta.getUriField().length() > 0) { outputRowData[rowIndex++] = data.uriName; } // Add RootUri if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) { outputRowData[rowIndex++] = data.rootUriName; } data.recordnr++; RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : (Object[]) irow.cloneRow(outputRowData); // copy it to make // surely the next step doesn't change it in between... return outputRowData; }