Search in sources :

Example 16 with User

use of com.ramussoft.net.common.User in project ramus by Vitaliy-Yakovchuk.

the class UserFactoryImpl method getUsers.

@SuppressWarnings("unchecked")
@Override
public List<User> getUsers() {
    return (List<User>) template.execute(new JDBCCallback() {

        @Override
        public Object execute(Connection connection) throws SQLException {
            List<User> result = new ArrayList<User>();
            Statement st = connection.createStatement();
            PreparedStatement groups = connection.prepareStatement("SELECT * FROM users_groups WHERE \"login\"=? ORDER BY group_name");
            ResultSet rs = st.executeQuery("SELECT * FROM users ORDER BY \"login\"");
            PreparedStatement groupQualifiers = template.getConnection().prepareStatement("SELECT qualifier_id FROM group_qualifier_access WHERE group_name=? ORDER BY qualifier_id");
            while (rs.next()) {
                User user = createUser(groups, rs, groupQualifiers);
                result.add(user);
            }
            groupQualifiers.close();
            groups.close();
            rs.close();
            st.close();
            return result;
        }
    });
}
Also used : User(com.ramussoft.net.common.User) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) JDBCCallback(com.ramussoft.jdbc.JDBCCallback) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement)

Example 17 with User

use of com.ramussoft.net.common.User in project ramus by Vitaliy-Yakovchuk.

the class UserFactoryImpl method createUser.

private User createUser(PreparedStatement groups, ResultSet rs, PreparedStatement groupQualifiers) throws SQLException {
    User user = new User();
    user.setName(rs.getString("name").trim());
    String login = rs.getString("login").trim();
    user.setLogin(login);
    user.setPassword(rs.getString("password").trim());
    groups.setString(1, login);
    ResultSet grs = groups.executeQuery();
    while (grs.next()) {
        Group group = new Group();
        group.setName(grs.getString("group_name").trim());
        fillGroup(group, groupQualifiers);
        user.getGroups().add(group);
    }
    grs.close();
    return user;
}
Also used : Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User) ResultSet(java.sql.ResultSet)

Aggregations

User (com.ramussoft.net.common.User)17 Group (com.ramussoft.net.common.Group)7 ResultSet (java.sql.ResultSet)3 JDBCCallback (com.ramussoft.jdbc.JDBCCallback)2 ActionEvent (java.awt.event.ActionEvent)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractAction (javax.swing.AbstractAction)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 PluginFactory (com.ramussoft.common.PluginFactory)1 PluginProvider (com.ramussoft.common.PluginProvider)1 Qualifier (com.ramussoft.common.Qualifier)1 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)1 IntegrityAccessorSuit (com.ramussoft.core.impl.IntegrityAccessorSuit)1 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)1 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)1 ActionDescriptor (com.ramussoft.gui.common.ActionDescriptor)1