Guest User

Untitled

a guest
Nov 22nd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import java.util.LinkedHashMap;
  6. import java.util.Map;
  7. import org.apache.commons.lang3.BooleanUtils;
  8. import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
  9. import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttr;
  10. import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttrUniqueValue;
  11. import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttrValue;
  12. import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
  13. import org.springframework.jdbc.datasource.SimpleDriverDataSource;
  14.  
  15. public class Main {
  16.  
  17. private static void view(
  18. final ResultSet rs, final Map<String, Map<String, PGUPlainAttr>> users, final boolean unique)
  19. throws SQLException {
  20.  
  21. while (rs.next()) {
  22. String key = rs.getString("any_id");
  23. Map<String, PGUPlainAttr> attrs = users.get(key);
  24. if (attrs == null) {
  25. attrs = new LinkedHashMap<>();
  26. users.put(key, attrs);
  27. }
  28.  
  29. String schema = rs.getString("schema_id");
  30. PGUPlainAttr attr = attrs.get(schema);
  31. if (attr == null) {
  32. attr = new PGUPlainAttr();
  33. attr.setSchema(schema);
  34. attrs.put(schema, attr);
  35. }
  36.  
  37. PlainAttrValue value;
  38. if (unique) {
  39. value = new PGUPlainAttrUniqueValue();
  40. attr.setUniqueValue((PGUPlainAttrUniqueValue) value);
  41. } else {
  42. value = new PGUPlainAttrValue();
  43. attr.getPGValues().add((PGUPlainAttrValue) value);
  44. }
  45. value.setAttr(attr);
  46. value.setBinaryValue(rs.getBytes("binaryvalue"));
  47. value.setDateValue(rs.getDate("datevalue"));
  48. value.setStringValue(rs.getString("stringvalue"));
  49.  
  50. int booleanValue = rs.getInt("booleanvalue");
  51. if (!rs.wasNull()) {
  52. value.setBooleanValue(BooleanUtils.toBoolean(booleanValue));
  53. }
  54.  
  55. double doubleValue = rs.getDouble("doublevalue");
  56. if (!rs.wasNull()) {
  57. value.setDoubleValue(doubleValue);
  58. }
  59.  
  60. long longValue = rs.getLong("longvalue");
  61. if (!rs.wasNull()) {
  62. value.setLongValue(longValue);
  63. }
  64. }
  65. }
  66.  
  67. public static void main(final String[] args) throws SQLException {
  68. SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
  69. dataSource.setDriverClass(org.postgresql.Driver.class);
  70. dataSource.setUrl("jdbc:postgresql://localhost:5432/syncope?stringtype=unspecified");
  71. dataSource.setUsername("syncope");
  72. dataSource.setPassword("syncope");
  73.  
  74. Connection conn = dataSource.getConnection();
  75. Statement stmt = conn.createStatement();
  76.  
  77. Map<String, Map<String, PGUPlainAttr>> users = new LinkedHashMap<>();
  78. view(stmt.executeQuery("SELECT * FROM group_search_attr"), users, false);
  79. view(stmt.executeQuery("SELECT * FROM group_search_unique_attr"), users, true);
  80.  
  81. users.forEach((key, attrs) -> {
  82. System.out.println("ZZZZZZZZZZZZ " + key + "\n");
  83. System.out.println("ZZZZZZZZZZZZ\nplainAttrs=\"" + POJOHelper.serialize(attrs.values()).replace("\"",
  84. """) + "\"/>");
  85. });
  86. }
  87. }
Add Comment
Please, Sign In to add comment