Commits

tbrugz  committed 64d7638

resultset: ResultSetCollectionAdapter: unique columns at first

  • Participants
  • Parent commits c89f786

Comments (0)

Files changed (2)

File src/tbrugz/queryon/QueryOn.java

 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 		conn.close();
 	}
 
+	static final List<String> statusUniqueColumns = Arrays.asList(new String[]{"schemaName", "name"});
 	void doStatus(RequestSpec reqspec, HttpServletResponse resp) throws IntrospectionException, SQLException, IOException, ServletException {
 		ResultSet rs = null;
+		//XXX: filter by schemaName, name? ResultSetFilterAdapter(rs, colnames, colvalues)?
 		if("table".equalsIgnoreCase(reqspec.object)) {
-			rs = new ResultSetCollectionAdapter<Table>("status", model.getTables());
+			rs = new ResultSetCollectionAdapter<Table>("status", statusUniqueColumns, model.getTables());
 		}
 		else if("view".equalsIgnoreCase(reqspec.object)) {
-			rs = new ResultSetCollectionAdapter<View>("status", model.getViews());
+			rs = new ResultSetCollectionAdapter<View>("status", statusUniqueColumns, model.getViews());
 		}
 		else if("executable".equalsIgnoreCase(reqspec.object)) {
-			rs = new ResultSetCollectionAdapter<ExecutableObject>("status", model.getExecutables());
+			rs = new ResultSetCollectionAdapter<ExecutableObject>("status", statusUniqueColumns, model.getExecutables());
 		}
 		else if("fk".equalsIgnoreCase(reqspec.object)) {
-			rs = new ResultSetCollectionAdapter<FK>("status", model.getForeignKeys());
+			rs = new ResultSetCollectionAdapter<FK>("status", statusUniqueColumns, model.getForeignKeys());
 		}
 		else {
 			throw new ServletException("unknown object: "+reqspec.object);
 		}
-		dumpResultSet(rs, reqspec, "status", null, resp);
+		dumpResultSet(rs, reqspec, "status", null /*statusUniqueColumns*/, resp);
 	}
 	
 	void dumpResultSet(ResultSet rs, RequestSpec reqspec, String queryName, List<String> uniqueColumns, HttpServletResponse resp) throws SQLException, IOException {

File src/tbrugz/queryon/resultset/ResultSetCollectionAdapter.java

 	E currentElement;
 	//int position = 0;
 
-	public ResultSetCollectionAdapter(String name, Collection<E> list) throws IntrospectionException {
+	public ResultSetCollectionAdapter(String name, List<String> uniqueCols, Collection<E> list) throws IntrospectionException {
 		this.name = name;
 		
 		E e = list.iterator().next();
 		
 		BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
 		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+		if(uniqueCols!=null) {
+			for(String col: uniqueCols) {
+				for (PropertyDescriptor prop : propertyDescriptors) {
+					if(col.equals(prop.getName())) {
+						columnNames.add(col);
+						methods.add(prop.getReadMethod());
+					}
+				}
+			}
+		}
 		for (PropertyDescriptor prop : propertyDescriptors) {
-			Method m = prop.getReadMethod();
 			String pname = prop.getName();
 			if("class".equals(pname)) { continue; }
+			if(columnNames.contains(pname)) { continue; }
 			//XXX: continue on transient, ... ??
+			
+			Method m = prop.getReadMethod();
 			columnNames.add(pname);
 			methods.add(m);
 		}