Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import org.apache.commons.lang3.BooleanUtils;
- import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
- import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttr;
- import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttrUniqueValue;
- import org.apache.syncope.core.persistence.jpa.entity.user.PGUPlainAttrValue;
- import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
- import org.springframework.jdbc.datasource.SimpleDriverDataSource;
- public class Main {
- private static void view(
- final ResultSet rs, final Map<String, Map<String, PGUPlainAttr>> users, final boolean unique)
- throws SQLException {
- while (rs.next()) {
- String key = rs.getString("any_id");
- Map<String, PGUPlainAttr> attrs = users.get(key);
- if (attrs == null) {
- attrs = new LinkedHashMap<>();
- users.put(key, attrs);
- }
- String schema = rs.getString("schema_id");
- PGUPlainAttr attr = attrs.get(schema);
- if (attr == null) {
- attr = new PGUPlainAttr();
- attr.setSchema(schema);
- attrs.put(schema, attr);
- }
- PlainAttrValue value;
- if (unique) {
- value = new PGUPlainAttrUniqueValue();
- attr.setUniqueValue((PGUPlainAttrUniqueValue) value);
- } else {
- value = new PGUPlainAttrValue();
- attr.getPGValues().add((PGUPlainAttrValue) value);
- }
- value.setAttr(attr);
- value.setBinaryValue(rs.getBytes("binaryvalue"));
- value.setDateValue(rs.getDate("datevalue"));
- value.setStringValue(rs.getString("stringvalue"));
- int booleanValue = rs.getInt("booleanvalue");
- if (!rs.wasNull()) {
- value.setBooleanValue(BooleanUtils.toBoolean(booleanValue));
- }
- double doubleValue = rs.getDouble("doublevalue");
- if (!rs.wasNull()) {
- value.setDoubleValue(doubleValue);
- }
- long longValue = rs.getLong("longvalue");
- if (!rs.wasNull()) {
- value.setLongValue(longValue);
- }
- }
- }
- public static void main(final String[] args) throws SQLException {
- SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
- dataSource.setDriverClass(org.postgresql.Driver.class);
- dataSource.setUrl("jdbc:postgresql://localhost:5432/syncope?stringtype=unspecified");
- dataSource.setUsername("syncope");
- dataSource.setPassword("syncope");
- Connection conn = dataSource.getConnection();
- Statement stmt = conn.createStatement();
- Map<String, Map<String, PGUPlainAttr>> users = new LinkedHashMap<>();
- view(stmt.executeQuery("SELECT * FROM group_search_attr"), users, false);
- view(stmt.executeQuery("SELECT * FROM group_search_unique_attr"), users, true);
- users.forEach((key, attrs) -> {
- System.out.println("ZZZZZZZZZZZZ " + key + "\n");
- System.out.println("ZZZZZZZZZZZZ\nplainAttrs=\"" + POJOHelper.serialize(attrs.values()).replace("\"",
- """) + "\"/>");
- });
- }
- }
Add Comment
Please, Sign In to add comment