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;
}
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();
}
}
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();
}
Aggregations