Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/Backend.java @ 550:68f01f10624e
Introduced helper for finding the user name for a given artifact
author | gernotbelger |
---|---|
date | Fri, 09 Feb 2018 13:26:19 +0100 |
parents | 3b1e48d22ce0 |
children | 584591f8203c |
comparison
equal
deleted
inserted
replaced
549:e781b847fdca | 550:68f01f10624e |
---|---|
131 public String SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT; | 131 public String SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT; |
132 public String SQL_COLLECTION_ITEM_DELETE; | 132 public String SQL_COLLECTION_ITEM_DELETE; |
133 public String SQL_COLLECTIONS_TOUCH_BY_ID; | 133 public String SQL_COLLECTIONS_TOUCH_BY_ID; |
134 public String SQL_COLLECTION_ITEMS_LIST_GID; | 134 public String SQL_COLLECTION_ITEMS_LIST_GID; |
135 public String SQL_ALL_ARTIFACTS; | 135 public String SQL_ALL_ARTIFACTS; |
136 public String SQL_FIND_USER_BY_ARTIFACT; | |
136 | 137 |
137 /** The singleton.*/ | 138 /** The singleton.*/ |
138 protected static Backend instance; | 139 protected static Backend instance; |
139 | 140 |
140 protected SQLExecutor sqlExecutor; | 141 protected SQLExecutor sqlExecutor; |
359 sql.get("collection.item.outdate.artifact"); | 360 sql.get("collection.item.outdate.artifact"); |
360 SQL_COLLECTION_ITEM_DELETE = sql.get("collection.item.delete"); | 361 SQL_COLLECTION_ITEM_DELETE = sql.get("collection.item.delete"); |
361 SQL_COLLECTIONS_TOUCH_BY_ID = sql.get("collections.touch.by.id"); | 362 SQL_COLLECTIONS_TOUCH_BY_ID = sql.get("collections.touch.by.id"); |
362 SQL_COLLECTION_ITEMS_LIST_GID = sql.get("collection.items.list.gid"); | 363 SQL_COLLECTION_ITEMS_LIST_GID = sql.get("collection.items.list.gid"); |
363 SQL_ALL_ARTIFACTS = sql.get("all.artifacts"); | 364 SQL_ALL_ARTIFACTS = sql.get("all.artifacts"); |
365 SQL_FIND_USER_BY_ARTIFACT = sql.get("find.user.by.artifact"); | |
364 } | 366 } |
365 | 367 |
366 public void addListener(BackendListener listener) { | 368 public void addListener(BackendListener listener) { |
367 listeners.add(listener); | 369 listeners.add(listener); |
368 logger.debug("# listeners: " + listeners.size()); | 370 logger.debug("# listeners: " + listeners.size()); |
1028 } | 1030 } |
1029 }; | 1031 }; |
1030 | 1032 |
1031 return exec.runRead() ? user[0] : null; | 1033 return exec.runRead() ? user[0] : null; |
1032 } | 1034 } |
1035 | |
1036 /** Find the owner of a given artifact */ | |
1037 public String findUserName(final String artifactGid) { | |
1038 | |
1039 final String[] returnValue = new String[1]; | |
1040 | |
1041 final SQLExecutor.Instance exec = this.sqlExecutor.new Instance() { | |
1042 | |
1043 @Override | |
1044 public boolean doIt() throws SQLException { | |
1045 | |
1046 prepareStatement(Backend.this.SQL_FIND_USER_BY_ARTIFACT); | |
1047 this.stmnt.setString(1, artifactGid); | |
1048 | |
1049 this.result = this.stmnt.executeQuery(); | |
1050 | |
1051 // final HashMap<String, LazyBackendUser> users = new HashMap<String, LazyBackendUser>(); | |
1052 | |
1053 while (this.result.next()) { | |
1054 // final String userIdentifier = this.result.getString(1); | |
1055 final String userName = this.result.getString(2); | |
1056 | |
1057 // We only need the name at the moment, else we could do this: User user = new LazyBackendUser( | |
1058 // userIdentifier, userFactory, Backend.this, context); | |
1059 returnValue[0] = userName; | |
1060 return true; | |
1061 } | |
1062 | |
1063 return true; | |
1064 } | |
1065 }; | |
1066 | |
1067 if (exec.runRead()) | |
1068 return returnValue[0]; | |
1069 | |
1070 return null; | |
1071 } | |
1033 | 1072 |
1034 public User [] getUsers( | 1073 public User [] getUsers( |
1035 final UserFactory factory, | 1074 final UserFactory factory, |
1036 final Object context | 1075 final Object context |
1037 ) { | 1076 ) { |