org.apache.commons.beanutils.DynaBean Java Examples
The following examples show how to use
org.apache.commons.beanutils.DynaBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecipientBeanQueryWorker.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
@Override public PaginatedListImpl<DynaBean> call() throws Exception { try { PaginatedListImpl<Recipient> recipientPaginatedList = recipientDao.getRecipients(companyID, columns, sqlStatementForData, sqlParametersForData, sortCriterion, sortedAscending, pageNumber, rownums); // Convert PaginatedListImpl of Recipient into PaginatedListImpl of DynaBean List<DynaBean> partialListOfDynaBeans = convertPaginatedListToDynaBean(recipientPaginatedList); return new PaginatedListImpl<>(partialListOfDynaBeans, recipientPaginatedList.getFullListSize(), recipientPaginatedList.getPageSize(), recipientPaginatedList.getPageNumber(), recipientPaginatedList.getSortCriterion(), recipientPaginatedList.getSortDirection()); } catch (Exception e) { logger.error("Error executing RecipientBeanQueryWorker", e); error = e; return null; } }
Example #2
Source File: DataWriter.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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()+")"); } } }
Example #3
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #4
Source File: DataToDatabaseSink.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Inserts the bean into the database or batch queue. * * @param table The table * @param bean The bean */ private void insertBeanIntoDatabase(Table table, DynaBean bean) throws DataSinkException { if (_useBatchMode) { _batchQueue.add(bean); if (_batchQueue.size() >= _batchSize) { purgeBatchQueue(); } } else { insertSingleBeanIntoDatabase(table, bean); } }
Example #5
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@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); } }
Example #6
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #7
Source File: TestAgainstLiveDatabaseBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #8
Source File: TestAgainstLiveDatabaseBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #9
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@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); }
Example #10
Source File: TestChangeColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests removing the default value of a primary key column. */ public void testPKColumnRemoveDefault() { 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='NUMERIC' size='12,2' primaryKey='true' required='true' default='2'/>\n"+ " <column name='avalue' type='INTEGER'/>\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='NUMERIC' size='12,2' primaryKey='true' required='true' default='2.20'/>\n"+ " <column name='avalue' type='INTEGER'/>\n"+ " </table>\n"+ "</database>"; createDatabase(model1Xml); insertRow("roundtrip", new Object[] { null, new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); DynaBean bean = (DynaBean)beans.get(0); // Some DBs return the BigDecimal with the two digits scale, some don't assertTrue(bean.get("pk").equals(new BigDecimal("2")) || bean.get("pk").equals(new BigDecimal("2.00"))); assertEquals(new Integer(1), bean, "avalue"); }
Example #11
Source File: TestChangeColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests removing the default value of a primary key column. */ public void testPKColumnRemoveDefault() { 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='NUMERIC' size='12,2' primaryKey='true' required='true' default='2'/>\n"+ " <column name='avalue' type='INTEGER'/>\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='NUMERIC' size='12,2' primaryKey='true' required='true' default='2.20'/>\n"+ " <column name='avalue' type='INTEGER'/>\n"+ " </table>\n"+ "</database>"; createDatabase(model1Xml); insertRow("roundtrip", new Object[] { null, new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); DynaBean bean = (DynaBean)beans.get(0); // Some DBs return the BigDecimal with the two digits scale, some don't assertTrue(bean.get("pk").equals(new BigDecimal("2")) || bean.get("pk").equals(new BigDecimal("2.00"))); assertEquals(new Integer(1), bean, "avalue"); }
Example #12
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Returns all identity properties whose value were defined by the database and which * now need to be read back from the DB. * * @param model The database model * @param dynaClass The dyna class * @param bean The bean * @return The columns */ private Column[] getRelevantIdentityColumns(Database model, SqlDynaClass dynaClass, final DynaBean bean) { SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties(); Collection relevantProperties = CollectionUtils.select(Arrays.asList(properties), new Predicate() { public boolean evaluate(Object input) { SqlDynaProperty prop = (SqlDynaProperty)input; // we only want those identity columns that were really specified by the DB // if the platform allows specification of values for identity columns // in INSERT/UPDATE statements, then we need to filter the corresponding // columns out return prop.getColumn().isAutoIncrement() && // GemStone changes BEGIN // allow using ALTER TABLE for identity columns // after initial data loading (!isAddIdentityUsingAlterTableOn() || !getPlatformInfo() .isAddingIdentityUsingAlterTableSupported()) && (!isIdentityOverrideOn() || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null)); /* (original code) (!isIdentityOverrideOn() || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null)); */ // GemStone changes END } }); Column[] columns = new Column[relevantProperties.size()]; int idx = 0; for (Iterator propIt = relevantProperties.iterator(); propIt.hasNext(); idx++) { columns[idx] = ((SqlDynaProperty)propIt.next()).getColumn(); } return columns; }
Example #13
Source File: TestChangeColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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"))); }
Example #14
Source File: DynaBeanAdapter.java From reflectutils with Apache License 2.0 | 5 votes |
public List<String> getPropertyNames(Object bean) { List<String> names = new ArrayList<String>(); DynaProperty origDescriptors[] = ((DynaBean) bean).getDynaClass().getDynaProperties(); for (DynaProperty dynaProperty : origDescriptors) { String name = dynaProperty.getName(); names.add(name); } return names; }
Example #15
Source File: TestDynaSqlQueries.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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")); }
Example #16
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void store(Database model, DynaBean dynaBean) throws DatabaseOperationException { Connection connection = borrowConnection(); try { store(connection, model, dynaBean); } finally { returnConnection(connection); } }
Example #17
Source File: TestDynaSqlQueries.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the store method. */ public void testStoreNew() 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().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 1", getPropertyValue(bean, "TheText")); }
Example #18
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean exists(Database model, DynaBean dynaBean) { Connection connection = borrowConnection(); try { return exists(connection, model, dynaBean); } finally { returnConnection(connection); } }
Example #19
Source File: TestDynaSqlQueries.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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")); }
Example #20
Source File: DynaBeanAdapter.java From reflectutils with Apache License 2.0 | 5 votes |
public Class<?> getFieldType(Object obj, String name) { DynaClass dynaClass = ((DynaBean) obj).getDynaClass(); DynaProperty dynaProperty = dynaClass.getDynaProperty(name); if (dynaProperty == null) { throw new FieldnameNotFoundException("DynaBean: Could not find this fieldName ("+name+") on the target object: " + obj, name, null); } return dynaProperty.getType(); }
Example #21
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void delete(Database model, DynaBean dynaBean) throws DatabaseOperationException { Connection connection = borrowConnection(); try { delete(connection, model, dynaBean); } finally { returnConnection(connection); } }
Example #22
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests parsing when case sensitivity is turned on. */ public void testCaseSensitivityTurnedOn() 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>"); String testDataXml = "<data>\n"+ " <test Id='1' Value='foo'/>\n"+ " <Test Id='2' value='baz'/>\n"+ "</data>"; ArrayList beans = new ArrayList(); DataReader dataReader = new DataReader(); dataReader.setCaseSensitive(true); dataReader.setModel(model); dataReader.setSink(new TestDataSink(beans)); dataReader.read(new StringReader(testDataXml)); assertEquals(1, beans.size()); DynaBean obj = (DynaBean)beans.get(0); assertEquals("Test", obj.getDynaClass().getName()); assertEquals("2", obj.get("Id").toString()); assertNull(obj.get("Value")); }
Example #23
Source File: TestAddColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the addition of a column with a default value. */ public void testAddColumnWithDefault() { 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"+ " </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='DOUBLE' default='2'/>\n"+ " </table>\n"+ "</database>"; createDatabase(model1Xml); insertRow("roundtrip", new Object[] { new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); Object avalue = ((DynaBean)beans.get(0)).get("avalue"); assertTrue((avalue == null) || new Double(2).equals(avalue)); }
Example #24
Source File: DataToDatabaseSink.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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())); } } }
Example #25
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean exists(Database model, DynaBean dynaBean) { Connection connection = borrowConnection(); try { return exists(connection, model, dynaBean); } finally { returnConnection(connection); } }
Example #26
Source File: TestAddColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the addition of a column with a default value. */ public void testAddColumnWithDefault() { 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"+ " </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='DOUBLE' default='2'/>\n"+ " </table>\n"+ "</database>"; createDatabase(model1Xml); insertRow("roundtrip", new Object[] { new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); Object avalue = ((DynaBean)beans.get(0)).get("avalue"); assertTrue((avalue == null) || new Double(2).equals(avalue)); }
Example #27
Source File: TestChangeColumn.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests increasing the scale of a primary key column. */ public void testPKColumnIncreaseScale() { 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='NUMERIC' size='10,3' 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='NUMERIC' size='10,5' primaryKey='true' required='true'/>\n"+ " </table>\n"+ "</database>"; createDatabase(model1Xml); insertRow("roundtrip", new Object[] { new BigDecimal("12345.123") }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); DynaBean bean = (DynaBean)beans.get(0); // Some DBs return the BigDecimal with the three digits scale, some don't assertTrue(bean.get("pk").equals(new BigDecimal("12345.123")) || bean.get("pk").equals(new BigDecimal("12345.12300"))); }
Example #28
Source File: PlatformImplBase.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@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); }
Example #29
Source File: DynaClassCache.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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"); } }
Example #30
Source File: TestDynaSqlQueries.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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")); }