private TypeHandler resolveTypeHandler(
      TypeHandlerFactory typeHandlerFactory,
      Class clazz,
      String propertyName,
      String javaType,
      String jdbcType) {
    try { // 我加上的
      DEBUG.P(this, "resolveTypeHandler(5)");

      TypeHandler handler = null;
      if (clazz == null) {
        // Unknown
        handler = typeHandlerFactory.getUnkownTypeHandler();
      } else if (DomTypeMarker.class.isAssignableFrom(clazz)) {
        // DOM
        handler = typeHandlerFactory.getTypeHandler(String.class, jdbcType);
      } else if (java.util.Map.class.isAssignableFrom(clazz)) {
        // Map
        if (javaType == null) {
          handler =
              typeHandlerFactory
                  .getUnkownTypeHandler(); // BUG 1012591 -
                                           // typeHandlerFactory.getTypeHandler(java.lang.Object.class, jdbcType);
        } else {
          try {
            javaType = typeHandlerFactory.resolveAlias(javaType);
            Class javaClass = Resources.classForName(javaType);
            handler = typeHandlerFactory.getTypeHandler(javaClass, jdbcType);
          } catch (Exception e) {
            throw new SqlMapException("Error.  Could not set TypeHandler.  Cause: " + e, e);
          }
        }
      } else if (typeHandlerFactory.getTypeHandler(clazz, jdbcType) != null) {
        // Primitive
        handler = typeHandlerFactory.getTypeHandler(clazz, jdbcType);
      } else {
        // JavaBean
        if (javaType == null) {

          Class type = PROBE.getPropertyTypeForGetter(clazz, propertyName);
          handler = typeHandlerFactory.getTypeHandler(type, jdbcType);

        } else {
          try {
            javaType = typeHandlerFactory.resolveAlias(javaType);
            Class javaClass = Resources.classForName(javaType);
            handler = typeHandlerFactory.getTypeHandler(javaClass, jdbcType);
          } catch (Exception e) {
            throw new SqlMapException("Error.  Could not set TypeHandler.  Cause: " + e, e);
          }
        }
      }
      return handler;

    } finally { // 我加上的
      DEBUG.P(0, this, "resolveTypeHandler(5)");
    }
  }
Beispiel #2
0
  public static void init(JPasswordField fpasswd) {
    try {
      String resource = "artemis_sqlmap/chado_iBatis_config.xml";
      Reader reader = Resources.getResourceAsReader(resource);

      Properties properties = null;
      if (System.getProperty("chado") != null) {
        String url = System.getProperty("chado");
        int index = url.indexOf("?");
        int index2 = url.indexOf("user="******"://");
        if (index3 < 0) index3 = 0;
        else index3 = index3 + 3;

        properties.put("chado", url.substring(index3, index));

        if (index2 < 0) properties.put("username", url.substring(index + 1));
        else properties.put("username", url.substring(index2 + 5));

        if (fpasswd != null && fpasswd.getPassword().length > 0)
          properties.put("password", new String(fpasswd.getPassword()));
      }

      sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, properties);
    } catch (Exception e) {
      // If you get an error at this point, it doesnt matter what it was.  It is going to be
      // unrecoverable and we will want the app to blow up hard so we are aware of the
      // problem.  You should always log such errors and re-throw them in such a way that
      // you can be made immediately aware of the problem.
      e.printStackTrace();
      throw new RuntimeException("Error initializing DbSqlConfig class.  Cause: " + e);
    }
  }
Beispiel #3
0
  // 생성자
  public writeAction() throws IOException {

    reader = Resources.getResourceAsReader("sqlMapConfig.xml"); // sqlMapConfig.xml 파일의 설정내용을 가져온다.
    sqlMapper =
        SqlMapClientBuilder.buildSqlMapClient(reader); // sqlMapConfig.xml의 내용을 적용한 sqlMapper 객체 생성.
    reader.close();
  }
  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws IOException {

    String config = "sqlMapConfig.xml";

    Reader reader = Resources.getResourceAsReader(config);
    SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
    ClusterViewModel cViewModel = new ClusterViewModel();
    cViewModel.setId(Rpid.generate());
    try {
      sqlMap.insert("insertClusterViewModel", cViewModel);
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    List<ClusterViewModel> list;
    try {
      list = sqlMap.queryForList("checkFromCluster");
      for (ClusterViewModel clusterViewModel : list) {
        System.out.println(clusterViewModel);
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 /*
  * Required by interface
  *
  * @param properties required by interface
  * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
  */
 public void configure(Properties properties) {
   try {
     Reader reader = null;
     if (properties.containsKey("SqlMapConfigURL")) {
       reader = Resources.getUrlAsReader((String) properties.get("SqlMapConfigURL"));
     } else if (properties.containsKey("SqlMapConfigResource")) {
       reader = Resources.getResourceAsReader((String) properties.get("SqlMapConfigResource"));
     } else {
       throw new DaoException(
           "SQLMAP transaction manager requires either 'SqlMapConfigURL' or 'SqlMapConfigResource' to be specified as a property.");
     }
     client = SqlMapClientBuilder.buildSqlMapClient(reader, properties);
   } catch (IOException e) {
     throw new DaoException("Error configuring SQL Map.  Cause: " + e);
   }
 }
Beispiel #6
0
 public static void main(String[] args) throws IOException, SQLException {
   String resource = "ibatis/sqlmap-config.xml";
   Reader reader = Resources.getResourceAsReader(resource);
   SqlMapClient sqlmap = SqlMapClientBuilder.buildSqlMapClient(reader);
   HashMap<String, String> param = new HashMap<String, String>();
   param.put("a", "1");
   Object obj = sqlmap.queryForObject("testSelectAs", param);
   System.out.println(obj);
 }
 static {
   try {
     Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
     client = SqlMapClientBuilder.buildSqlMapClient(reader);
   } catch (Exception e) {
     System.out.println("在userdao的static里面出错了");
     e.printStackTrace();
   }
 }
 static {
   try {
     String resource = "SqlMapConfig.xml";
     Reader reader = Resources.getResourceAsReader(resource);
     sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
   } catch (Exception e) {
     e.printStackTrace();
     throw new RuntimeException("Error initializing IbatisHelper class. Cause : " + e);
   }
 }
Beispiel #9
0
 /**
  * Singleton SqlMapClient 객체를 리턴
  *
  * @return SqlMapClient
  */
 public static SqlMapClient getSqlMapClient() {
   if (null == sqlMapClient) {
     try {
       Reader reader = Resources.getResourceAsReader("SqlMapConf.xml");
       sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
       reader.close();
     } catch (Exception e) {
       throw new RuntimeException(
           "Something bad happened while building the SqlMapClient instance." + e, e);
     }
   }
   return sqlMapClient;
 }
  @Before
  public void setUp() throws Exception {

    Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
    SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
    reader.close();

    LegacyBankService legacyBankService = new IBatisLegacyBankService(sqlMapClient);

    KnowledgeBase knowledgeBase = DroolsHelper.createKnowledgeBase("etl-iBatis.drl");

    etlBankService = new DataTransformationServiceImpl();
    // etlBankService.setBankingService(new BankingServiceImpl());
    etlBankService.setLegacyBankService(legacyBankService);
    etlBankService.setReportFactory(new DefaultReportFactory());
    etlBankService.setKnowledgeBase(knowledgeBase);
  }
Beispiel #11
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("{ledger_id}")
  public Ledger getUser(@PathParam("ledger_id") long ledger_id) {
    Ledger objLedger = new Ledger();
    objLedger.setLedger_id(ledger_id);
    try {
      Reader reader = Resources.getResourceAsReader("./dao/SqlMapConfig.xml");
      SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

      objLedger = (Ledger) sqlMap.queryForObject("Ledger.getLedgerById", objLedger);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return objLedger;
  }
Beispiel #12
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/groups")
  public List<AccountGroup> getAccountGroups() {
    List<AccountGroup> objAccountGroupList = null;

    try {
      Reader reader = Resources.getResourceAsReader("./dao/SqlMapConfig.xml");
      SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

      objAccountGroupList =
          (List<AccountGroup>) sqlMap.queryForList("Ledger.getAccountGroups", null);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return objAccountGroupList;
  }
Beispiel #13
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/list/{company_id}/{type}")
  public List<Ledger> getLedgers(
      @PathParam("company_id") long company_id, @PathParam("type") String type) {
    List<Ledger> objLedgerList = null;
    Ledger objLedger = new Ledger();
    objLedger.setCompany_id(company_id);

    try {
      Reader reader = Resources.getResourceAsReader("./dao/SqlMapConfig.xml");
      SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

      if (type.equals("all")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getLedgersByCompanyId", objLedger);
      } else if (type.equals("as")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getAssetsByCompanyId", objLedger);
      } else if (type.equals("li")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getLiabilitiesByCompanyId", objLedger);
      } else if (type.equals("de")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getDirectExpensesByCompanyId", objLedger);
      } else if (type.equals("di")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getDirectIncomeByCompanyId", objLedger);
      } else if (type.equals("ie")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getIndirectExpensesByCompanyId", objLedger);
      } else if (type.equals("ii")) {
        objLedgerList =
            (List<Ledger>) sqlMap.queryForList("Ledger.getIndirectIncomeByCompanyId", objLedger);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return objLedgerList;
  }
Beispiel #14
0
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.TEXT_PLAIN)
  public String insertLedger(Ledger objLedger) {
    try {
      Reader reader = Resources.getResourceAsReader("./dao/SqlMapConfig.xml");
      SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
      Ledger temp = (Ledger) sqlMap.queryForObject("Ledger.getDuplicateLedger", objLedger);
      if (temp != null) {
        return "Sorry, Ledger name already exists.! Kindly try some other name.";
      }

      sqlMap.startTransaction();
      sqlMap.insert("Ledger.insertLedger", objLedger);
      sqlMap.commitTransaction();
      sqlMap.endTransaction();

    } catch (Exception e) {
      e.printStackTrace();
      return "Some problem occured while creating New Ledger. Kindly try again!";
    }
    return "New Ledger created successfully";
  }
Beispiel #15
0
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.TEXT_PLAIN)
  public String updateLedger(Ledger objLedger) {
    try {
      Reader reader = Resources.getResourceAsReader("./dao/SqlMapConfig.xml");
      SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

      Ledger temp = (Ledger) sqlMap.queryForObject("Ledger.getLedgerById", objLedger);
      if (temp == null) {
        return "Ledger can not be identified. Try logging in again.!";
      }

      sqlMap.startTransaction();
      sqlMap.update("Ledger.updateByLedgerId", objLedger);
      sqlMap.commitTransaction();
      sqlMap.endTransaction();
    } catch (Exception e) {
      e.printStackTrace();
      return "Some problem occured while updating Ledger information. Kindly try again!";
    }
    return "Information updated successfully";
  }
  private ParameterMapping newParseMapping(
      String token, Class parameterClass, TypeHandlerFactory typeHandlerFactory) {
    ParameterMapping mapping = new ParameterMapping();

    // #propertyName,javaType=string,jdbcType=VARCHAR,mode=IN,nullValue=N/A,handler=string,numericScale=2#

    StringTokenizer paramParser = new StringTokenizer(token, "=,", false);
    mapping.setPropertyName(paramParser.nextToken());

    while (paramParser.hasMoreTokens()) {
      String field = paramParser.nextToken();
      if (paramParser.hasMoreTokens()) {
        String value = paramParser.nextToken();
        if ("javaType".equals(field)) {
          value = typeHandlerFactory.resolveAlias(value);
          mapping.setJavaTypeName(value);
        } else if ("jdbcType".equals(field)) {
          mapping.setJdbcTypeName(value);
        } else if ("mode".equals(field)) {
          mapping.setMode(value);
        } else if ("nullValue".equals(field)) {
          mapping.setNullValue(value);
        } else if ("handler".equals(field)) {
          try {
            value = typeHandlerFactory.resolveAlias(value);
            Object impl = Resources.instantiate(value);
            if (impl instanceof TypeHandlerCallback) {
              mapping.setTypeHandler(new CustomTypeHandler((TypeHandlerCallback) impl));
            } else if (impl instanceof TypeHandler) {
              mapping.setTypeHandler((TypeHandler) impl);
            } else {
              throw new SqlMapException(
                  "The class "
                      + value
                      + " is not a valid implementation of TypeHandler or TypeHandlerCallback");
            }
          } catch (Exception e) {
            throw new SqlMapException(
                "Error loading class specified by handler field in " + token + ".  Cause: " + e, e);
          }
        } else if ("numericScale".equals(field)) {
          try {
            Integer numericScale = Integer.valueOf(value);
            if (numericScale.intValue() < 0) {
              throw new SqlMapException(
                  "Value specified for numericScale must be greater than or equal to zero");
            }
            mapping.setNumericScale(numericScale);
          } catch (NumberFormatException e) {
            throw new SqlMapException("Value specified for numericScale is not a valid Integer");
          }
        } else {
          throw new SqlMapException(
              "Unrecognized parameter mapping field: '" + field + "' in " + token);
        }
      } else {
        throw new SqlMapException(
            "Incorrect inline parameter map format (missmatched name=value pairs): " + token);
      }
    }

    if (mapping.getTypeHandler() == null) {
      TypeHandler handler;
      if (parameterClass == null) {
        handler = typeHandlerFactory.getUnkownTypeHandler();
      } else {
        handler =
            resolveTypeHandler(
                typeHandlerFactory,
                parameterClass,
                mapping.getPropertyName(),
                mapping.getJavaTypeName(),
                mapping.getJdbcTypeName());
      }
      mapping.setTypeHandler(handler);
    }

    return mapping;
  }
Beispiel #17
0
 public MainBean() throws Exception {
   reader = Resources.getResourceAsReader("sqlMapConfig.xml");
   sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
   reader.close();
 }
 // DB커넥트 생성자
 public ImprovementCaseEdit() throws IOException {
   reader = Resources.getResourceAsReader("sqlMapConfig.xml");
   sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
   reader.close();
 }
 // DB커넥트 생성자
 public TrainingEventView() throws IOException {
   reader = Resources.getResourceAsReader("sqlMapConfig.xml");
   sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
   reader.close();
 }