List of usage examples for org.apache.commons.beanutils BasicDynaClass newInstance
public DynaBean newInstance() throws IllegalAccessException, InstantiationException
From source file:com.xpfriend.fixture.cast.temp.DynaBeanFactory.java
@SuppressWarnings("unchecked") protected <T> T createObject(Class<? extends T> cls, Table table, Row row) { try {// w ww . ja v a2 s . com BasicDynaClass dynaClass = getDynaClass(table); DynaBean bean = dynaClass.newInstance(); setProperties(table, row, bean); return (T) bean; } catch (Exception e) { throw new ConfigException(e); } }
From source file:junit.mock.TestDynaPropertiesMO.java
private DynaBean createDynaBean() throws Exception { DynaProperty[] props = new DynaProperty[] { new DynaProperty("id", String.class), new DynaProperty("responsetime", Long.class) }; BasicDynaClass dynaClass = new BasicDynaClass("requesttime", null, props); DynaBean bean = dynaClass.newInstance(); bean.set("id", "12345"); bean.set("responsetime", new Long(500)); return bean;//from w w w. j a v a2 s. co m }
From source file:com.manning.junitbook.ch14.servlets.TestAdminServlet.java
/** * Creates a java.util.Collection of DynaBean objects to show in the JSP. * //from w w w . j av a 2s .com * @return * @throws Exception */ private Collection<DynaBean> createCommandResult() throws Exception { List<DynaBean> results = new ArrayList<DynaBean>(); DynaProperty[] props = new DynaProperty[] { new DynaProperty("id", String.class), new DynaProperty("responsetime", Long.class) }; BasicDynaClass dynaClass = new BasicDynaClass("requesttime", null, props); DynaBean request1 = dynaClass.newInstance(); request1.set("id", "12345"); request1.set("responsetime", new Long(500)); results.add(request1); DynaBean request2 = dynaClass.newInstance(); request1.set("id", "56789"); request1.set("responsetime", new Long(430)); results.add(request2); return results; }
From source file:net.mlw.vlh.adapter.jdbc.dynabean.DefaultDynaBeanAdapter.java
public List processResultSet(String name, ResultSet result, int numberPerPage, ValueListInfo info) throws SQLException { List list = new ArrayList(); ResultSetDynaClass rsdc = new ResultSetDynaClass(result, false, isUseName()); BasicDynaClass bdc = new BasicDynaClass(name, BasicDynaBean.class, rsdc.getDynaProperties()); int rowIndex = 0; for (Iterator rows = rsdc.iterator(); rows.hasNext() && rowIndex < numberPerPage; rowIndex++) { try {// w ww .ja va2 s .c om DynaBean oldRow = (DynaBean) rows.next(); DynaBean newRow = bdc.newInstance(); DynaProperty[] properties = oldRow.getDynaClass().getDynaProperties(); for (int i = 0, length = properties.length; i < length; i++) { String propertyName = properties[i].getName(); Object value = oldRow.get(propertyName); newRow.set(propertyName, value); } list.add(newRow); } catch (Exception e) { LOGGER.error(e); } } return list; }
From source file:com.feilong.commons.core.bean.BeanUtilTest.java
/** * Demo dyna beans.// w ww . jav a 2s .c o m * * @throws Exception * the exception */ @Test public void demoDynaBeans() throws Exception { log.debug(StringUtils.center(" demoDynaBeans ", 40, "=")); // creating a DynaBean DynaProperty[] dynaBeanProperties = new DynaProperty[] { //DynaProperty new DynaProperty("name", String.class), new DynaProperty("inPrice", Double.class), new DynaProperty("outPrice", Double.class), }; BasicDynaClass cargoClass = new BasicDynaClass("Cargo", BasicDynaBean.class, dynaBeanProperties); //BasicDynaClass BasicDynaBean DynaBean cargo = cargoClass.newInstance();//DynaBean // accessing a DynaBean cargo.set("name", "Instant Noodles"); cargo.set("inPrice", new Double(21.3)); cargo.set("outPrice", new Double(23.8)); log.debug("name: " + cargo.get("name")); log.debug("inPrice: " + cargo.get("inPrice")); log.debug("outPrice: " + cargo.get("outPrice")); }
From source file:org.agnitas.dao.impl.MailingDaoImpl.java
public PaginatedList getMailingList(int companyID, String types, boolean isTemplate, String sort, String direction, int page, int rownums) { JdbcTemplate aTemplate = new JdbcTemplate((DataSource) applicationContext.getBean("dataSource")); List<String> charColumns = Arrays.asList(new String[] { "shortname", "description", "mailinglist" }); int offset = (page - 1) * rownums; String mailingTypes = " AND mailing_type in (" + types + ") "; if (isTemplate) { mailingTypes = " "; }/* w w w .jav a 2s . c o m*/ String orderby = null; String defaultorder = " send_null ASC, senddate DESC, mailing_id DESC "; if (sort != null && !"".equals(sort.trim())) { orderby = getUpperSort(charColumns, sort); orderby = orderby + " " + direction; } else { orderby = defaultorder; } String sqlStatement = " SELECT *, case when senddate is null then 0 else 1 end as send_null " + " FROM ( SELECT a.mailing_id , a.shortname , a.description , min(c." + AgnUtils.changeDateName() + ") senddate, m.shortname mailinglist " + " FROM (mailing_tbl a LEFT JOIN mailing_account_tbl c ON (a.mailing_id=c.mailing_id AND c.status_field='W')) " + " LEFT JOIN mailinglist_tbl m ON ( a.mailinglist_id=m.mailinglist_id AND a.company_id=m.company_id) " + " WHERE a.company_id = " + companyID + " AND a.deleted<>1 AND a.is_template=" + (isTemplate ? 1 : 0) + mailingTypes + " GROUP BY a.mailing_id, a.shortname, a.description, m.shortname ) openemm ORDER BY " + orderby; int totalsize = aTemplate.queryForInt("select count(*) from ( " + sqlStatement + ") agn"); sqlStatement = sqlStatement + " LIMIT " + offset + " , " + rownums; List<Map> tmpList = aTemplate.queryForList(sqlStatement); DynaProperty[] properties = new DynaProperty[] { new DynaProperty("mailingid", Long.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class), new DynaProperty("mailinglist", String.class), new DynaProperty("senddate", Timestamp.class) }; BasicDynaClass dynaClass = new BasicDynaClass("mailing", null, properties); List<DynaBean> result = new ArrayList<DynaBean>(); for (Map row : tmpList) { DynaBean newBean; try { newBean = dynaClass.newInstance(); newBean.set("mailingid", row.get("MAILING_ID")); newBean.set("shortname", row.get("SHORTNAME")); newBean.set("description", row.get("DESCRIPTION")); newBean.set("mailinglist", row.get("MAILINGLIST")); newBean.set("senddate", row.get("SENDDATE")); result.add(newBean); } catch (IllegalAccessException e) { AgnUtils.logger().error("IllegalAccessException: " + e); AgnUtils.logger().error(AgnUtils.getStackTrace(e)); } catch (InstantiationException e) { AgnUtils.logger().error("InstantiationException: " + e); AgnUtils.logger().error(AgnUtils.getStackTrace(e)); } } DynaBeanPaginatedListImpl paginatedList = new DynaBeanPaginatedListImpl(result, totalsize, rownums, page, sort, direction); return paginatedList; }
From source file:org.agnitas.dao.impl.RecipientDaoImpl.java
@Override public PaginatedListImpl<DynaBean> getRecipientList(Set<String> columns, String sqlStatementForCount, Object[] parametersForsCount, String sqlStatementForRows, Object[] parametersForsRows, String sort, String direction, int page, int rownums, int previousFullListSize) throws IllegalAccessException, InstantiationException { JdbcTemplate aTemplate = new JdbcTemplate((DataSource) this.applicationContext.getBean("dataSource")); int totalRows = aTemplate.queryForInt(sqlStatementForCount, parametersForsCount); if (previousFullListSize == 0 || previousFullListSize != totalRows) { page = 1;/*from w ww .j a va 2 s . c o m*/ } page = AgnUtils.getValidPageNumber(totalRows, page, rownums); String sortClause = ""; if (!StringUtils.isBlank(sort)) { sortClause = " ORDER BY " + "lower(" + sort + ")"; if (!StringUtils.isEmpty(direction)) { sortClause = sortClause + " " + direction; } } int offset = (page - 1) * rownums; if (AgnUtils.isOracleDB()) { sqlStatementForRows = "SELECT * from ( select " + StringUtils.join(columns, ", ") + ", rownum r from ( " + sqlStatementForRows + " ) where 1 = 1 " + sortClause + ") where r between " + (offset + 1) + " and " + (offset + rownums); } else { sqlStatementForRows = sqlStatementForRows + sortClause + " LIMIT " + offset + " , " + rownums; } @SuppressWarnings("unchecked") List<Map<String, Object>> tmpList = aTemplate.queryForList(sqlStatementForRows, parametersForsRows); List<DynaBean> result = new ArrayList<DynaBean>(); if (tmpList != null && !tmpList.isEmpty()) { DynaProperty[] properties = new DynaProperty[columns.size()]; int i = 0; for (String c : columns) { properties[i++] = new DynaProperty(c.toLowerCase(), String.class); } BasicDynaClass dynaClass = new BasicDynaClass("recipient", null, properties); for (Map<String, Object> row : tmpList) { DynaBean bean = dynaClass.newInstance(); for (String c : columns) { bean.set(c.toLowerCase(), row.get(c.toUpperCase()) != null ? row.get(c.toUpperCase()).toString() : ""); } result.add(bean); } } PaginatedListImpl<DynaBean> paginatedList = new PaginatedListImpl<DynaBean>(result, totalRows, rownums, page, sort, direction); return paginatedList; }
From source file:org.agnitas.web.CampaignAction.java
/** * loads the campaigns//from w ww.j ava 2 s .c o m * @throws InstantiationException * @throws IllegalAccessException * * */ public List<DynaBean> getCampaignList(HttpServletRequest request) throws IllegalAccessException, InstantiationException { ApplicationContext aContext = getWebApplicationContext(); JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource")); List<Integer> charColumns = Arrays.asList(new Integer[] { 0, 1 }); String[] columns = new String[] { "shortname", "description", "" }; int sortcolumnindex = 0; if (request.getParameter( new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_SORT)) != null) { sortcolumnindex = Integer.parseInt(request.getParameter( new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_SORT))); } String sort = columns[sortcolumnindex]; if (charColumns.contains(sortcolumnindex)) { sort = "upper( " + sort + " )"; } int order = 1; if (request.getParameter( new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_ORDER)) != null) { order = new Integer(request.getParameter( new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_ORDER))); } String sqlStatement = "SELECT campaign_id, shortname, description FROM campaign_tbl WHERE company_id=" + AgnUtils.getCompanyID(request) + " ORDER BY " + sort + " " + (order == 2 ? "DESC" : "ASC"); List<Map> tmpList = aTemplate.queryForList(sqlStatement); DynaProperty[] properties = new DynaProperty[] { new DynaProperty("campaignId", Integer.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class) }; if (AgnUtils.isOracleDB()) { properties = new DynaProperty[] { new DynaProperty("campaignId", BigDecimal.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class) }; } BasicDynaClass dynaClass = new BasicDynaClass("campaign", null, properties); List<DynaBean> result = new ArrayList<DynaBean>(); for (Map row : tmpList) { DynaBean newBean = dynaClass.newInstance(); newBean.set("campaignId", row.get("CAMPAIGN_ID")); newBean.set("shortname", row.get("SHORTNAME")); newBean.set("description", row.get("DESCRIPTION")); result.add(newBean); } return result; }
From source file:org.agnitas.web.EmmActionAction.java
public List<DynaBean> getActionList(HttpServletRequest request) throws IllegalAccessException, InstantiationException { ApplicationContext aContext = getWebApplicationContext(); JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource")); List<Integer> charColumns = Arrays.asList(new Integer[] { 0, 1 }); String[] columns = new String[] { "r.shortname", "r.description", "", "" }; int sortcolumnindex = 0; if (request.getParameter( new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT)) != null) { sortcolumnindex = Integer.parseInt(request.getParameter( new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT))); }//from w w w . j av a 2 s .c o m String sort = columns[sortcolumnindex]; if (charColumns.contains(sortcolumnindex)) { sort = "upper( " + sort + " )"; } int order = 1; if (request.getParameter( new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER)) != null) { order = new Integer(request.getParameter( new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER))); } String sqlStatement = "SELECT r.action_id, r.shortname, r.description, count(u.form_id) used " + " FROM rdir_action_tbl r LEFT JOIN userform_tbl u ON (u.startaction_id = r.action_id or u.endaction_id = r.action_id) " + " WHERE r.company_id= " + AgnUtils.getCompanyID(request) + " GROUP BY r.action_id, r.shortname, r.description " + " ORDER BY " + sort + " " + (order == 1 ? "ASC" : "DESC"); List<Map> tmpList = aTemplate.queryForList(sqlStatement); DynaProperty[] properties = new DynaProperty[] { new DynaProperty("actionId", Long.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class), new DynaProperty("used", Long.class) }; if (AgnUtils.isOracleDB()) { properties = new DynaProperty[] { new DynaProperty("actionId", BigDecimal.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class), new DynaProperty("used", BigDecimal.class) }; } BasicDynaClass dynaClass = new BasicDynaClass("emmaction", null, properties); List<DynaBean> result = new ArrayList<DynaBean>(); for (Map row : tmpList) { DynaBean newBean = dynaClass.newInstance(); newBean.set("actionId", row.get("ACTION_ID")); newBean.set("shortname", row.get("SHORTNAME")); newBean.set("description", row.get("DESCRIPTION")); newBean.set("used", row.get("USED")); result.add(newBean); } return result; }
From source file:org.agnitas.web.MailingStatAction.java
public List<DynaBean> getMailingStats(HttpServletRequest request) throws IllegalAccessException, InstantiationException { ApplicationContext aContext = getWebApplicationContext(); JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource")); String sqlStatement = "SELECT a.mailing_id, a.shortname, a.description, b.shortname AS listname " + "FROM mailing_tbl a, mailinglist_tbl b WHERE a.company_id=" + AgnUtils.getCompanyID(request) + " " + "AND a.mailinglist_id=b.mailinglist_id AND a.deleted=0 AND a.is_template=0 ORDER BY mailing_id DESC"; List<Map> tmpList = aTemplate.queryForList(sqlStatement); DynaProperty[] properties = new DynaProperty[] { new DynaProperty("mailingid", Long.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class), new DynaProperty("listname", String.class), }; if (AgnUtils.isOracleDB()) { properties = new DynaProperty[] { new DynaProperty("mailingid", BigDecimal.class), new DynaProperty("shortname", String.class), new DynaProperty("description", String.class), new DynaProperty("listname", String.class), }; }//from w w w . ja v a 2 s.c o m BasicDynaClass dynaClass = new BasicDynaClass("mailingstat", null, properties); List<DynaBean> result = new ArrayList<DynaBean>(); for (Map row : tmpList) { DynaBean newBean = dynaClass.newInstance(); newBean.set("mailingid", row.get("MAILING_ID")); newBean.set("shortname", row.get("SHORTNAME")); newBean.set("description", row.get("DESCRIPTION")); newBean.set("listname", row.get("LISTNAME")); result.add(newBean); } return result; }