Java 类org.apache.commons.beanutils.DynaBean 实例源码

项目:OSCAR-ConCert    文件:BillingreferralEditAction.java   
public ActionForward searchByName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    DynaBean lazyForm = (DynaBean) form;
    String name = (String)lazyForm.get("search");

    String last_name="",first_name="";
    if (name != null && !name.equals("")) {
        if (name.indexOf(',') < 0) {
            last_name = name;
        } else {
            name = name.substring(0, name.indexOf(','));
            first_name = name.substring(name.indexOf(',') + 1, name.length());
        }
    }

    List<ProfessionalSpecialist> referrals = psDao.findByFullName(last_name, first_name);
    request.setAttribute("referrals", referrals);
    request.setAttribute("searchBy", "searchByName");

    return mapping.findForward("list");
}
项目:OSCAR-ConCert    文件:SitesManageAction.java   
public ActionForward addRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    DynaBean lazyForm = (DynaBean) form;

    Site site = (Site) lazyForm.get("site");

    String roleId = request.getParameter("roleId");
    String roleType = request.getParameter("roleType");

    SuperSiteUtil superSiteUtil = (SuperSiteUtil) SpringUtils.getBean("superSiteUtil");
    SiteRoleMpgDao siteRoleMpgDao = SpringUtils.getBean(SiteRoleMpgDao.class);

    if(roleType!=null)
    {
        if(roleType.equalsIgnoreCase("access"))
            siteRoleMpgDao.addAccessRoleToSite(site.getId(), Integer.parseInt(roleId));
        else if(roleType.equalsIgnoreCase("admit_discharge"))
            siteRoleMpgDao.addAdmitDischargeRoleToSite(site.getId(), Integer.parseInt(roleId));
    }

    request.setAttribute("siteId", site.getId()+"");
    lazyForm.set("site", site);
    return mapping.findForward("details");
}
项目:OSCAR-ConCert    文件:SitesManageAction.java   
public ActionForward deleteRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    DynaBean lazyForm = (DynaBean) form;

    Site site = (Site) lazyForm.get("site");

    String roleId = request.getParameter("roleId");
    String roleType = request.getParameter("roleType");

    SuperSiteUtil superSiteUtil = (SuperSiteUtil) SpringUtils.getBean("superSiteUtil");
    SiteRoleMpgDao siteRoleMpgDao = SpringUtils.getBean(SiteRoleMpgDao.class);

    if(roleType!=null)
    {
        if(roleType.equalsIgnoreCase("access"))
            siteRoleMpgDao.deleteAccessRoleFromSite(site.getId(), Integer.parseInt(roleId));
        else if(roleType.equalsIgnoreCase("admit_discharge"))
            siteRoleMpgDao.deleteAdmitDischargeRoleToSite(site.getId(), Integer.parseInt(roleId));
    }

    request.setAttribute("siteId", site.getId()+"");
    lazyForm.set("site", site);
    return mapping.findForward("details");
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * Creates the SQL for updating an object of the given type. If a concrete bean is given,
 * then a concrete update statement is created, otherwise an update statement usable in a
 * prepared statement is build.
 * 
 * @param model       The database model
 * @param dynaClass   The type
 * @param primaryKeys The primary keys
 * @param properties  The properties to write
 * @param oldBean     Contains column values to identify the rows to update (i.e. for the WHERE clause)
 * @param newBean     Contains the new column values to write
 * @return The SQL required to update the instance
 */
protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, DynaBean oldBean, DynaBean newBean)
{
    Table   table           = model.findTable(dynaClass.getTableName());
    HashMap oldColumnValues = toColumnValues(primaryKeys, oldBean);
    HashMap newColumnValues = toColumnValues(properties, newBean);

    if (primaryKeys.length == 0)
    {
        _log.info("Cannot update instances of type " + dynaClass + " because it has no primary keys");
        return null;
    }
    else
    {
        return _builder.getUpdateSql(table, oldColumnValues, newColumnValues, newBean == null);
    }
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public String getUpdateSql(Database model, DynaBean dynaBean)
{
    SqlDynaClass      dynaClass      = model.getDynaClassFor(dynaBean);
    SqlDynaProperty[] primaryKeys    = dynaClass.getPrimaryKeyProperties();
    SqlDynaProperty[] nonPrimaryKeys = dynaClass.getNonPrimaryKeyProperties();

    if (primaryKeys.length == 0)
    {
        _log.info("Cannot update instances of type " + dynaClass + " because it has no primary keys");
        return null;
    }
    else
    {
        return createUpdateSql(model, dynaClass, primaryKeys, nonPrimaryKeys, dynaBean);
    }
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public String getDeleteSql(Database model, DynaBean dynaBean)
{
    SqlDynaClass      dynaClass   = model.getDynaClassFor(dynaBean);
    SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();

    if (primaryKeys.length == 0)
    {
        _log.warn("Cannot delete instances of type " + dynaClass + " because it has no primary keys");
        return null;
    }
    else
    {
        return createDeleteSql(model, dynaClass, primaryKeys, dynaBean);
    }
}
项目:gemfirexd-oss    文件:DataWriter.java   
/**
 * Writes the beans contained in the given iterator.
 * 
 * @param beans The beans iterator
 */
public void write(Iterator beans) throws DataWriterException
{
    while (beans.hasNext())
    {
        DynaBean bean = (DynaBean)beans.next();

        if (bean instanceof SqlDynaBean)
        {
            write((SqlDynaBean)bean);
        }
        else
        {
            _log.warn("Cannot write normal dyna beans (type: "+bean.getDynaClass().getName()+")");
        }
    }
}
项目:gemfirexd-oss    文件:DataToDatabaseSink.java   
/**
 * Builds an identity object for the specified foreign key using the foreignkey column values
 * of the supplied bean.
 * 
 * @param owningTable The table owning the foreign key
 * @param fk          The foreign key
 * @param bean        The bean
 * @return The identity
 */
private Identity buildIdentityFromFK(Table owningTable, ForeignKey fk, DynaBean bean)
{
    Identity identity = new Identity(fk.getForeignTable(), getFKName(owningTable, fk));

    for (int idx = 0; idx < fk.getReferenceCount(); idx++)
    {
        Reference reference = (Reference)fk.getReference(idx);
        Object    value     = bean.get(reference.getLocalColumnName());

        if (value == null)
        {
            return null;
        }
        identity.setColumnValue(reference.getForeignColumnName(), value);
    }
    return identity;
}
项目:gemfirexd-oss    文件:TestPlatformImplBase.java   
/**
 * Test the toColumnValues method.
 */
public void testToColumnValues()
{
    final String schema =
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='id' autoIncrement='true' type='INTEGER' primaryKey='true'/>\n"+
        "    <column name='name' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>";

    Database         database = parseDatabaseFromString(schema);
    PlatformImplBase platform = new TestPlatform();
    Table            table    = database.getTable(0);
    SqlDynaClass     clz      = SqlDynaClass.newInstance(table);
    DynaBean         db       = new SqlDynaBean(SqlDynaClass.newInstance(table));

    db.set("name", "name");

    Map map = platform.toColumnValues(clz.getSqlDynaProperties(), db);

    assertEquals("name",
                 map.get("name"));
    assertTrue(map.containsKey("id"));
}
项目:gemfirexd-oss    文件:TestAgainstLiveDatabaseBase.java   
/**
 * Determines the value of the bean's property that has the given name. Depending on the
 * case-setting of the current builder, the case of teh name is considered or not. 
 * 
 * @param bean     The bean
 * @param propName The name of the property
 * @return The value
 */
protected Object getPropertyValue(DynaBean bean, String propName)
{
    if (getPlatform().isDelimitedIdentifierModeOn())
    {
        return bean.get(propName);
    }
    else
    {
        DynaProperty[] props = bean.getDynaClass().getDynaProperties();

        for (int idx = 0; idx < props.length; idx++)
        {
            if (propName.equalsIgnoreCase(props[idx].getName()))
            {
                return bean.get(props[idx].getName());
            }
        }
        throw new IllegalArgumentException("The bean has no property with the name "+propName);
    }
}
项目:gemfirexd-oss    文件:TestAgainstLiveDatabaseBase.java   
/**
 * Compares the specified attribute value of the given bean with the expected object.
 * 
 * @param expected The expected object
 * @param bean     The bean
 * @param attrName The attribute name
 */
protected void assertEquals(Object expected, Object bean, String attrName)
{
    DynaBean dynaBean = (DynaBean)bean;
    Object   value    = dynaBean.get(attrName);

    if ((value instanceof byte[]) && !(expected instanceof byte[]) && (dynaBean instanceof SqlDynaBean))
    {
        SqlDynaClass dynaClass = (SqlDynaClass)((SqlDynaBean)dynaBean).getDynaClass();
        Column       column    = ((SqlDynaProperty)dynaClass.getDynaProperty(attrName)).getColumn();

        if (TypeMap.isBinaryType(column.getTypeCode()))
        {
            value = new BinaryObjectsHelper().deserialize((byte[])value);
        }
    }
    if (expected == null)
    {
        assertNull(value);
    }
    else
    {
        assertEquals(expected, value);
    }
}
项目:NotifyTools    文件:LocaleBeanUtilsBean.java   
/**
 * Calculate the property type.
 *
 * @param target The bean
 * @param name The property name
 * @param propName The Simple name of target property
 * @return The property's type
 *
 * @throws IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @throws InvocationTargetException if the property accessor method
 *  throws an exception
 */
protected Class<?> definePropertyType(final Object target, final String name, final String propName)
        throws IllegalAccessException, InvocationTargetException {

    Class<?> type = null;               // Java type of target property

    if (target instanceof DynaBean) {
        final DynaClass dynaClass = ((DynaBean) target).getDynaClass();
        final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
        if (dynaProperty == null) {
            return null; // Skip this property setter
        }
        type = dynaProperty.getType();
    }
    else {
        PropertyDescriptor descriptor = null;
        try {
            descriptor =
                    getPropertyUtils().getPropertyDescriptor(target, name);
            if (descriptor == null) {
                return null; // Skip this property setter
            }
        }
        catch (final NoSuchMethodException e) {
            return null; // Skip this property setter
        }
        if (descriptor instanceof MappedPropertyDescriptor) {
            type = ((MappedPropertyDescriptor) descriptor).
                    getMappedPropertyType();
        }
        else if (descriptor instanceof IndexedPropertyDescriptor) {
            type = ((IndexedPropertyDescriptor) descriptor).
                    getIndexedPropertyType();
        }
        else {
            type = descriptor.getPropertyType();
        }
    }
    return type;
}
项目:lams    文件:RequestUtils.java   
/**
 * <p>Determine whether <code>instance</code> of <code>ActionForm</code> is
 * suitable for re-use as an instance of the form described by
 * <code>config</code>.</p>
 * @param instance an instance of <code>ActionForm</code> which was found,
 * probably in either request or session scope.
 * @param config the configuration for the ActionForm which is needed.
 * @return true if the instance found is "compatible" with the type required
 * in the <code>FormBeanConfig</code>; false if not, or if <code>instance</code>
 * is null.
 * @throws ClassNotFoundException if the <code>type</code> property of
 * <code>config</code> is not a valid Class name.
 */
private static boolean canReuseActionForm(ActionForm instance, FormBeanConfig config)
        throws ClassNotFoundException
{
    if (instance == null) {
        return (false);
    }

    boolean canReuse = false;
    String formType = null;
    String className = null;

    if (config.getDynamic()) {
        className = ((DynaBean) instance).getDynaClass().getName();
        canReuse = className.equals(config.getName());
        formType = "DynaActionForm";
    } else {
        Class configClass = applicationClass(config.getType());
        className = instance.getClass().getName();
        canReuse = configClass.isAssignableFrom(instance.getClass());
        formType = "ActionForm";
    }

    if (log.isDebugEnabled()) {
        log.debug(
                " Can recycle existing "
                + formType
                + " instance "
                + "of type '"
                + className
                + "'?: "
                + canReuse);
        log.trace(" --> " + instance);
    }
    return (canReuse);
}
项目:lams    文件:DynaActionFormClass.java   
/**
 * <p>Instantiate and return a new {@link DynaActionForm} instance,
 * associated with this <code>DynaActionFormClass</code>.  The
 * properties of the returned {@link DynaActionForm} will have been
 * initialized to the default values specified in the form bean
 * configuration information.</p>
 *
 * @exception IllegalAccessException if the Class or the appropriate
 *  constructor is not accessible
 * @exception InstantiationException if this Class represents an abstract
 *  class, an array class, a primitive type, or void; or if instantiation
 *  fails for some other reason
 */
public DynaBean newInstance()
    throws IllegalAccessException, InstantiationException {

    DynaActionForm dynaBean =
        (DynaActionForm) getBeanClass().newInstance();
    dynaBean.setDynaActionFormClass(this);
    FormPropertyConfig props[] = config.findFormPropertyConfigs();
    for (int i = 0; i < props.length; i++) {
        dynaBean.set(props[i].getName(), props[i].initial());
    }
    return (dynaBean);

}
项目:jaffa-framework    文件:ExcelExportService.java   
/**
 * Formats the input object based on the layout specified in the ColumnModel.
 */
private static String format(Object value, DynaBean columnModel) {
    try {
        String layout = (String) columnModel.get("layout");
        if ("[hh:mm]".equals(layout))
            return decimal2hmm(value);
    } catch (Exception e) {
    }
    return value != null ? value.toString() : "";
}
项目:jaffa-framework    文件:ExcelExportService.java   
/**
 * Formats the input object based on the layout specified in the
 * ColumnModel.
 */
private static String format(Object value, DynaBean columnModel) {
    try {
        String layout = (String) columnModel.get("layout");
        if (value != null && value instanceof Double) {
            return Formatter.format((Double) value);
        } else {
            if ("[hh:mm]".equals(layout)) {
                return decimal2hmm(value);
            }
        }
    } catch (Exception e) {
    }
    return value != null ? value.toString() : "";
}
项目:OSCAR-ConCert    文件:BillingreferralEditAction.java   
public ActionForward searchByNo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    DynaBean lazyForm = (DynaBean) form;
    String referralNo = (String)lazyForm.get("search");

    List<ProfessionalSpecialist> referrals = psDao.findByReferralNo(referralNo);
    request.setAttribute("referrals", referrals);

    request.setAttribute("searchBy", "searchByNo");

    return mapping.findForward("list");
}
项目:OSCAR-ConCert    文件:BillingreferralEditAction.java   
public ActionForward searchBySpecialty(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    DynaBean lazyForm = (DynaBean) form;
    String specialty = (String)lazyForm.get("search");

    List<ProfessionalSpecialist> referrals = psDao.findBySpecialty(specialty);
    request.setAttribute("referrals", referrals);
    request.setAttribute("searchBy", "searchBySpecialty");

    return mapping.findForward("list");
}
项目:OSCAR-ConCert    文件:SitesManageAction.java   
public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    DynaBean lazyForm = (DynaBean) form;

    Site s = new Site();
    lazyForm.set("site", s);

    return mapping.findForward("details");
}
项目:openbravo-brazil    文件:ImportModule.java   
/**
 * Adds the classpath entries to .classpath file from the modules in the Vector<DynaBean>
 * 
 */
private void addDynaClasspathEntries(Vector<DynaBean> dModulesToInstall) throws Exception {
  if (!(new File(obDir + "/.classpath").exists())) {
    log4j.info("No " + obDir + "/.classpath file");
    return;
  }
  log4j.info("Adding .claspath entries");
  final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  final Document doc = docBuilder.parse(obDir + "/.classpath");
  for (final DynaBean module : dModulesToInstall) {
    final String dir = "modules/" + (String) module.get("JAVAPACKAGE") + "/src";
    if (new File(obDir + "/" + dir).exists()) {
      addClassPathEntry(doc, dir);
    } else {
      log4j.info(dir + " does not exist, no claspath entry added");
    }
  }

  // Save the modified xml file to .classpath file
  final Transformer transformer = TransformerFactory.newInstance().newTransformer();
  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  final FileOutputStream fout = new FileOutputStream(obDir + "/.classpath");
  final StreamResult result = new StreamResult(fout);
  final DOMSource source = new DOMSource(doc);
  transformer.transform(source, result);
  fout.close();
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public String getInsertSql(Database model, DynaBean dynaBean)
{
    SqlDynaClass      dynaClass  = model.getDynaClassFor(dynaBean);
    SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();

    if (properties.length == 0)
    {
        _log.info("Cannot insert instances of type " + dynaClass + " because it has no properties");
        return null;
    }

    return createInsertSql(model, dynaClass, properties, dynaBean);
}
项目:gemfirexd-oss    文件:TestChangeColumn.java   
/**
 * Tests decreasing the size of a column.
 */
public void testColumnDecreaseSize()
{
    final String model1Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='VARCHAR' size='32' required='true'/>\n"+
        "  </table>\n"+
        "</database>";
    final String model2Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='VARCHAR' size='16' required='true'/>\n"+
        "  </table>\n"+
        "</database>";

    createDatabase(model1Xml);

    insertRow("roundtrip", new Object[] { new Integer(1), "12345678901234567890123456789012" });

    alterDatabase(model2Xml);

    assertEquals(getAdjustedModel(),
                 readModelFromDatabase("roundtriptest"));

    List     beans = getRows("roundtrip");
    DynaBean bean  = (DynaBean)beans.get(0);

    assertEquals(new Integer(1), bean, "pk");
    assertTrue("12345678901234567890123456789012".equals(bean.get("avalue")) || "1234567890123456".equals(bean.get("avalue")));
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public void insert(Database model, DynaBean dynaBean) throws DatabaseOperationException
{
    Connection connection = borrowConnection();

    try
    {
        insert(connection, model, dynaBean);
    }
    finally
    {
        returnConnection(connection);
    }
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public boolean exists(Database model, DynaBean dynaBean)
{
    Connection connection = borrowConnection();

    try
    {
        return exists(connection, model, dynaBean);
    }
    finally
    {
        returnConnection(connection);
    }
}
项目:gemfirexd-oss    文件:PlatformImplBase.java   
/**
 * {@inheritDoc}
 */
public void store(Connection connection, Database model, DynaBean dynaBean) throws DatabaseOperationException
{
    if (exists(connection, model, dynaBean))
    {
        update(connection, model, dynaBean);
    }
    else
    {
        insert(connection, model, dynaBean);
    }
}
项目:gemfirexd-oss    文件:PostgreSqlPlatform.java   
/**
 * {@inheritDoc}
 */
protected void setObject(PreparedStatement statement, int sqlIndex, DynaBean dynaBean, SqlDynaProperty property) throws SQLException
{
    int     typeCode = property.getColumn().getTypeCode();
    Object  value    = dynaBean.get(property.getName());

    // PostgreSQL doesn't like setNull for BYTEA columns
    if (value == null)
    {
        switch (typeCode)
        {
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
            case Types.BLOB:
                statement.setBytes(sqlIndex, null);
                break;
            default:
                statement.setNull(sqlIndex, typeCode);
                break;
        }
    }
    else
    {
        super.setObject(statement, sqlIndex, dynaBean, property);
    }
}
项目:gemfirexd-oss    文件:DynaClassCache.java   
/**
 * Returns the {@link SqlDynaClass} for the given bean.
 * 
 * @param dynaBean The bean
 * @return The dyna bean class
 */
public SqlDynaClass getDynaClass(DynaBean dynaBean) throws SqlDynaException
{
    DynaClass dynaClass = dynaBean.getDynaClass();

    if (dynaClass instanceof SqlDynaClass)
    {
        return (SqlDynaClass)dynaClass;
    }
    else
    {
        // TODO: we could autogenerate an SqlDynaClass here ?
        throw new SqlDynaException("The dyna bean is not an instance of a SqlDynaClass");
    }
}
项目:gemfirexd-oss    文件:TestChangeColumn.java   
/**
 * Tests decreasing the size of a column.
 */
public void testPKColumnDecreaseSize()
{
    final String model1Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='CHAR' size='32' primaryKey='true' required='true'/>\n"+
        "  </table>\n"+
        "</database>";
    final String model2Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='CHAR' size='16' primaryKey='true' required='true'/>\n"+
        "  </table>\n"+
        "</database>";

    createDatabase(model1Xml);

    insertRow("roundtrip", new Object[] { "12345678901234567890123456789012" });

    alterDatabase(model2Xml);

    assertEquals(getAdjustedModel(),
                 readModelFromDatabase("roundtriptest"));

    List     beans = getRows("roundtrip");
    DynaBean bean  = (DynaBean)beans.get(0);

    assertTrue("12345678901234567890123456789012".equals(bean.get("pk")) || "1234567890123456".equals(bean.get("pk")));
}
项目:gemfirexd-oss    文件:TestChangeColumn.java   
/**
 * Tests increasing the scale of a column.
 */
public void testColumnIncreaseScale()
{
    final String model1Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='DECIMAL' size='10,4' required='true'/>\n"+
        "  </table>\n"+
        "</database>";
    final String model2Xml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='DECIMAL' size='10,5' required='true'/>\n"+
        "  </table>\n"+
        "</database>";

    createDatabase(model1Xml);

    insertRow("roundtrip", new Object[] { new Integer(1), new BigDecimal("12345.1234") });

    alterDatabase(model2Xml);

    assertEquals(getAdjustedModel(),
                 readModelFromDatabase("roundtriptest"));

    List     beans = getRows("roundtrip");
    DynaBean bean  = (DynaBean)beans.get(0);

    assertEquals(new Integer(1), bean, "pk");
    // Some DBs return the BigDecimal with the five digits scale, some don't
    assertTrue(bean.get("avalue").equals(new BigDecimal("12345.1234")) ||
               bean.get("avalue").equals(new BigDecimal("12345.12340")));
}
项目:gemfirexd-oss    文件:DataToDatabaseSink.java   
/**
 * Builds an identity object from the primary keys of the specified table using the
 * column values of the supplied bean.
 * 
 * @param table The table
 * @param bean  The bean
 * @return The identity
 */
private Identity buildIdentityFromPKs(Table table, DynaBean bean)
{
    Identity identity  = new Identity(table);
    Column[] pkColumns = table.getPrimaryKeyColumns();

    for (int idx = 0; idx < pkColumns.length; idx++)
    {
        identity.setColumnValue(pkColumns[idx].getName(), bean.get(pkColumns[idx].getName()));
    }
    return identity;
}
项目:gemfirexd-oss    文件:DataToDatabaseSink.java   
/**
 * Updates the values of the columns constituting the indicated foreign key with the values
 * of the given identity.
 * 
 * @param bean     The bean whose columns shall be updated
 * @param fkName   The name of the foreign key
 * @param identity The target identity
 */
private void updateFKColumns(DynaBean bean, String fkName, Identity identity)
{
    Table      sourceTable = ((SqlDynaClass)bean.getDynaClass()).getTable();
    Table      targetTable = identity.getTable();
    ForeignKey fk          = null;

    for (int idx = 0; idx < sourceTable.getForeignKeyCount(); idx++)
    {
        ForeignKey curFk = sourceTable.getForeignKey(idx);

        if (curFk.getForeignTableName().equalsIgnoreCase(targetTable.getQualifiedName()))
        {
            if (fkName.equals(getFKName(sourceTable, curFk)))
            {
                fk = curFk;
                break;
            }
        }
    }
    if (fk != null)
    {
        for (int idx = 0; idx < fk.getReferenceCount(); idx++)
        {
            Reference curRef       = fk.getReference(idx);
            Column    sourceColumn = curRef.getLocalColumn();
            Column    targetColumn = curRef.getForeignColumn();

            bean.set(sourceColumn.getName(), identity.getColumnValue(targetColumn.getName()));
        }
    }
}
项目:gemfirexd-oss    文件:TestDynaSqlQueries.java   
/**
 * Tests the insert method.
 */
public void testInsertSingle() throws Exception
{
    createDatabase(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='TheId' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='TheText' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>");

    SqlDynaClass dynaClass = SqlDynaClass.newInstance(getModel().getTable(0));
    DynaBean     dynaBean  = new SqlDynaBean(dynaClass);

    dynaBean.set("TheId", new Integer(1));
    dynaBean.set("TheText", "Text 1"); 

    getPlatform().insert(getModel(), dynaBean);

    List beans = getPlatform().fetch(getModel(),
                                     "SELECT * FROM " + asIdentifier("TestTable"),
                                     new Table[] { getModel().getTable(0) });

    assertEquals(1,
                 beans.size());

    DynaBean bean = (DynaBean)beans.get(0);

    assertEquals(new Integer(1),
                 getPropertyValue(bean, "TheId"));
    assertEquals("Text 1",
                 getPropertyValue(bean, "TheText"));
}
项目:gemfirexd-oss    文件:TestDynaSqlQueries.java   
/**
 * Tests the update method.
 */
public void testUpdate() throws Exception
{
    createDatabase(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='TheId' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='TheText' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>");

    insertData(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<data>\n"+
        "  <TestTable TheId='1' TheText='Text 1'/>\n"+
        "</data>");

    SqlDynaClass dynaClass = SqlDynaClass.newInstance(getModel().getTable(0));
    DynaBean     dynaBean  = new SqlDynaBean(dynaClass);

    dynaBean.set("TheId", new Integer(1));
    dynaBean.set("TheText", "Text 10"); 

    getPlatform().update(getModel(), dynaBean);

    List beans = getPlatform().fetch(getModel(),
                                     "SELECT * FROM " + asIdentifier("TestTable"),
                                     new Table[] { getModel().getTable(0) });

    assertEquals(1,
                 beans.size());

    DynaBean bean = (DynaBean)beans.get(0);

    assertEquals(new Integer(1),
                 getPropertyValue(bean, "TheId"));
    assertEquals("Text 10",
                 getPropertyValue(bean, "TheText"));
}
项目:openbravo-brazil    文件:ImportModule.java   
/**
 * Reads a ZipInputStream and returns a Vector<DynaBean> with its modules
 * 
 * @throws Exception
 */
private Vector<DynaBean> getEntryDynaBeans(byte[] obxEntryBytes) throws Exception {
  final ByteArrayInputStream ba = new ByteArrayInputStream(obxEntryBytes);

  final DatabaseDataIO io = new DatabaseDataIO();
  final DataReader dr = io.getConfiguredCompareDataReader(db);
  dr.getSink().start();
  dr.parse(ba);
  return ((DataToArraySink) dr.getSink()).getVector();
}
项目:gemfirexd-oss    文件:TestDynaSqlQueries.java   
/**
 * Tests the store method.
 */
public void testStoreExisting() throws Exception
{
    createDatabase(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='TheId' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='TheText' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>");

    insertData(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<data>\n"+
        "  <TestTable TheId='1' TheText='Text 1'/>\n"+
        "</data>");

    SqlDynaClass dynaClass = SqlDynaClass.newInstance(getModel().getTable(0));
    DynaBean     dynaBean  = new SqlDynaBean(dynaClass);

    dynaBean.set("TheId", new Integer(1));
    dynaBean.set("TheText", "Text 10"); 

    getPlatform().store(getModel(), dynaBean);

    List beans = getPlatform().fetch(getModel(),
                                     "SELECT * FROM " + asIdentifier("TestTable"),
                                     new Table[] { getModel().getTable(0) });

    assertEquals(1,
                 beans.size());

    DynaBean bean = (DynaBean)beans.get(0);

    assertEquals(new Integer(1),
                 getPropertyValue(bean, "TheId"));
    assertEquals("Text 10",
                 getPropertyValue(bean, "TheText"));
}
项目:gemfirexd-oss    文件:TestAgainstLiveDatabaseBase.java   
/**
 * Inserts a row into the designated table.
 * 
 * @param tableName    The name of the table (case insensitive)
 * @param columnValues The values for the columns in order of definition
 * @return The dyna bean for the row
 */
protected DynaBean insertRow(String tableName, Object[] columnValues)
{
    Table    table = getModel().findTable(tableName);
    DynaBean bean  = getModel().createDynaBeanFor(table);

    for (int idx = 0; (idx < table.getColumnCount()) && (idx < columnValues.length); idx++)
    {
        Column column = table.getColumn(idx);

        bean.set(column.getName(), columnValues[idx]);
    }
    getPlatform().insert(getModel(), bean);
    return bean;
}
项目:spring-boot    文件:SpringMailService.java   
/**
 * Velocity 模板发送邮件 html 格式
 *
 * @param to
 * @param subject
 * @throws javax.mail.MessagingException
 */
public void sendMailVelocity(String from ,String[] to, String subject) throws MessagingException {

    //如果不是 html 格式,修改为  SimpleMailMessage
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true, StandardCharsets.UTF_8.toString());

    /**
     *邮件内容
     */
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);

    //模板内容
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("firstName", "Yashwant");
    model.put("lastName", "Chavan");
    model.put("location", "china");
    //创建动态 bean
    DynaBean dynaBean = new LazyDynaBean();
    dynaBean.set("name", "It is name"); //simple
    dynaBean.set("gender", new Integer(1));  //simple
    //设置 bean 属性

    // Velocity 工具类,实例可以直接放入 map ,在模板文件中直接使用
    // 如日期格式化 $dateTool.format("yyyy-MM-dd",$info.issueTime)
    DateTool dateTool = new DateTool();//日期工具
    NumberTool numberTool = new NumberTool();//数字工具
    model.put("dateTool",dateTool);
    model.put("numberTool",numberTool);

    model.put("bean", dynaBean);
    String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "./templates/velocity_template_email-newsletter.vm", StandardCharsets.UTF_8.toString(), model);
    helper.setText(text, true);

    mailSender.send(message);
}
项目:gemfirexd-oss    文件:TestAgainstLiveDatabaseBase.java   
/**
 * Deletes the specified row from the table.
 * 
 * @param tableName      The name of the table (case insensitive)
 * @param pkColumnValues The values for the pk columns in order of definition
 */
protected void deleteRow(String tableName, Object[] pkColumnValues)
{
    Table    table     = getModel().findTable(tableName);
    DynaBean bean      = getModel().createDynaBeanFor(table);
    Column[] pkColumns = table.getPrimaryKeyColumns();

    for (int idx = 0; (idx < pkColumns.length) && (idx < pkColumnValues.length); idx++)
    {
        bean.set(pkColumns[idx].getName(), pkColumnValues[idx]);
    }
    getPlatform().delete(getModel(), bean);
}
项目:gemfirexd-oss    文件:TestDataReaderAndWriter.java   
/**
 * Tests that attributes for which no column is defined, are ignored.
 */
public void testAttributeForUndefinedColumn() throws Exception
{
    Database model = readModel(
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='test'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='value' type='VARCHAR' size='50' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    List beans = readBeans(
        model,
        "<data>\n"+
        "  <test id='1' value1='foo'/>\n"+
        "</data>");

    assertEquals(1, beans.size());

    DynaBean obj = (DynaBean)beans.get(0);

    assertEquals("test",
                 obj.getDynaClass().getName());
    assertEquals("1",
                 obj.get("id").toString());
    assertNull(obj.get("value"));
}