/** * INTERNAL */ public JdbcConnection(String url, Properties info) throws SQLException { this(new ConnectionInfo(url, info)); }
@Override public ServerSession createSession(String url) { return createSession(new ConnectionInfo(url)); }
default Session createSession(String url) { return createSession(new ConnectionInfo(url)); }
public ConnectionInfo copy(String newServer) { ConnectionInfo ci = new ConnectionInfo(); ci.prop.putAll(prop); StringBuilder buff = new StringBuilder(Constants.URL_PREFIX); buff.append(Constants.URL_TCP).append("//").append(newServer).append('/').append(dbName); ci.url = buff.toString(); ci.user = user; ci.filePasswordHash = filePasswordHash; ci.fileEncryptionKey = fileEncryptionKey; ci.userPasswordHash = userPasswordHash; ci.dbName = dbName; ci.nameNormalized = nameNormalized; ci.remote = remote; ci.ssl = ssl; ci.embedded = embedded; ci.servers = newServer; ci.sessionFactory = sessionFactory; ci.persistent = persistent; return ci; }
public String getURL(String hostId) { if (connectionInfo == null) { String dbName = database.getShortName(); String url = createURL(dbName, hostId); connectionInfo = new ConnectionInfo(url, dbName); connectionInfo.setUserName(user.getName()); connectionInfo.setUserPasswordHash(user.getUserPasswordHash()); return url; } StringBuilder buff = new StringBuilder(); String url = connectionInfo.getURL(); int pos1 = url.indexOf("//") + 2; buff.append(url.substring(0, pos1)).append(hostId); int pos2 = url.indexOf('/', pos1); buff.append(url.substring(pos2)); return buff.toString(); }
public static Session getSession(ServerSession originalSession, String url, boolean remote) { Session session = remote ? getQueue(url).poll() : null; // 在本地创建session时不用从缓存队列中找 if (session == null || session.isClosed()) { ConnectionInfo oldCi = originalSession.getConnectionInfo(); // 未来新加的代码如果忘记设置这个字段,出问题时方便查找原因 if (oldCi == null) { throw DbException.throwInternalError(); } ConnectionInfo ci = new ConnectionInfo(url, oldCi.getProperties()); ci.setProperty("IS_LOCAL", "true"); ci.setUserName(oldCi.getUserName()); ci.setUserPasswordHash(oldCi.getUserPasswordHash()); ci.setFilePasswordHash(oldCi.getFilePasswordHash()); ci.setFileEncryptionKey(oldCi.getFileEncryptionKey()); ci.setRemote(remote); // 因为已经精确知道要连哪个节点了,connect不用考虑运行模式,所以用false session = ci.createSession().connect(false); } return session; }
private Session createSession(Transfer transfer, int sessionId, String originalURL, String dbName, String userName) throws IOException { ConnectionInfo ci = new ConnectionInfo(originalURL, dbName); ci.setUserName(userName); ci.setUserPasswordHash(transfer.readBytes()); ci.setFilePasswordHash(transfer.readBytes()); ci.setFileEncryptionKey(transfer.readBytes()); int len = transfer.readInt(); for (int i = 0; i < len; i++) { String key = transfer.readString(); String value = transfer.readString(); ci.addProperty(key, value, true); // 一些不严谨的client driver可能会发送重复的属性名 } if (baseDir == null) { baseDir = SysProperties.getBaseDirSilently(); } // override client's requested properties with server settings if (baseDir != null) { ci.setBaseDir(baseDir); } Session session = ci.createSession(); if (session.isValid()) { addSession(sessionId, session); assignCommandHandler(sessionId); } return session; }