[gogoego] r3709 committed - user integers not strings for ids ... string were used out of respect ...

2 views
Skip to first unread message

codesite...@google.com

unread,
Jul 19, 2010, 1:11:22 PM7/19/10
to gog...@googlegroups.com
Revision: 3709
Author: carl....@solertium.com
Date: Mon Jul 19 10:09:32 2010
Log: user integers not strings for ids ... string were used out of respect
for a VFS implementation of ProfileManager but this has yet to happen so we
will cross that bridge when we get there.
http://code.google.com/p/gogoego/source/detail?r=3709

Modified:

/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/Profile.java

/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/ProfileResource.java

/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/H2ProfileManager.java

/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/ProfileManager.java

=======================================
---
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/Profile.java
Mon Sep 21 11:51:23 2009
+++
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/Profile.java
Mon Jul 19 10:09:32 2010
@@ -42,17 +42,16 @@
private HashMap<String, String> userData;

public Profile() {
- userData= new HashMap<String, String>();
+ this(null);
}

public Profile(String username) {
- this.username= username;
- userData= new HashMap<String, String>();
+ this(username, new HashMap<String, String>());
}

public Profile(String username, HashMap<String, String> userData) {
+ this.username = username;
this.userData = userData;
- this.username=username;
}

public void setId(long id){
@@ -70,6 +69,10 @@
public HashMap<String, String> getData(){
return userData;
}
+
+ public void addData(String key, String value) {
+ userData.put(key, value);
+ }

public static Profile fromXML(String xml){
Document doc = BaseDocumentUtils.impl.createDocumentFromString(xml);
@@ -95,5 +98,9 @@
xml += "</profile>";
return xml;
}
+
+ public String toString() {
+ return toXML();
+ }

}
=======================================
---
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/ProfileResource.java
Fri Sep 4 13:11:29 2009
+++
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/core/ProfileResource.java
Mon Jul 19 10:09:32 2010
@@ -247,7 +247,7 @@
if (!"VALUE".equals(fields.get(0).getAttribute("name")))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);

- getManager().updateField(userID, fieldID,
fields.get(0).getTextContent());
+ getManager().updateField(Integer.parseInt(userID), fieldID,
fields.get(0).getTextContent());
}

private void updateUser(final Representation entity) throws
ResourceException {
=======================================
---
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/H2ProfileManager.java
Sun May 9 22:32:53 2010
+++
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/H2ProfileManager.java
Mon Jul 19 10:09:32 2010
@@ -37,10 +37,12 @@
import com.solertium.db.ExecutionContext;
import com.solertium.db.Row;
import com.solertium.db.RowID;
+import com.solertium.db.RowProcessor;
import com.solertium.db.SystemExecutionContext;
import com.solertium.db.query.DeleteQuery;
import com.solertium.db.query.InsertQuery;
import com.solertium.db.query.QConstraint;
+import com.solertium.db.query.QRelationConstraint;
import com.solertium.db.query.SelectQuery;
import com.solertium.db.query.UpdateQuery;
import com.solertium.util.BaseDocumentUtils;
@@ -225,58 +227,36 @@
return users;
}

- /*public void addProfile(Profile profile) {
-
- if(getProfile(profile.getName())!= null){
- System.out.println("Profile already exists");
- return;
- }
- System.out.println("inserting profile");
- InsertQuery isql = new InsertQuery();
- Row row = new Row();
- int id = 0;
- try {
- id = (int) RowID.get(ec, profile_table, "ID");
- } catch (DBException ex) {
-
- }
-
- row.add(new CInteger("ID", new Integer(id)));
- row.add(new CString("NAME", profile.getName()));
-
-
- isql.setRow(row);
- isql.setTable(profile_table);
-
+ public Map<String, Profile> getAllProfiles() throws ResourceException {
+ final SelectQuery query = new SelectQuery();
+ query.select(profile_table, "name");
+ query.select(data_table, "*");
+ query.join(data_table, new QRelationConstraint(
+ new CanonicalColumnName(profile_table, "id"),
+ new CanonicalColumnName(data_table, "profile_id")
+ ));
+
+ final Map<String, Profile> map = new HashMap<String, Profile>();
+
try {
- ec.doUpdate(isql);
- } catch (DBException dbException) {
- TrivialExceptionHandler.ignore(this, dbException);
- }
-
- for(String key: profile.getData().keySet()){
- InsertQuery data_isql = new InsertQuery();
- data_isql.setTable(data_table);
- Row dataRow = new Row();
- try {
- dataRow.add(new CInteger("ID", new Integer((int) RowID.get(ec,
data_table, "ID"))));
- dataRow.add(new CInteger("PROFILE_ID", id));
- dataRow.add(new CString("KEY", key));
- dataRow.add(new CString("VALUE", profile.getData().get(key)));
- data_isql.setRow(dataRow);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- try {
- System.out.println(data_isql.getSQL(ec.getDBSession()));
- ec.doUpdate(data_isql);
- } catch (DBException dbException) {
- TrivialExceptionHandler.ignore(this, dbException);
- }
-
- }
- }*/
+ ec.doQuery(query, new RowProcessor() {
+ public void process(Row row) {
+ final String username = row.get("name").toString();
+ Profile p = map.get(username);
+ if (p == null)
+ p = new Profile(username);
+
+ p.addData(row.get("key").toString(), row.get("value").toString());
+
+ map.put(username, p);
+ }
+ });
+ } catch (DBException e) {
+ throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
+ }
+
+ return map;
+ }

public void removeProfile(String userID) throws ResourceException {
{
@@ -398,7 +378,27 @@
}
}

- public void updateField(String userID, String fieldID, String value)
throws ResourceException {
+ public void updateField(Integer userID, String fieldName, String value)
throws ResourceException {
+ final SelectQuery query = new SelectQuery();
+ query.select(data_table, "ID");
+ query.constrain(new CanonicalColumnName(data_table, "profile_id"),
QConstraint.CT_EQUALS, userID);
+ query.constrain(QConstraint.CG_AND, new
CanonicalColumnName(data_table, "key"), QConstraint.CT_EQUALS, fieldName);
+
+ final Row.Loader rl = new Row.Loader();
+
+ try {
+ ec.doQuery(query, rl);
+ } catch (DBException e) {
+ throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
+ }
+
+ if (rl.getRow() == null)
+ throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
+ else
+ updateField(userID, rl.getRow().get(0).getInteger(), value);
+ }
+
+ public void updateField(Integer userID, Integer fieldID, String value)
throws ResourceException {
final Row row = new Row();
row.add(new CString("VALUE", value));

@@ -407,7 +407,7 @@
query.setRow(row);
query.constrain(
new CanonicalColumnName(data_table, "ID"),
- QConstraint.CT_EQUALS, Integer.valueOf(fieldID)
+ QConstraint.CT_EQUALS, fieldID
);

try {
=======================================
---
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/ProfileManager.java
Fri Sep 4 13:11:29 2009
+++
/trunk/modules/com.solertium.util.restlet.usermodel/src/com/solertium/util/restlet/usermodel/managers/ProfileManager.java
Mon Jul 19 10:09:32 2010
@@ -53,7 +53,14 @@
public Profile getProfile(String userID) throws ResourceException;

/**
- * Returns a lsit of all users
+ * Returns a mapping of all profiles in the system.
+ * @return
+ * @throws ResourceException
+ */
+ public Map<String, Profile> getAllProfiles() throws ResourceException;
+
+ /**
+ * Returns a list of all users
* @param
* @return
*/
@@ -113,7 +120,16 @@
* @param value
* @throws ResourceException
*/
- public void updateField(String userID, String fieldID, String value)
throws ResourceException;
+ public void updateField(Integer userID, String fieldID, String value)
throws ResourceException;
+
+ /**
+ * Change a field value
+ * @param userID
+ * @param fieldID
+ * @param value
+ * @throws ResourceException
+ */
+ public void updateField(Integer userID, Integer fieldID, String value)
throws ResourceException;

/**
* Retrive a mapping of all users. The key should be the unique
identifier,

Reply all
Reply to author
Forward
0 new messages