Exemplo n.º 1
0
  /**
   * Create DataSource
   *
   * @param connection connection
   * @return data dource
   */
  @Override
  public DataSource getDataSource(CConnection connection) {
    if (m_ds != null) return m_ds;

    try {
      System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
      // System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL");
      ComboPooledDataSource cpds = new ComboPooledDataSource();
      cpds.setDataSourceName("AdempiereDS");
      cpds.setDriverClass(DRIVER);
      // loads the jdbc driver
      cpds.setJdbcUrl(getConnectionURL(connection));
      cpds.setUser(connection.getDbUid());
      cpds.setPassword(connection.getDbPwd());
      cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
      cpds.setIdleConnectionTestPeriod(1200);
      cpds.setAcquireRetryAttempts(2);
      // cpds.setTestConnectionOnCheckin(true);
      // cpds.setTestConnectionOnCheckout(true);
      // cpds.setCheckoutTimeout(60);

      if (Ini.isClient()) {
        cpds.setInitialPoolSize(1);
        cpds.setMinPoolSize(1);
        cpds.setMaxPoolSize(15);
        cpds.setMaxIdleTimeExcessConnections(1200);
        cpds.setMaxIdleTime(900);
        m_maxbusyconnections = 10;
      } else {
        cpds.setInitialPoolSize(10);
        cpds.setMinPoolSize(5);
        cpds.setMaxPoolSize(150);
        cpds.setMaxIdleTimeExcessConnections(1200);
        cpds.setMaxIdleTime(1200);
        m_maxbusyconnections = 120;
      }

      // the following sometimes kill active connection!
      // cpds.setUnreturnedConnectionTimeout(1200);
      // cpds.setDebugUnreturnedConnectionStackTraces(true);

      m_ds = cpds;
    } catch (Exception ex) {
      m_ds = null;
      // log might cause infinite loop since it will try to acquire database connection again
      // log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex);
      System.err.println("Could not initialise C3P0 Datasource: " + ex.getLocalizedMessage());
    }

    return m_ds;
  } //  getDataSource
Exemplo n.º 2
0
  public Boolean savePreferences(Map<String, String> ctx) {
    CContext cContext = getContext();
    MUser user = MUser.get(cContext);
    MUserPreference preference = user.getPreference();
    String printerName = ctx.get("PrinterName");
    if (printerName != null && printerName.trim().equalsIgnoreCase("")) {
      cContext.setPrinterName(printerName);
      preference.setPrinterName(printerName);
    }
    String autoCommit = ctx.get("AutoCommit");
    if (autoCommit != null) {
      cContext.setAutoCommit(autoCommit.trim().equalsIgnoreCase("Y"));
      preference.setIsAutoCommit(autoCommit.trim().equalsIgnoreCase("Y"));
    }
    String showAdvanced = ctx.get("#ShowAdvanced");
    if (showAdvanced != null) {
      cContext.setContext("#ShowAdvanced", showAdvanced);
      preference.setIsShowAdvanced(showAdvanced.trim().equalsIgnoreCase("Y"));
    }
    String showAccounting = ctx.get("#ShowAcct");
    if (showAccounting != null) {
      cContext.setContext("#ShowAcct", showAccounting);
      preference.setIsShowAcct(showAccounting.trim().equalsIgnoreCase("Y"));
    }
    String showTranslation = ctx.get("#ShowTrl");
    if (showTranslation != null) {
      cContext.setContext("#ShowTrl", showTranslation);
      preference.setIsShowTrl(showTranslation.trim().equalsIgnoreCase("Y"));
    }
    String uiTheme = ctx.get("#UITheme");
    if (uiTheme != null && !uiTheme.trim().equalsIgnoreCase("")) {
      cContext.setContext("#UITheme", uiTheme);
      preference.setUITheme(uiTheme);
    }

    String printPreview = ctx.get("#PrintPreview");
    if (printPreview != null) {
      cContext.setPrintPreview(printPreview.equalsIgnoreCase("Y"));
      Ini.setProperty(Ini.P_PRINTPREVIEW, printPreview.equalsIgnoreCase("Y"));
      Ini.saveProperties(Ini.isClient());
    }

    String date = ctx.get("#Date");
    cContext.setContext("#Date", date);

    return preference.save();
  }
Exemplo n.º 3
0
  /**
   * Invoke the form VCreateFromPackage
   *
   * @param ctx context
   * @param WindowNo window no
   * @param mTab tab
   * @param mField field
   * @param value value
   * @return null or error message
   */
  public String createFrom(
      final Properties ctx,
      final int WindowNo,
      final GridTab mTab,
      final GridField mField,
      final Object value) {

    final I_C_Invoice invoice = InterfaceWrapperHelper.create(mTab, I_C_Invoice.class);
    if (invoice.getC_Invoice_ID() <= 0) {
      return "";
    }
    final I_C_DocType dt = invoice.getC_DocTypeTarget();

    if (!Constants.DOCBASETYPE_AEInvoice.equals(dt.getDocBaseType())
        || !CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION.equals(
            dt.getDocSubType())) {
      // nothing to do
      final IDocumentPA docPA = Services.get(IDocumentPA.class);
      final I_C_DocType dtCorr =
          docPA.retrieve(
              ctx,
              invoice.getAD_Org_ID(),
              Constants.DOCBASETYPE_AEInvoice,
              CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION,
              true,
              null);
      if (dtCorr != null) {
        final String msg =
            Msg.getMsg(
                ctx, MSG_INVOICECORR_CREATEFROM_WRONG_DOCTYPE_1P, new Object[] {dtCorr.getName()});
        return msg;
      } else {
        throw new AdempiereException(
            "Missing C_DocType with DocBaseType='"
                + Constants.DOCBASETYPE_AEInvoice
                + "' and DocSubType='"
                + CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION
                + "'");
      }
    }

    final String swingclassname = "de.metas.commission.form.VCreateCorrections";
    final String zkclassname = "not.yet.implemented";
    final String classname;
    if (Ini.isClient()) {
      classname = swingclassname;
    } else {
      classname = zkclassname;
      return "";
    }

    ICreateFrom cf = null;
    Class cl;
    try {
      if (Ini.isClient()) {
        cl = Class.forName(classname);
      } else {
        cl = Thread.currentThread().getContextClassLoader().loadClass(classname);
      }
    } catch (final ClassNotFoundException e) {
      log.error(e.getLocalizedMessage(), e);
      return e.getLocalizedMessage();
    }
    if (cl != null) {
      try {
        java.lang.reflect.Constructor<? extends ICreateFrom> ctor =
            cl.getConstructor(I_C_Invoice.class, int.class);
        cf = ctor.newInstance(invoice, WindowNo);
      } catch (Throwable e) {
        log.error(e.getLocalizedMessage(), e);
        return e.getLocalizedMessage();
      }
    }

    if (cf != null) {
      if (cf.isInitOK()) {
        cf.showWindow();
        cf.closeWindow();
        mTab.dataRefresh();
      } else cf.closeWindow();
    }

    return "";
  } // createShippingPackages