Search in sources :

Example 1 with User

use of com.wplatform.ddal.dbobject.User in project jdbc-shards by wplatform.

the class JdbcDataSource method getConnection.

/**
     * Open a new connection using the current URL and the specified user name
     * and password.
     *
     * @param user     the user name
     * @param password the password
     * @return the connection
     */
@Override
public Connection getConnection(String user, String password) throws SQLException {
    User userObject = database.getUser(user);
    SessionInterface session = database.createSession(userObject);
    JdbcConnection conn = new JdbcConnection(session, user, this.configLocation);
    return conn;
}
Also used : User(com.wplatform.ddal.dbobject.User) SessionInterface(com.wplatform.ddal.engine.SessionInterface)

Example 2 with User

use of com.wplatform.ddal.dbobject.User in project jdbc-shards by wplatform.

the class Database method openDatabase.

private synchronized void openDatabase() {
    User systemUser = new User(this, allocateObjectId(), SYSTEM_USER_NAME);
    systemUser.setAdmin(true);
    systemUser.setUserPasswordHash(new byte[0]);
    users.put(SYSTEM_USER_NAME, systemUser);
    Schema schema = new Schema(this, allocateObjectId(), Constants.SCHEMA_MAIN, systemUser, true);
    schemas.put(schema.getName(), schema);
    Role publicRole = new Role(this, 0, Constants.PUBLIC_ROLE_NAME, true);
    roles.put(Constants.PUBLIC_ROLE_NAME, publicRole);
    Session sysSession = createSession(systemUser);
    try {
        SchemaConfig sc = configuration.getSchemaConfig();
        List<TableConfig> ctList = sc.getTables();
        for (TableConfig tableConfig : ctList) {
            String identifier = tableConfig.getName();
            identifier = identifier(identifier);
            TableMate tableMate = new TableMate(schema, allocateObjectId(), identifier);
            tableMate.setTableRouter(tableConfig.getTableRouter());
            tableMate.setShards(tableConfig.getShards());
            tableMate.setScanLevel(tableConfig.getScanLevel());
            tableMate.loadMataData(sysSession);
            if (tableConfig.isValidation()) {
                tableMate.check();
            }
            this.addSchemaObject(tableMate);
        }
    } finally {
        sysSession.close();
    }
}
Also used : Role(com.wplatform.ddal.dbobject.Role) User(com.wplatform.ddal.dbobject.User) SchemaConfig(com.wplatform.ddal.config.SchemaConfig) Schema(com.wplatform.ddal.dbobject.schema.Schema) TableConfig(com.wplatform.ddal.config.TableConfig) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Example 3 with User

use of com.wplatform.ddal.dbobject.User in project jdbc-shards by wplatform.

the class Parser method parseAlterUser.

private AlterUser parseAlterUser() {
    String userName = readUniqueIdentifier();
    if (readIf("SET")) {
        AlterUser command = new AlterUser(session);
        command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
        command.setUser(database.getUser(userName));
        if (readIf("PASSWORD")) {
            command.setPassword(readExpression());
        } else if (readIf("SALT")) {
            command.setSalt(readExpression());
            read("HASH");
            command.setHash(readExpression());
        } else {
            throw getSyntaxError();
        }
        return command;
    } else if (readIf("RENAME")) {
        read("TO");
        AlterUser command = new AlterUser(session);
        command.setType(CommandInterface.ALTER_USER_RENAME);
        command.setUser(database.getUser(userName));
        String newName = readUniqueIdentifier();
        command.setNewName(newName);
        return command;
    } else if (readIf("ADMIN")) {
        AlterUser command = new AlterUser(session);
        command.setType(CommandInterface.ALTER_USER_ADMIN);
        User user = database.getUser(userName);
        command.setUser(user);
        if (readIf("TRUE")) {
            command.setAdmin(true);
        } else if (readIf("FALSE")) {
            command.setAdmin(false);
        } else {
            throw getSyntaxError();
        }
        return command;
    }
    throw getSyntaxError();
}
Also used : User(com.wplatform.ddal.dbobject.User)

Aggregations

User (com.wplatform.ddal.dbobject.User)3 SchemaConfig (com.wplatform.ddal.config.SchemaConfig)1 TableConfig (com.wplatform.ddal.config.TableConfig)1 Role (com.wplatform.ddal.dbobject.Role)1 Schema (com.wplatform.ddal.dbobject.schema.Schema)1 TableMate (com.wplatform.ddal.dbobject.table.TableMate)1 SessionInterface (com.wplatform.ddal.engine.SessionInterface)1