1 16 17 package org.pentaho.plugin.kettle; 18 19 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.pentaho.core.connection.memory.MemoryMetaData; 26 import org.pentaho.core.connection.memory.MemoryResultSet; 27 import org.pentaho.core.solution.IActionResource; 28 import org.pentaho.core.system.PentahoSystem; 29 import org.pentaho.core.util.XmlHelper; 30 import org.pentaho.core.util.XmlW3CHelper; 31 import org.pentaho.messages.Messages; 32 import org.pentaho.plugin.ComponentBase; 33 34 import be.ibridge.kettle.core.LocalVariables; 35 import be.ibridge.kettle.core.LogWriter; 36 import be.ibridge.kettle.core.Result; 37 import be.ibridge.kettle.core.Row; 38 import be.ibridge.kettle.core.exception.KettleException; 39 import be.ibridge.kettle.core.logging.Log4jStringAppender; 40 import be.ibridge.kettle.core.value.Value; 41 import be.ibridge.kettle.job.Job; 42 import be.ibridge.kettle.job.JobMeta; 43 import be.ibridge.kettle.repository.RepositoriesMeta; 44 import be.ibridge.kettle.repository.Repository; 45 import be.ibridge.kettle.repository.RepositoryDirectory; 46 import be.ibridge.kettle.repository.RepositoryMeta; 47 import be.ibridge.kettle.repository.UserInfo; 48 import be.ibridge.kettle.trans.StepLoader; 49 import be.ibridge.kettle.trans.Trans; 50 import be.ibridge.kettle.trans.TransMeta; 51 import be.ibridge.kettle.trans.step.RowListener; 52 import be.ibridge.kettle.trans.step.StepMetaDataCombi; 53 54 60 public class KettleComponent extends ComponentBase implements RowListener { 61 62 private static final long serialVersionUID = 8217343898202366129L; 63 64 private static final String DIRECTORY = "directory"; 66 private static final String TRANSFORMATION = "transformation"; 68 private static final String JOB = "job"; 70 private static final String TRANSFORMFILE = "transformation-file"; 72 private static final String JOBFILE = "job-file"; 74 private static final String IMPORTSTEP = "importstep"; 76 79 private String repositoriesXMLFile; 80 81 82 private String repositoryName; 83 84 85 private String username; 86 87 MemoryResultSet results; 88 89 90 private String password; 91 92 private Log4jStringAppender kettleUserAppender; 93 94 public Log getLogger() { 95 return LogFactory.getLog(KettleComponent.class); 96 } 97 98 protected boolean validateSystemSettings() { 99 boolean useRepository = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.type", "files").equals("rdbms"); if (useRepository) { 102 repositoriesXMLFile = PentahoSystem.getSystemSetting("kettle/settings.xml", "repositories.xml.file", null); repositoryName = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.name", null); username = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.userid", ""); password = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.password", ""); if ("".equals(repositoryName) || username.equals("")) { 111 error(Messages.getErrorString("Kettle.ERROR_0001_SERVER_SETTINGS_NOT_SET")); return false; 113 } 114 115 boolean ok = (repositoryName != null && repositoryName.length() > 0); 116 ok = ok || (username != null && username.length() > 0); 117 118 return ok; 119 } 120 return true; 121 } 122 123 public boolean init() { 124 return true; 125 126 } 127 128 public boolean validateAction() { 129 130 if (isDefinedResource(TRANSFORMFILE) || isDefinedResource(JOBFILE)) { 131 return true; 132 } 133 134 boolean useRepository = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.type", "files").equals("rdbms"); 136 if (!useRepository) { 137 error(Messages.getErrorString("Kettle.ERROR_0019_REPOSITORY_TYPE_FILES")); return false; 139 } 140 141 if (isDefinedInput(DIRECTORY) && (isDefinedInput(TRANSFORMATION) || isDefinedInput(JOB))) { 142 return true; 143 } 144 145 if (!isDefinedInput(DIRECTORY)) { 146 error(Messages.getErrorString("Kettle.ERROR_0002_DIR_OR_FILE__NOT_DEFINED", getActionName())); return false; 148 } else { 149 if (!isDefinedInput(TRANSFORMATION)) { 150 error(Messages.getErrorString("Kettle.ERROR_0003_TRANS_NOT_DEFINED", getActionName())); return false; 152 } 153 } 154 155 return false; 156 157 } 158 159 162 public boolean executeAction() { 163 164 if (debug) 165 debug(Messages.getString("Kettle.DEBUG_START")); 167 TransMeta transMeta = null; 168 JobMeta jobMeta = null; 169 LogWriter logWriter = null; 170 171 kettleUserAppender = LogWriter.createStringAppender(); 172 try { 173 logWriter = LogWriter.getInstance("Kettle-pentaho", false, LogWriter.LOG_LEVEL_BASIC); } catch (Throwable t) { 175 176 } 177 178 179 boolean running = true; 182 int index = 1; 183 ArrayList parameterList = new ArrayList (); 184 while (running) { 185 if (isDefinedInput("parameter" + index)) { String value = null; 187 String inputName = getInputStringValue("parameter" + index); if (isDefinedInput(inputName)) { 190 value = getInputStringValue(inputName); 191 } 192 parameterList.add(value); 193 } else { 194 running = false; 195 } 196 index++; 197 } 198 199 Iterator inputNamesIter = getInputNames().iterator(); 201 while (inputNamesIter.hasNext()) { 202 String name = (String ) inputNamesIter.next(); 203 String value = null; 204 if (isDefinedInput(name)) { 205 value = getInputStringValue(name); 206 } 207 if (!parameterList.contains(value)) { 208 parameterList.add(value); 209 } 210 } 211 212 String parameters[] = (String []) parameterList.toArray(new String [parameterList.size()]); 213 214 Repository repository = connectToRepository(logWriter); 215 boolean result = false; 216 logWriter.addAppender(kettleUserAppender); 217 try { 218 if (isDefinedInput(DIRECTORY)) { 219 String directoryName = getInputStringValue(DIRECTORY); 220 221 if (repository == null) { 222 return false; 223 } 224 225 if (isDefinedInput(TRANSFORMATION)) { 226 String transformationName = getInputStringValue(TRANSFORMATION); 227 transMeta = loadTransformFromRepository(directoryName, transformationName, repository, logWriter); 228 if (transMeta != null) { 229 transMeta.setArguments(parameters); 230 } else { 231 return false; 232 } 233 } else if (isDefinedInput(JOB)) { 234 String jobName = getInputStringValue(JOB); 235 jobMeta = loadJobFromRepository(directoryName, jobName, repository, logWriter); 236 if (jobMeta != null) { 237 jobMeta.setArguments(parameters); 238 } else { 239 return false; 240 } 241 } 242 } else if (isDefinedResource(TRANSFORMFILE)) { 243 IActionResource transformResource = getResource(TRANSFORMFILE); 244 String fileAddress = getActualFileName(transformResource); 245 246 try { 247 if (fileAddress != null) { transMeta = new TransMeta(fileAddress, repository, true); 249 } else { 250 String jobXmlStr = getResourceAsString(getResource(TRANSFORMFILE)); 251 jobXmlStr = jobXmlStr.replaceAll("\\$\\{pentaho.solutionpath\\}", PentahoSystem.getApplicationContext().getFileOutputPath("")); jobXmlStr = jobXmlStr.replaceAll("\\%\\%pentaho.solutionpath\\%\\%", PentahoSystem.getApplicationContext().getFileOutputPath("")); org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString(jobXmlStr); 254 transMeta = new TransMeta(doc.getFirstChild()); 256 } 257 } catch (Exception e) { 258 error(Messages.getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", TRANSFORMFILE, fileAddress), e); return false; 260 } 261 262 if (transMeta == null) { 263 error(Messages.getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", TRANSFORMFILE, fileAddress)); info(kettleUserAppender.getBuffer().toString()); 265 return false; 266 } else { transMeta.setArguments(parameters); 268 } 269 } else if (isDefinedResource(JOBFILE)) { 270 String fileAddress = ""; try { 272 fileAddress = getResource(JOBFILE).getAddress(); 273 String jobXmlStr = XmlHelper.getContentFromSolutionResource(fileAddress); 274 String solutionPath = PentahoSystem.getApplicationContext().getFileOutputPath( "" ); solutionPath = solutionPath.replaceAll( "\\\\", "\\\\\\\\" ); solutionPath = solutionPath.replaceAll( "\\$", "\\\\\\$" ); jobXmlStr = jobXmlStr.replaceAll( "\\$\\{pentaho.solutionpath\\}", solutionPath ); jobXmlStr = jobXmlStr.replaceAll( "\\%\\%pentaho.solutionpath\\%\\%", solutionPath ); org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString(jobXmlStr); 280 if (doc == null) { 281 error(Messages.getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", JOBFILE, fileAddress)); info(kettleUserAppender.getBuffer().toString()); 283 return false; 284 } 285 try { 287 repository = connectToRepository(logWriter); 288 jobMeta = new JobMeta(logWriter, doc.getFirstChild(), repository); 290 } catch (Exception e) { 291 error(Messages.getString("Kettle.ERROR_0023_NO_META"), e); } finally { 293 if (repository != null) { 294 if (debug) 295 debug(Messages.getString("Kettle.DEBUG_DISCONNECTING")); repository.disconnect(); 297 } 298 } 299 } catch (Exception e) { 300 error(Messages.getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", JOBFILE, fileAddress), e); return false; 302 } 303 if (jobMeta == null) { 304 error(Messages.getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", JOBFILE, fileAddress)); info(kettleUserAppender.getBuffer().toString()); 306 return false; 307 } else { 308 jobMeta.setArguments(parameters); 309 } 310 311 } 312 313 316 if (transMeta != null) { 317 result = executeTransformation(transMeta, logWriter); 318 } 319 if (jobMeta != null) { 320 result = executeJob(jobMeta, repository, logWriter); 321 } 322 323 } finally { 324 logWriter.removeAppender(kettleUserAppender); 325 if (repository != null) { 326 if (debug) 327 debug(Messages.getString("Kettle.DEBUG_DISCONNECTING")); repository.disconnect(); 329 } 330 } 331 return result; 332 333 } 334 335 private String getActualFileName(IActionResource resource) { 336 String fileAddress = null; 337 338 if ((resource.getSourceType() == IActionResource.FILE_RESOURCE)) { 340 fileAddress = resource.getAddress(); 341 } 342 else if (resource.getSourceType() == IActionResource.SOLUTION_FILE_RESOURCE) { 344 fileAddress = PentahoSystem.getApplicationContext().getSolutionPath(resource.getAddress()); 345 } 346 347 if (fileAddress != null) { 349 File file = new File (fileAddress); 350 if (!file.exists() || !file.isFile()) { 351 fileAddress = null; 352 } 353 } 354 return (fileAddress); 355 } 356 357 private boolean executeTransformation(TransMeta transMeta, LogWriter logWriter) { 358 boolean success = true; 359 Trans trans = null; 360 try { 361 if (transMeta != null) { 362 try { 363 trans = new Trans(logWriter, transMeta); 364 } catch (Throwable t) { 365 error(Messages.getErrorString("Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA"), t); return false; 367 } 368 369 } 370 if (trans == null) { 371 error(Messages.getErrorString("Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA")); error(kettleUserAppender.getBuffer().toString()); 373 return false; 374 } 375 if (trans != null) { 376 if (debug) 378 debug(Messages.getString("Kettle.DEBUG_PREPARING_TRANSFORMATION")); try { 380 KettleSystemListener.environmentInit(); 381 if (!trans.prepareExecution(transMeta.getArguments())) { 382 error(Messages.getErrorString("Kettle.ERROR_0011_TRANSFORMATION_PREPARATION_FAILED")); error(kettleUserAppender.getBuffer().toString()); 384 return false; 385 } 386 } catch (Throwable t) { 387 error(Messages.getErrorString("Kettle.ERROR_0011_TRANSFORMATION_PREPARATION_FAILED"), t); return false; 389 } 390 391 String stepName = null; 392 String outputName = null; 393 if (debug) 394 debug(Messages.getString("Kettle.DEBUG_FINDING_STEP_IMPORTER")); if (isDefinedInput(IMPORTSTEP)) { 396 try { 397 stepName = getInputStringValue(IMPORTSTEP); 400 if (getOutputNames().size() == 1) { 401 outputName = (String ) getOutputNames().iterator().next(); 402 } 403 boolean foundStep = false; 404 if (stepName != null && outputName != null) { 405 ArrayList stepList = trans.getSteps(); 406 for (int stepNo = 0; stepNo < stepList.size(); stepNo++) { 408 StepMetaDataCombi step = (StepMetaDataCombi) stepList.get(stepNo); 410 if (step.stepname.equals(stepName)) { 411 if (debug) 412 debug(Messages.getString("Kettle.DEBUG_FOUND_STEP_IMPORTER")); if (debug) 415 debug(Messages.getString("Kettle.DEBUG_GETTING_STEP_METADATA")); Row row = transMeta.getStepFields(stepName); 417 String fieldNames[] = row.getFieldNames(); 420 String columns[][] = new String [1][fieldNames.length]; 421 for (int column = 0; column < fieldNames.length; column++) { 422 columns[0][column] = fieldNames[column]; 423 } 424 if (debug) 425 debug(Messages.getString("Kettle.DEBUG_CREATING_RESULTSET_METADATA")); 427 MemoryMetaData metaData = new MemoryMetaData(columns, null); 428 results = new MemoryResultSet(metaData); 429 step.step.addRowListener(this); 431 foundStep = true; 432 break; 433 } 434 } 435 436 } 437 if (!foundStep) { 438 error(Messages.getErrorString("Kettle.ERROR_0012_ROW_LISTENER_CREATE_FAILED")); } 440 } catch (Exception e) { 441 error(Messages.getErrorString("Kettle.ERROR_0012_ROW_LISTENER_CREATE_FAILED"), e); return false; 443 } 444 } 445 446 try { 447 if (debug) 448 debug(Messages.getString("Kettle.DEBUG_STARTING_TRANSFORMATION")); trans.startThreads(); 450 } catch (Throwable t) { 451 error(Messages.getErrorString("Kettle.ERROR_0013_TRANSFORMATION_START_FAILED"), t); return false; 453 } 454 455 try { 456 if (debug) 459 debug(Messages.getString("Kettle.DEBUG_TRANSFORMATION_RUNNING")); trans.waitUntilFinished(); 461 } catch (Throwable t) { 462 error(Messages.getErrorString("Kettle.ERROR_0014_ERROR_DURING_EXECUTE")); return false; 464 } 465 info(kettleUserAppender.getBuffer().toString()); 467 if (outputName != null && results != null) { 468 if (debug) 469 debug(Messages.getString("Kettle.DEBUG_SETTING_OUTPUT")); setOutputValue(outputName, results); 471 } 472 } 473 } catch (Exception e) { 474 error(Messages.getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e); success = false; 476 } finally { 477 if (trans != null) { 478 LocalVariables.getInstance().removeKettleVariables(Thread.currentThread().getName()); 479 } 480 } 481 return success; 482 483 } 484 485 private boolean executeJob(JobMeta jobMeta, Repository repository, LogWriter logWriter) { 486 boolean success = true; 487 Job job = null; 488 try { 489 if (jobMeta != null) { 490 try { 491 job = new Job(logWriter, StepLoader.getInstance(), repository, jobMeta); 492 } catch (Throwable t) { 493 error(Messages.getErrorString("Kettle.ERROR_0021_BAD_JOB_METADATA"), t); return false; 495 } 496 497 } 498 if (job == null) { 499 error(Messages.getErrorString("Kettle.ERROR_0021_BAD_JOB_METADATA")); info(kettleUserAppender.getBuffer().toString()); 501 return false; 502 } 503 if (job != null) { 504 Result result = null; 506 try { 507 if (debug) 508 debug(Messages.getString("Kettle.DEBUG_STARTING_JOB")); KettleSystemListener.environmentInit(); 510 result = job.execute(); 511 } catch (Throwable t) { 512 error(Messages.getErrorString("Kettle.ERROR_002_JOB_START_FAILED"), t); return false; 514 } 515 516 try { 517 if (debug) 520 debug(Messages.getString("Kettle.DEBUG_JOB_RUNNING")); job.waitUntilFinished(5000000); 522 if (!result.getResult()) { 523 error(Messages.getErrorString("Kettle.ERROR_0014_ERROR_DURING_EXECUTE")); info(kettleUserAppender.getBuffer().toString()); 525 return false; 526 } 527 } catch (Throwable t) { 528 error(Messages.getErrorString("Kettle.ERROR_0014_ERROR_DURING_EXECUTE"), t); return false; 530 } 531 info(kettleUserAppender.getBuffer().toString()); 533 } 534 } catch (Exception e) { 535 error(Messages.getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e); success = false; 537 } finally { 538 if (job != null) { 539 LocalVariables.getInstance().removeKettleVariables(Thread.currentThread().getName()); 540 } 541 } 542 return success; 543 544 } 545 546 private TransMeta loadTransformFromRepository(String directoryName, String transformationName, Repository repository, LogWriter logWriter) { 547 if (debug) 548 debug(Messages.getString("Kettle.DEBUG_DIRECTORY", directoryName)); if (debug) 550 debug(Messages.getString("Kettle.DEBUG_TRANSFORMATION", transformationName)); TransMeta transMeta = null; 552 try { 553 554 if (debug) 555 debug(Messages.getString("Kettle.DEBUG_FINDING_DIRECTORY")); 557 RepositoryDirectory repositoryDirectory = null; 559 try { 560 repositoryDirectory = repository.getDirectoryTree().findDirectory(directoryName); 561 } catch (Throwable t) { 562 error(Messages.getErrorString("Kettle.ERROR_0006_DIRECTORY_NOT_FOUND", directoryName), t); return null; 564 } 565 if (repositoryDirectory == null) { 566 error(Messages.getErrorString("Kettle.ERROR_0006_DIRECTORY_NOT_FOUND", directoryName)); return null; 568 } 569 570 if (repositoryDirectory != null) { 571 if (debug) 572 debug(Messages.getString("Kettle.DEBUG_GETTING_TRANSFORMATION_METADATA")); 574 try { 575 transMeta = new TransMeta(repository, transformationName, repositoryDirectory); 577 } catch (Throwable t) { 578 error(Messages.getErrorString("Kettle.ERROR_0009_TRANSFROMATION_METADATA_NOT_FOUND", repositoryDirectory + "/" + transformationName), t); return null; 580 } 581 if (transMeta == null) { 582 error(Messages.getErrorString("Kettle.ERROR_0009_TRANSFROMATION_METADATA_NOT_FOUND", repositoryDirectory + "/" + transformationName)); info(kettleUserAppender.getBuffer().toString()); 584 return null; 585 } else { 586 return transMeta; 587 } 588 } 589 590 if (debug) 591 debug(kettleUserAppender.getBuffer().toString()); 592 594 } catch (Throwable e) { 595 error(Messages.getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e); } 597 return null; 598 } 599 600 private JobMeta loadJobFromRepository(String directoryName, String jobName, Repository repository, LogWriter logWriter) { 601 if (debug) 602 debug(Messages.getString("Kettle.DEBUG_DIRECTORY", directoryName)); if (debug) 604 debug(Messages.getString("Kettle.DEBUG_JOB", jobName)); JobMeta jobMeta = null; 606 try { 607 608 if (debug) 609 debug(Messages.getString("Kettle.DEBUG_FINDING_DIRECTORY")); 611 RepositoryDirectory repositoryDirectory = null; 613 try { 614 repositoryDirectory = repository.getDirectoryTree().findDirectory(directoryName); 615 } catch (Throwable t) { 616 error(Messages.getErrorString("Kettle.ERROR_0006_DIRECTORY_NOT_FOUND", directoryName), t); return null; 618 } 619 if (repositoryDirectory == null) { 620 error(Messages.getErrorString("Kettle.ERROR_0006_DIRECTORY_NOT_FOUND", directoryName)); return null; 622 } 623 624 if (repositoryDirectory != null) { 625 if (debug) 626 debug(Messages.getString("Kettle.DEBUG_GETTING_JOB_METADATA")); 628 try { 629 jobMeta = new JobMeta(logWriter, repository, jobName, repositoryDirectory); 631 } catch (Throwable t) { 632 error(Messages.getErrorString("Kettle.ERROR_0020_JOB_METADATA_NOT_FOUND", repositoryDirectory + "/" + jobName), t); return null; 634 } 635 if (jobMeta == null) { 636 error(Messages.getErrorString("Kettle.ERROR_0020_JOB_METADATA_NOT_FOUND", repositoryDirectory + "/" + jobName)); info(kettleUserAppender.getBuffer().toString()); 638 return null; 639 } else { 640 return jobMeta; 641 } 642 } 643 644 if (debug) 645 debug(kettleUserAppender.getBuffer().toString()); 646 648 } catch (Throwable e) { 649 error(Messages.getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e); } 651 return null; 652 } 653 654 private Repository connectToRepository(LogWriter logWriter) { 655 boolean useRepository = PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.type", "files").equals("rdbms"); 657 if (!useRepository) { 658 return null; 659 } 660 661 try { 662 if (debug) 663 debug(Messages.getString("Kettle.DEBUG_META_REPOSITORY")); 665 RepositoriesMeta repositoriesMeta = null; 666 try { 667 repositoriesMeta = new RepositoriesMeta(logWriter); 668 } catch (Throwable t) { 669 error(Messages.getErrorString("Kettle.ERROR_0007_BAD_META_REPOSITORY"), t); return null; 671 } 672 if (repositoriesMeta == null) { 673 error(Messages.getErrorString("Kettle.ERROR_0007_BAD_META_REPOSITORY")); info(kettleUserAppender.getBuffer().toString()); 675 return null; 676 } 677 678 if (debug) 679 debug(Messages.getString("Kettle.DEBUG_POPULATING_META")); try { 681 repositoriesMeta.readData(); } catch (Throwable t) { 684 error(Messages.getErrorString("Kettle.ERROR_0018_META_REPOSITORY_NOT_POPULATED"), t); return null; 686 } 687 if (repositoriesXMLFile != null && !"".equals(repositoriesXMLFile)) { 689 error(Messages.getErrorString("Kettle.ERROR_0017_XML_REPOSITORY_NOT_SUPPORTED")); info(kettleUserAppender.getBuffer().toString()); 691 return null; 692 } 693 694 if (debug) 695 debug(Messages.getString("Kettle.DEBUG_FINDING_REPOSITORY")); RepositoryMeta repositoryMeta = null; 698 try { 699 repositoryMeta = repositoriesMeta.findRepository(repositoryName); 700 } catch (Throwable t) { 701 error(Messages.getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName), t); return null; 703 } 704 705 if (repositoryMeta == null) { 706 error(Messages.getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName)); info(kettleUserAppender.getBuffer().toString()); 708 return null; 709 } 710 711 if (debug) 712 debug(Messages.getString("Kettle.DEBUG_GETTING_REPOSITORY")); Repository repository = null; 714 UserInfo userInfo = null; 715 try { 716 repository = new Repository(logWriter, repositoryMeta, userInfo); 717 } catch (Throwable t) { 718 error(Messages.getErrorString("Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE"), t); return null; 720 } 721 722 if (debug) 724 debug(Messages.getString("Kettle.DEBUG_CONNECTING")); if (repository.connect(getClass().getName())) { 726 try { 727 userInfo = new UserInfo(repository, username, password); 728 } catch (KettleException e) { 729 userInfo = null; 730 } finally { 731 } 732 } else { 733 error(Messages.getErrorString("Kettle.ERROR_0005_LOGIN_FAILED")); info(kettleUserAppender.getBuffer().toString()); 735 return null; 736 } 737 738 if (debug) 740 debug(Messages.getString("Kettle.DEBUG_FINDING_DIRECTORY")); 742 return repository; 743 744 } catch (Throwable e) { 745 error(Messages.getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e); } 747 return null; 748 } 749 750 public void done() { 751 752 } 753 754 public void rowReadEvent(Row row) { 755 } 756 757 public void rowWrittenEvent(Row row) { 758 759 if (results == null) { 760 return; 761 } 762 Object pentahoRow[] = new Object [results.getColumnCount()]; 763 for (int columnNo = 0; columnNo < results.getColumnCount(); columnNo++) { 764 Value value = row.getValue(columnNo); 765 switch (value.getType()) { 766 case Value.VALUE_TYPE_BIGNUMBER: 767 pentahoRow[columnNo] = value.getBigNumber(); 768 break; 769 case Value.VALUE_TYPE_BOOLEAN: 770 pentahoRow[columnNo] = new Boolean (value.getBoolean()); 771 break; 772 case Value.VALUE_TYPE_DATE: 773 pentahoRow[columnNo] = value.getDate(); 774 break; 775 case Value.VALUE_TYPE_INTEGER: 776 pentahoRow[columnNo] = new Long (value.getInteger()); 777 break; 778 case Value.VALUE_TYPE_NONE: 779 pentahoRow[columnNo] = value.getString(); 780 break; 781 case Value.VALUE_TYPE_NUMBER: 782 pentahoRow[columnNo] = new Double (value.getNumber()); 783 break; 784 case Value.VALUE_TYPE_STRING: 785 pentahoRow[columnNo] = value.getString(); 786 break; 787 default: 788 pentahoRow[columnNo] = value.getString(); 789 } 790 } 791 results.addRow(pentahoRow); 792 793 } 794 795 } 796 | Popular Tags |