[Registry-dev] svn commit r16618 - in
trunk/registry/modules/core/src: main/java/org/wso2/registry
test/java/org/wso2/registry/jdbc
svn at wso2.org
svn at wso2.org
Wed May 7 04:49:31 PDT 2008
Author: deepal
Date: Wed May 7 04:49:20 2008
New Revision: 16618
Log:
second part for the pagination
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java Wed May 7 04:49:20 2008
@@ -26,6 +26,7 @@
public class CollectionImpl extends ResourceImpl implements Collection {
private int childCount;
+
public CollectionImpl() {
}
@@ -46,37 +47,56 @@
}
public String[] getChildren(int start, int pageLen) {
- try {
- String sql = "SELECT R.RID, R.PATH FROM RESOURCE R, DEPENDENCY D WHERE D.PARENT_RID=?" +
- " AND D.CHILD_RID=R.RID ORDER BY R.PATH";
- PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
- ps.setString(1, getId());
- List<String> childPathList = new ArrayList();
- ResultSet results = ps.executeQuery();
- int current = 0;
- while (results.next()) {
- String childID = results.getString("RID");
- if (AuthorizationUtils.authorize(childID, ActionConstants.GET)) {
- if (current >= start && (pageLen == -1 || current < start + pageLen))
- childPathList.add(results.getString("PATH"));
- System.out.println(results.getString("PARENT_RID"));
- current++;
+ if (content == null) {
+ try {
+ String sql = "SELECT R.RID, R.PATH FROM RESOURCE R, DEPENDENCY D WHERE D.PARENT_RID=?" +
+ " AND D.CHILD_RID=R.RID ORDER BY R.PATH";
+ PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
+ ps.setString(1, getId());
+ List<String> childPathList = new ArrayList();
+ ResultSet results = ps.executeQuery();
+ int current = 0;
+ while (results.next()) {
+ String childID = results.getString("RID");
+ if (AuthorizationUtils.authorize(childID, ActionConstants.GET)) {
+ if (current >= start && (pageLen == -1 || current < start + pageLen))
+ childPathList.add(results.getString("PATH"));
+ current++;
+ }
}
- }
- if (current < start) {
- throw new RegistryException("Didn't have enough results to start at #" + start);
- }
- ps.close();
- return childPathList.toArray(new String[childPathList.size()]);
+ if (current < start) {
+ throw new RegistryException("Didn't have enough results to start at #" + start);
+ }
+ ps.close();
+ return childPathList.toArray(new String[childPathList.size()]);
+
+ } catch (Exception e) {
+ String msg = "Failed to get child paths of resource " +
+ getPath() + ". " + e.getMessage();
+ //TODO need to log the message
- } catch (Exception e) {
- String msg = "Failed to get child paths of resource " +
- getPath() + ". " + e.getMessage();
- //TODO need to log the message
- return new String[0];
+ }
+ } else {
+ if ( content instanceof String[]){
+ System.out.println("came here");
+ List<String> childPathList = new ArrayList();
+ String childNodes [] = (String[])content;
+ int limit = 0;
+ if (start > childNodes.length) {
+ return new String[0];
+ }
+ if (start + pageLen > childNodes.length) {
+ limit = childNodes.length;
+ }
+ for (int i = start ; i < limit; i++) {
+ String childNode = childNodes[i];
+ childPathList.add(childNode);
+ }
+ return childPathList.toArray(new String[childPathList.size()]);
+ }
}
- // TODO - implement
+ return new String[0];
}
public List<Resource> getChildResources() {
@@ -85,23 +105,29 @@
public int getChildCount() {
- String sql = "SELECT COUNT(*) AS CHILD_COUNT FROM DEPENDENCY WHERE PARENT_RID=?";
- try {
- PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
- ps.setString(1, getId());
- ResultSet results = ps.executeQuery();
- if (results.next()) {
- childCount = results.getInt("CHILD_COUNT");
- return childCount;
+ if (content == null) {
+ String sql = "SELECT COUNT(*) AS CHILD_COUNT FROM DEPENDENCY WHERE PARENT_RID=?";
+ try {
+ PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
+ ps.setString(1, getId());
+ ResultSet results = ps.executeQuery();
+ if (results.next()) {
+ childCount = results.getInt("CHILD_COUNT");
+ return childCount;
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ } else {
+ if ( content instanceof String[]){
+ return ((String[])content).length;
}
- } catch (SQLException e) {
- e.printStackTrace();
}
return 0;
}
public void setChildCount(int count) {
- childCount = count;
+ childCount = count;
}
}
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java Wed May 7 04:49:20 2008
@@ -45,8 +45,10 @@
String childNodes [] = (String[])collection.getContent();
assertEquals(childNodes.length ,50);
Collection coll = registry.get("/test/c1", 0, 20);
- assertEquals(coll.getChildCount() ,50);
+ assertEquals(coll.getChildCount() ,20);
childNodes = coll.getChildren();
assertEquals(childNodes.length ,20);
+ coll = (Collection) registry.get("/test/c1");
+ assertEquals(coll.getChildCount() ,50);
}
}
More information about the Registry-dev
mailing list