SimpleDbViewModelService implements WteModelService { @Override public WteDataModel createModel(Template<?> template, Object input) { String viewName = template.getProperties().get(VIEW_NAME); String pkColumnName = template.getProperties().get( PRIMARY_KEY_COLUMN_NAME); Integer pk = (Integer) input; Map<String, Object> dataMap = new HashMap<String, Object>(); String query = "select * from " + viewName + " where " + pkColumnName + "=" + pk; try { Connection connection = null; Statement statement = null; try { connection = ds.getConnection(); statement = connection.createStatement(); ResultSet rs = statement.executeQuery(query); ResultSetMetaData metaData = rs.getMetaData(); while (rs.next()) { for (int i = 1; i <= metaData.getColumnCount(); i++) { String columnName = metaData.getColumnName(i) .toLowerCase(); dataMap.put(columnName, rs.getObject(i)); } } } finally { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new WteException("error in createModel (" + viewName + ", " + pkColumnName + ", " + pk + ")", e); } return new WteMapModel(dataMap); } protected  SimpleDbViewModelService();  SimpleDbViewModelService(DataSource aDs); @Override Map<String, Class<?>> listModelElements(Class<?> inputClass,
			Map<String, String> properties); @Override List<String> listRequiredModelProperties(); @Override WteDataModel createModel(Template<?> template, Object input); static final String VIEW_NAME; static final String PRIMARY_KEY_COLUMN_NAME; }
@Test public void testModel() throws SQLException { SimpleDbViewModelService ms = new SimpleDbViewModelService(ds); @SuppressWarnings("unchecked") Template<Integer> template = mock(Template.class); Map<String, String> modelProperties = new HashMap<String, String>(); modelProperties.put(SimpleDbViewModelService.VIEW_NAME, "TESTDBVIEW"); modelProperties.put(SimpleDbViewModelService.PRIMARY_KEY_COLUMN_NAME, "ID"); when(template.getProperties()).thenReturn(modelProperties); when(template.getInputType()).then(new Answer<Class<?>>() { @Override public Class<?> answer(InvocationOnMock invocation) throws Throwable { return Integer.class; } }); WteDataModel model = ms.createModel(template, new Integer(1)); assertNotNull(model.getValue("id")); assertNotNull(model.getValue("testboolean")); assertNotNull(model.getValue("testvarchar255")); assertNotNull(model.getValue("testtimestamp")); assertNotNull(model.getValue("testtime")); assertNotNull(model.getValue("testdate")); assertNotNull(model.getValue("testchar255")); assertNotNull(model.getValue("testlongvarchar255")); assertNotNull(model.getValue("testtinyint")); assertNotNull(model.getValue("testsmallint")); assertNotNull(model.getValue("testint")); assertNotNull(model.getValue("testreal")); assertNotNull(model.getValue("testfloat")); assertNotNull(model.getValue("testnumeric")); assertNotNull(model.getValue("testdecimal")); }