mysql-connector-java-5.1.30-bin

16:39:13.462 INFO  jd.cli.Main - Decompiling mysql-connector-java-5.1.30-bin.jar
package com.mysql.fabric;

import java.util.List;

public class DumpResponse
{
  private List<?> returnValue;
  private int ttl;
  
  public DumpResponse(List<?> responseData)
  {
    ttl = ((Integer)responseData.get(2)).intValue();
    returnValue = ((List)responseData.get(3));
  }
  
  public List getReturnValue()
  {
    return returnValue;
  }
  
  public int getTtl()
  {
    return ttl;
  }
  
  public String dumpReturnValue()
  {
    StringBuffer b = new StringBuffer();
    if ((returnValue.size() > 0) && (List.class.isAssignableFrom(returnValue.get(0).getClass()))) {
      for (List l : returnValue)
      {
        b.append("[\n");
        for (Object o : l)
        {
          b.append(" " + o.toString());
          b.append(" (" + o.getClass() + "),\n");
        }
        b.append("]\n");
      }
    } else {
      for (Object o : returnValue) {
        b.append(o.toString() + ",");
      }
    }
    return b.toString();
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.DumpResponse
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public class FabricCommunicationException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public FabricCommunicationException(Throwable cause)
  {
    super(cause);
  }
  
  public FabricCommunicationException(String message)
  {
    super(message);
  }
  
  public FabricCommunicationException(String message, Throwable cause)
  {
    super(message, cause);
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.FabricCommunicationException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import com.mysql.fabric.proto.xmlrpc.XmlRpcClient;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class FabricConnection
{
  private XmlRpcClient client;
  private Map<String, ShardMapping> shardMappingsByTableName = new HashMap();
  private Map<String, ServerGroup> serverGroupsByName = new HashMap();
  private long shardMappingsExpiration;
  private long serverGroupsExpiration;
  
  public FabricConnection(String url, String username, String password)
    throws FabricCommunicationException
  {
    client = new XmlRpcClient(url, username, password);
    refreshState();
  }
  
  public FabricConnection(Set<String> urls, String username, String password)
    throws FabricCommunicationException
  {
    throw new UnsupportedOperationException("Multiple connections not supported.");
  }
  
  public String getInstanceUuid()
  {
    return null;
  }
  
  public int getVersion()
  {
    return 0;
  }
  
  public int refreshState()
    throws FabricCommunicationException
  {
    FabricStateResponse<Set<ServerGroup>> serverGroups = client.getServerGroups();
    FabricStateResponse<Set<ShardMapping>> shardMappings = client.getShardMappings();
    serverGroupsExpiration = serverGroups.getExpireTimeMillis();
    shardMappingsExpiration = shardMappings.getExpireTimeMillis();
    for (ServerGroup g : (Set)serverGroups.getData()) {
      serverGroupsByName.put(g.getName(), g);
    }
    for (Iterator i$ = ((Set)shardMappings.getData()).iterator(); i$.hasNext();)
    {
      m = (ShardMapping)i$.next();
      for (ShardTable t : m.getShardTables()) {
        shardMappingsByTableName.put(t.getDatabase() + "." + t.getTable(), m);
      }
    }
    ShardMapping m;
    return 0;
  }
  
  public ServerGroup getServerGroup(String serverGroupName)
    throws FabricCommunicationException
  {
    if (isStateExpired()) {
      refreshState();
    }
    return (ServerGroup)serverGroupsByName.get(serverGroupName);
  }
  
  public ShardMapping getShardMapping(String database, String table)
    throws FabricCommunicationException
  {
    if (isStateExpired()) {
      refreshState();
    }
    return (ShardMapping)shardMappingsByTableName.get(database + "." + table);
  }
  
  public boolean isStateExpired()
  {
    return (System.currentTimeMillis() > shardMappingsExpiration) || (System.currentTimeMillis() > serverGroupsExpiration);
  }
  
  public Set<String> getFabricHosts()
  {
    return null;
  }
  
  public XmlRpcClient getClient()
  {
    return client;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.FabricConnection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public class FabricStateResponse<T>
{
  private T data;
  private long expireTimeMillis;
  
  public FabricStateResponse(T data, int secsTtl)
  {
    this.data = data;
    expireTimeMillis = (System.currentTimeMillis() + 1000 * secsTtl);
  }
  
  public FabricStateResponse(T data, long expireTimeMillis)
  {
    this.data = data;
    this.expireTimeMillis = expireTimeMillis;
  }
  
  public T getData()
  {
    return (T)data;
  }
  
  public long getExpireTimeMillis()
  {
    return expireTimeMillis;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.FabricStateResponse
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Comparator;

class HashShardMapping$ReverseShardIndexSorter
  implements Comparator<ShardIndex>
{
  public int compare(ShardIndex i1, ShardIndex i2)
  {
    return i2.getBound().compareTo(i1.getBound());
  }
  
  public static final ReverseShardIndexSorter instance = new ReverseShardIndexSorter();
}

/* Location:
 * Qualified Name:     com.mysql.fabric.HashShardMapping.ReverseShardIndexSorter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class HashShardMapping
  extends ShardMapping
{
  private static final MessageDigest md5Hasher;
  
  private static class ReverseShardIndexSorter
    implements Comparator<ShardIndex>
  {
    public int compare(ShardIndex i1, ShardIndex i2)
    {
      return i2.getBound().compareTo(i1.getBound());
    }
    
    public static final ReverseShardIndexSorter instance = new ReverseShardIndexSorter();
  }
  
  static
  {
    try
    {
      md5Hasher = MessageDigest.getInstance("MD5");
    }
    catch (NoSuchAlgorithmException ex)
    {
      throw new ExceptionInInitializerError(ex);
    }
  }
  
  public HashShardMapping(String mappingId, ShardingType shardingType, String globalGroupName, Set<ShardTable> shardTables, Set<ShardIndex> shardIndices)
  {
    super(mappingId, shardingType, globalGroupName, shardTables, new TreeSet(ReverseShardIndexSorter.instance));
    
    this.shardIndices.addAll(shardIndices);
  }
  
  protected ShardIndex getShardIndexForKey(String stringKey)
  {
    String hashedKey = new BigInteger(1, md5Hasher.digest(stringKey.getBytes())).toString(16).toUpperCase();
    for (int i = 0; i < 32 - hashedKey.length(); i++) {
      hashedKey = "0" + hashedKey;
    }
    for (ShardIndex i : shardIndices) {
      if (i.getBound().compareTo(hashedKey) <= 0) {
        return i;
      }
    }
    return (ShardIndex)shardIndices.iterator().next();
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.HashShardMapping
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Comparator;

class RangeShardMapping$RangeShardIndexSorter
  implements Comparator<ShardIndex>
{
  public int compare(ShardIndex i1, ShardIndex i2)
  {
    Integer bound1 = Integer.valueOf(Integer.parseInt(i1.getBound()));
    Integer bound2 = Integer.valueOf(Integer.parseInt(i2.getBound()));
    return bound2.compareTo(bound1);
  }
  
  public static final RangeShardIndexSorter instance = new RangeShardIndexSorter();
}

/* Location:
 * Qualified Name:     com.mysql.fabric.RangeShardMapping.RangeShardIndexSorter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class RangeShardMapping
  extends ShardMapping
{
  private static class RangeShardIndexSorter
    implements Comparator<ShardIndex>
  {
    public int compare(ShardIndex i1, ShardIndex i2)
    {
      Integer bound1 = Integer.valueOf(Integer.parseInt(i1.getBound()));
      Integer bound2 = Integer.valueOf(Integer.parseInt(i2.getBound()));
      return bound2.compareTo(bound1);
    }
    
    public static final RangeShardIndexSorter instance = new RangeShardIndexSorter();
  }
  
  public RangeShardMapping(String mappingId, ShardingType shardingType, String globalGroupName, Set<ShardTable> shardTables, Set<ShardIndex> shardIndices)
  {
    super(mappingId, shardingType, globalGroupName, shardTables, new TreeSet(RangeShardIndexSorter.instance));
    this.shardIndices.addAll(shardIndices);
  }
  
  protected ShardIndex getShardIndexForKey(String stringKey)
  {
    Integer key = Integer.valueOf(-1);
    key = Integer.valueOf(Integer.parseInt(stringKey));
    for (ShardIndex i : shardIndices)
    {
      Integer lowerBound = Integer.valueOf(i.getBound());
      if (key.intValue() >= lowerBound.intValue()) {
        return i;
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.RangeShardMapping
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.List;

public class Response
{
  private boolean successful;
  private Object returnValue;
  private String traceString;
  
  public Response(List<?> responseData)
  {
    successful = ((Boolean)responseData.get(0)).booleanValue();
    if (successful)
    {
      returnValue = responseData.get(2);
    }
    else
    {
      traceString = ((String)responseData.get(1));
      String[] trace = traceString.split("\n");
      
      returnValue = trace[(trace.length - 1)];
    }
  }
  
  public boolean isSuccessful()
  {
    return successful;
  }
  
  public Object getReturnValue()
  {
    return returnValue;
  }
  
  public String getTraceString()
  {
    return traceString;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.Response
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public class Server
  implements Comparable<Server>
{
  private String groupName;
  private String uuid;
  private String hostname;
  private int port;
  private ServerMode mode;
  private ServerRole role;
  private double weight;
  
  public Server(String groupName, String uuid, String hostname, int port, ServerMode mode, ServerRole role, double weight)
  {
    this.groupName = groupName;
    this.uuid = uuid;
    this.hostname = hostname;
    this.port = port;
    this.mode = mode;
    this.role = role;
    this.weight = weight;
    assert ((uuid != null) && (!"".equals(uuid)));
    assert ((hostname != null) && (!"".equals(hostname)));
    assert (port > 0);
    assert (mode != null);
    assert (role != null);
    assert (weight > 0.0D);
  }
  
  public String getGroupName()
  {
    return groupName;
  }
  
  public String getUuid()
  {
    return uuid;
  }
  
  public String getHostname()
  {
    return hostname;
  }
  
  public int getPort()
  {
    return port;
  }
  
  public ServerMode getMode()
  {
    return mode;
  }
  
  public ServerRole getRole()
  {
    return role;
  }
  
  public double getWeight()
  {
    return weight;
  }
  
  public String toString()
  {
    return String.format("Server[%s, %s:%d, %s, %s, weight=%s]", new Object[] { uuid, hostname, Integer.valueOf(port), mode, role, Double.valueOf(weight) });
  }
  
  public boolean equals(Object o)
  {
    if (!(o instanceof Server)) {
      return false;
    }
    Server s = (Server)o;
    return s.getUuid().equals(getUuid());
  }
  
  public int hashCode()
  {
    return getUuid().hashCode();
  }
  
  public int compareTo(Server other)
  {
    return getUuid().compareTo(other.getUuid());
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.Server
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Set;

public class ServerGroup
{
  private String name;
  private Set<Server> servers;
  
  public ServerGroup(String name, Set<Server> servers)
  {
    this.name = name;
    this.servers = servers;
  }
  
  public String getName()
  {
    return name;
  }
  
  public Set<Server> getServers()
  {
    return servers;
  }
  
  public String toString()
  {
    return String.format("Group[name=%s, servers=%s]", new Object[] { name, servers });
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ServerGroup
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.HashMap;
import java.util.Map;

public enum ServerMode
{
  OFFLINE,  READ_ONLY,  READ_WRITE;
  
  private static final Map<Integer, ServerMode> serverModesByConstant;
  
  static
  {
    serverModesByConstant = new HashMap();
    
    serverModesByConstant.put(Integer.valueOf(0), OFFLINE);
    serverModesByConstant.put(Integer.valueOf(1), READ_ONLY);
    serverModesByConstant.put(Integer.valueOf(3), READ_WRITE);
  }
  
  public static ServerMode getFromConstant(Integer constant)
  {
    return (ServerMode)serverModesByConstant.get(constant);
  }
  
  private ServerMode() {}
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ServerMode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.HashMap;
import java.util.Map;

public enum ServerRole
{
  SPARE,  SCALE,  SECONDARY,  PRIMARY;
  
  private static final Map<Integer, ServerRole> serverRolesByConstant;
  
  static
  {
    serverRolesByConstant = new HashMap();
    
    serverRolesByConstant.put(Integer.valueOf(0), SPARE);
    serverRolesByConstant.put(Integer.valueOf(1), SCALE);
    serverRolesByConstant.put(Integer.valueOf(2), SECONDARY);
    serverRolesByConstant.put(Integer.valueOf(3), PRIMARY);
  }
  
  public static ServerRole getFromConstant(Integer constant)
  {
    return (ServerRole)serverRolesByConstant.get(constant);
  }
  
  private ServerRole() {}
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ServerRole
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public class ShardIndex
{
  private String bound;
  private Integer shardId;
  private String groupName;
  
  public ShardIndex(String bound, Integer shardId, String groupName)
  {
    this.bound = bound;
    this.shardId = shardId;
    this.groupName = groupName;
  }
  
  public String getBound()
  {
    return bound;
  }
  
  public Integer getShardId()
  {
    return shardId;
  }
  
  public String getGroupName()
  {
    return groupName;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardIndex
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Collections;
import java.util.Set;

public abstract class ShardMapping
{
  private String mappingId;
  private ShardingType shardingType;
  private String globalGroupName;
  protected Set<ShardTable> shardTables;
  protected Set<ShardIndex> shardIndices;
  
  public ShardMapping(String mappingId, ShardingType shardingType, String globalGroupName, Set<ShardTable> shardTables, Set<ShardIndex> shardIndices)
  {
    this.mappingId = mappingId;
    this.shardingType = shardingType;
    this.globalGroupName = globalGroupName;
    this.shardTables = shardTables;
    this.shardIndices = shardIndices;
  }
  
  public String getGroupNameForKey(String key)
  {
    return getShardIndexForKey(key).getGroupName();
  }
  
  protected abstract ShardIndex getShardIndexForKey(String paramString);
  
  public String getMappingId()
  {
    return mappingId;
  }
  
  public ShardingType getShardingType()
  {
    return shardingType;
  }
  
  public String getGlobalGroupName()
  {
    return globalGroupName;
  }
  
  public Set<ShardTable> getShardTables()
  {
    return Collections.unmodifiableSet(shardTables);
  }
  
  public Set<ShardIndex> getShardIndices()
  {
    return Collections.unmodifiableSet(shardIndices);
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardMapping
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

class ShardMappingFactory$1
{
  static
  {
    try
    {
      $SwitchMap$com$mysql$fabric$ShardingType[ShardingType.RANGE.ordinal()] = 1;
    }
    catch (NoSuchFieldError ex) {}
    try
    {
      $SwitchMap$com$mysql$fabric$ShardingType[ShardingType.HASH.ordinal()] = 2;
    }
    catch (NoSuchFieldError ex) {}
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardMappingFactory.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

import java.util.Set;

public class ShardMappingFactory
{
  public ShardMapping createShardMapping(String mappingId, ShardingType shardingType, String globalGroupName, Set<ShardTable> shardTables, Set<ShardIndex> shardIndices)
  {
    ShardMapping sm = null;
    switch (shardingType)
    {
    case RANGE: 
      sm = new RangeShardMapping(mappingId, shardingType, globalGroupName, shardTables, shardIndices);
      break;
    case HASH: 
      sm = new HashShardMapping(mappingId, shardingType, globalGroupName, shardTables, shardIndices);
      break;
    default: 
      throw new IllegalArgumentException("Invalid ShardingType");
    }
    return sm;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardMappingFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public class ShardTable
{
  private String database;
  private String table;
  private String column;
  
  public ShardTable(String database, String table, String column)
  {
    this.database = database;
    this.table = table;
    this.column = column;
  }
  
  public String getDatabase()
  {
    return database;
  }
  
  public String getTable()
  {
    return table;
  }
  
  public String getColumn()
  {
    return column;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardTable
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric;

public enum ShardingType
{
  LIST,  RANGE,  HASH;
  
  private ShardingType() {}
}

/* Location:
 * Qualified Name:     com.mysql.fabric.ShardingType
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric.hibernate;

import com.mysql.fabric.FabricCommunicationException;
import com.mysql.fabric.FabricConnection;
import com.mysql.fabric.Server;
import com.mysql.fabric.ServerGroup;
import com.mysql.fabric.ServerMode;
import com.mysql.fabric.ShardMapping;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider;

public class FabricMultiTenantConnectionProvider
  implements MultiTenantConnectionProvider
{
  private static final long serialVersionUID = 1L;
  private FabricConnection fabricConnection;
  private String database;
  private String table;
  private String user;
  private String password;
  private ShardMapping shardMapping;
  private ServerGroup globalGroup;
  
  public FabricMultiTenantConnectionProvider(String fabricUrl, String database, String table, String user, String password, String fabricUser, String fabricPassword)
  {
    try
    {
      fabricConnection = new FabricConnection(fabricUrl, fabricUser, fabricPassword);
      this.database = database;
      this.table = table;
      this.user = user;
      this.password = password;
      shardMapping = fabricConnection.getShardMapping(this.database, this.table);
      globalGroup = fabricConnection.getServerGroup(shardMapping.getGlobalGroupName());
    }
    catch (FabricCommunicationException ex)
    {
      throw new RuntimeException(ex);
    }
  }
  
  private Connection getReadWriteConnectionFromServerGroup(ServerGroup serverGroup)
    throws SQLException
  {
    for (Server s : serverGroup.getServers()) {
      if (ServerMode.READ_WRITE.equals(s.getMode()))
      {
        String jdbcUrl = String.format("jdbc:mysql://%s:%s/%s", new Object[] { s.getHostname(), Integer.valueOf(s.getPort()), database });
        return DriverManager.getConnection(jdbcUrl, user, password);
      }
    }
    throw new SQLException("Unable to find r/w server for chosen shard mapping in group " + serverGroup.getName());
  }
  
  public Connection getAnyConnection()
    throws SQLException
  {
    return getReadWriteConnectionFromServerGroup(globalGroup);
  }
  
  public Connection getConnection(String tenantIdentifier)
    throws SQLException
  {
    String serverGroupName = shardMapping.getGroupNameForKey(tenantIdentifier);
    try
    {
      ServerGroup serverGroup = fabricConnection.getServerGroup(serverGroupName);
      return getReadWriteConnectionFromServerGroup(serverGroup);
    }
    catch (FabricCommunicationException ex)
    {
      throw new RuntimeException(ex);
    }
  }
  
  public void releaseAnyConnection(Connection connection)
    throws SQLException
  {
    try
    {
      connection.close();
    }
    catch (Exception ex)
    {
      throw new RuntimeException(ex);
    }
  }
  
  public void releaseConnection(String tenantIdentifier, Connection connection)
    throws SQLException
  {
    releaseAnyConnection(connection);
  }
  
  public boolean supportsAggressiveRelease()
  {
    return false;
  }
  
  public boolean isUnwrappableAs(Class unwrapType)
  {
    return false;
  }
  
  public <T> T unwrap(Class<T> unwrapType)
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     com.mysql.fabric.hibernate.FabricMultiTenantConnectionProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric.jdbc;

import com.mysql.fabric.FabricCommunicationException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ConnectionImpl;
import com.mysql.jdbc.ExceptionInterceptor;
import com.mysql.jdbc.MySQLConnection;
import com.mysql.jdbc.SQLError;
import java.sql.SQLException;
import java.util.Properties;

public class ErrorReportingExceptionInterceptor
  implements ExceptionInterceptor
{
  private String hostname;
  private String port;
  private String fabricHaGroup;
  
  public SQLException interceptException(SQLException sqlEx, Connection conn)
  {
    MySQLConnection mysqlConn = (MySQLConnection)conn;
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getLoadBalanceSafeProxy().getClass())) {
      return null;
    }
    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy)mysqlConn.getLoadBalanceSafeProxy();
    try
    {
      return fabricProxy.interceptException(sqlEx, conn, fabricHaGroup, hostname, port);
    }
    catch (FabricCommunicationException ex)
    {
      return SQLError.createSQLException("Failed to report error to Fabric.", "08S01", ex, conn.getExceptionInterceptor(), conn);
    }
  }
  
  public void init(Connection conn, Properties props)
    throws SQLException
  {
    hostname = props.getProperty("HOST");
    port = props.getProperty("PORT");
    String connectionAttributes = props.getProperty("connectionAttributes");
    fabricHaGroup = connectionAttributes.replaceAll("^.*\\bfabricHaGroup:(.+)\\b.*$", "$1");
  }
  
  public void destroy() {}
}

/* Location:
 * Qualified Name:     com.mysql.fabric.jdbc.ErrorReportingExceptionInterceptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric.jdbc;

import com.mysql.fabric.ServerGroup;
import com.mysql.jdbc.MySQLConnection;
import java.sql.SQLException;
import java.util.Set;

public abstract interface FabricMySQLConnection
  extends MySQLConnection
{
  public abstract void clearServerSelectionCriteria()
    throws SQLException;
  
  public abstract void setShardKey(String paramString)
    throws SQLException;
  
  public abstract String getShardKey();
  
  public abstract void setShardTable(String paramString)
    throws SQLException;
  
  public abstract String getShardTable();
  
  public abstract void setServerGroupName(String paramString)
    throws SQLException;
  
  public abstract String getServerGroupName();
  
  public abstract ServerGroup getCurrentServerGroup();
  
  public abstract void clearQueryTables()
    throws SQLException;
  
  public abstract void addQueryTable(String paramString)
    throws SQLException;
  
  public abstract Set<String> getQueryTables();
}

/* Location:
 * Qualified Name:     com.mysql.fabric.jdbc.FabricMySQLConnection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric.jdbc;

import com.mysql.jdbc.ConnectionProperties;

public abstract interface FabricMySQLConnectionProperties
  extends ConnectionProperties
{
  public abstract void setFabricShardKey(String paramString);
  
  public abstract String getFabricShardKey();
  
  public abstract void setFabricShardTable(String paramString);
  
  public abstract String getFabricShardTable();
  
  public abstract void setFabricServerGroup(String paramString);
  
  public abstract String getFabricServerGroup();
  
  public abstract void setFabricProtocol(String paramString);
  
  public abstract String getFabricProtocol();
  
  public abstract void setFabricUsername(String paramString);
  
  public abstract String getFabricUsername();
  
  public abstract void setFabricPassword(String paramString);
  
  public abstract String getFabricPassword();
  
  public abstract void setFabricReportErrors(boolean paramBoolean);
  
  public abstract boolean getFabricReportErrors();
}

/* Location:
 * Qualified Name:     com.mysql.fabric.jdbc.FabricMySQLConnectionProperties
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mysql.fabric.jdbc;

import com.mysql.fabric.FabricCommunicationException;
import com.mysql.fabric.FabricConnection;
import com.mysql.fabric.Server;
import com.mysql.fabric.ServerGroup;
import com.mysql.fabric.ServerMode;
import com.mysql.fabric.ShardMapping;
import com.mysql.fabric.proto.xmlrpc.XmlRpcClient;
import com.mysql.jdbc.Buffer;
import com.mysql.jdbc.CachedResultSetMetaData;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ConnectionProperties;
import com.mysql.jdbc.ConnectionPropertiesImpl;
import com.mysql.jdbc.ExceptionInterceptor;
import com.mysql.jdbc.Extension;
import com.mysql.jdbc.Field;
import com.mysql.jdbc.MySQLConnection;
import com.mysql.jdbc.MysqlIO;
import com.mysql.jdbc.ReplicationConnection;
import com.mysql.jdbc.ResultSetInternalMethods;
import com.mysql.jdbc.SQLError;
import com.mysql.jdbc.ServerPreparedStatement;
import com.mysql.jdbc.SingleByteCharsetConverter;
import com.mysql.jdbc.StatementImpl;
import com.mysql.jdbc.StatementInterceptorV2;
import com.mysql.jdbc.log.Log;
import java.sql.CallableStatement;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import java.util.Timer;
import java.util.concurrent.Executor;

public class FabricMySQLConnectionProxy
  extends ConnectionPropertiesImpl
  implements FabricMySQLConnection, FabricMySQLConnectionProperties
{
  private static final long serialVersionUID = 1L;
  protected FabricConnection fabricConnection;
  protected boolean closed = false;
  protected boolean transactionInProgress = false;
  protected Map<ServerGroup, ReplicationConnection> serverConnections = new HashMap();
  protected ReplicationConnection currentConnection;
  protected String shardKey;
  protected String shardTable;
  protected String serverGroupName;
  protected Set<String> queryTables = new HashSet();
  protected Server server;
  protected ServerGroup serverGroup;
  protected String host;
  protected String port;
  protected String username;
  protected String password;
  protected String database;
  protected ShardMapping shardMapping;
  protected boolean readOnly = false;
  protected boolean autoCommit = true;
  protected int transactionIsolation = 4;
  private String fabricShardKey;
  private String fabricShardTable;
  private String fabricServerGroup;
  private String fabricProtocol;
  private String fabricUsername;
  private String fabricPassword;
  private boolean reportErrors = false;
  
  public FabricMySQLConnectionProxy(Properties props)
    throws SQLException
  {
    fabricShardKey = props.getProperty("fabricShardKey");
    fabricShardTable = props.getProperty("fabricShardTable");
    fabricServerGroup = props.getProperty("fabricServerGroup");
    fabricProtocol = props.getProperty("fabricProtocol");
    fabricUsername = props.getProperty("fabricUsername");
    fabricPassword = props.getProperty("fabricPassword");
    reportErrors = Boolean.valueOf(props.getProperty("fabricReportErrors")).booleanValue();
    props.remove("fabricShardKey");
    props.remove("fabricShardTable");
    props.remove("fabricServerGroup");
    props.remove("fabricProtocol");
    props.remove("fabricUsername");
    props.remove("fabricPassword");
    props.remove("fabricReportErrors");
    
    host = props.getProperty("HOST");
    port = props.getProperty("PORT");
    username = props.getProperty("user");
    password = props.getProperty("password");
    database = props.getProperty("DBNAME");
    if (username == null) {
      username = "";
    }
    if (password == null) {
      password = "";
    }
    String exceptionInterceptors = props.getProperty("exceptionInterceptors");
    if ((exceptionInterceptors == null) || ("null".equals("exceptionInterceptors"))) {
      exceptionInterceptors = "";
    } else {
      exceptionInterceptors = exceptionInterceptors + ",";
    }
    exceptionInterceptors = exceptionInterceptors + "com.mysql.fabric.jdbc.ErrorReportingExceptionInterceptor";
    props.setProperty("exceptionInterceptors", exceptionInterceptors);
    
    initializeProperties(props);
    if ((fabricServerGroup != null) && (fabricShardTable != null)) {
      throw SQLError.createSQLException("Server group and shard table are mutually exclusive. Only one may be provided.", "08004", null, getExceptionInterceptor(), this);
    }
    try
    {
      String url = fabricProtocol + "://" + host + ":" + port;
      fabricConnection = new FabricConnection(url, fabricUsername, fabricPassword);
    }
    catch (FabricCommunicationException ex)
    {
      throw SQLError.createSQLException("Unable to establish connection to the Fabric server", "08004", ex, getExceptionInterceptor(), this);
    }
    setShardTable(fabricShardTable);
    setShardKey(fabricShardKey);
    
    setServerGroupName(fabricServerGroup);
  }
  
  private boolean intercepting = false;
  
  SQLException interceptException(SQLException sqlEx, Connection conn, String group, String hostname, String portnumber)
    throws FabricCommunicationException
  {
    if (!sqlEx.getSQLState().startsWith("08")) {
      return null;
    }
    if (intercepting) {
      return null;
    }
    intercepting = true;
    try
    {
      Server currentServer = null;
      ServerGroup currentGroup = fabricConnection.getServerGroup(group);
      for (Server s : currentGroup.getServers()) {
        if ((s.getHostname().equals(hostname)) && (Integer.valueOf(s.getPort()).toString().equals(portnumber)))
        {
          currentServer = s;
          break;
        }
      }
      if (currentServer == null) {
        return SQLError.createSQLException("Unable to lookup server to report error to Fabric", sqlEx.getSQLState(), sqlEx, getExceptionInterceptor(), this);
      }
      if (reportErrors) {
        fabricConnection.getClient().reportServerError(currentServer, sqlEx.toString(), true);
      }
      serverConnections.remove(serverGroup);
      try
      {
        currentConnection.close();
      }
      catch (SQLException ex) {}
      currentConnection = null;
      serverGroup = currentGroup;
    }
    finally
    {
      intercepting = false;
    }
    return null;
  }
  
  public void setShardKey(String shardKey)
    throws SQLException
  {
    ensureNoTransactionInProgress();
    
    currentConnection = null;
    if (shardKey != null)
    {
      if (serverGroupName != null) {
        throw SQLError.createSQLException("Shard key cannot be provided when server group is chosen directly.", "S1009", null, getExceptionInterceptor(), this);
      }
      if (shardTable == null) {
        throw SQLError.createSQLException("Shard key cannot be provided with a shard table.", "S1009", null, getExceptionInterceptor(), this);
      }
      server = null;
      
      setCurrentServerGroup(shardMapping.getGroupNameForKey(shardKey));
    }
    else if (shardTable != null)
    {
      setCurrentServerGroup(shardMapping.getGlobalGroupName());
    }
    this.shardKey = shardKey;
  }
  
  public String getShardKey()
  {
    return shardKey;
  }
  
  public void setShardTable(String shardTable)
    throws SQLException
  {
    ensureNoTransactionInProgress();
    
    currentConnection = null;
    if (serverGroupName != null) {
      throw SQLError.createSQLException("Server group and shard table are mutually exclusive. Only one may be provided.", "S1009", null, getExceptionInterceptor(), this);
    }
    server = null;
    shardKey = null;
    serverGroup = null;
    this.shardTable = shardTable;
    if (shardTable == null)
    {
      shardMapping = null;
    }
    else
    {
      String table = shardTable;
      String db = database;
      if (shardTable.contains("."))
      {
        String[] pair = shardTable.split("\\.");
        table = pair[0];
        db = pair[1];
      }
      try
      {
        shardMapping = fabricConnection.getShardMapping(db, table);
        if (shardMapping == null) {
          throw SQLError.createSQLException("Shard mapping not found for table `" + shardTable + "'", "S1009", null, getExceptionInterceptor(), this);
        }
        setCurrentServerGroup(shardMapping.getGlobalGroupName());
      }
      catch (FabricCommunicationException ex)
      {
        throw SQLError.createSQLException("Fabric communication failure.", "08S01", ex, getExceptionInterceptor(), this);
      }
    }
  }
  
  public String getShardTable()
  {
    return shardTable;
  }
  
  public void setServerGroupName(String serverGroupName)
    throws SQLException
  {
    ensureNoTransactionInProgress();
    
    currentConnection = null;
    if (serverGroupName != null) {
      setCurrentServerGroup(serverGroupName);
    }
    this.serverGroupName = serverGroupName;
  }
  
  public String getServerGroupName()
  {
    return serverGroupName;
  }
  
  public void clearServerSelectionCriteria()
    throws SQLException
  {
    ensureNoTransactionInProgress();
    shardTable = null;
    shardKey = null;
    serverGroupName = null;
    server = null;
    serverGroup = null;
    queryTables.clear();
    currentConnection = null;
  }
  
  public ServerGroup getCurrentServerGroup()
  {
    return serverGroup;
  }
  
  public void clearQueryTables()
    throws SQLException
  {
    ensureNoTransactionInProgress();
    
    currentConnection = null;
    
    queryTables.clear();
    setShardTable(null);
  }
  
  public void addQueryTable(String tableName)
    throws SQLException
  {
    ensureNoTransactionInProgress();
    
    currentConnection = null;
    try
    {
      if (shardMapping == null)
      {
        if (fabricConnection.getShardMapping(database, tableName) != null) {
          setShardTable(tableName);
        }
      }
      else
      {
        ShardMapping mappingForTableName = fabricConnection.getShardMapping(database, tableName);
        if ((mappingForTableName != null) && (!mappingForTableName.equals(shardMapping))) {
          throw SQLError.createSQLException("Cross-shard query not allowed", "S1009", null, getExceptionInterceptor(), this);
        }
      }
      queryTables.add(tableName);
    }
    catch (FabricCommunicationException ex)
    {
      throw SQLError.createSQLException("Fabric communication failure.", "08S01", ex, getExceptionInterceptor(), this);
    }
  }
  
  public Set<String> getQueryTables()
  {
    return queryTables;
  }
  
  protected void setCurrentServerGroup(String serverGroupName)
    throws SQLException
  {
    server = null;
    serverGroup = null;
    try
    {
      serverGroup = fabricConnection.getServerGroup(serverGroupName);
    }
    catch (FabricCommunicationException ex)
    {
      throw SQLError.createSQLException("Fabric communication failure.", "08S01", ex, getExceptionInterceptor(), this);
    }
    if (serverGroup == null) {
      throw SQLError.createSQLException("Cannot find server group: `" + serverGroupName + "'", "S1009", null, getExceptionInterceptor(), this);
    }
  }
  
  protected MySQLConnection getActiveMySQLConnection()
    throws SQLException
  {
    ReplicationConnection c = (ReplicationConnection)getActiveConnection();
    MySQLConnection mc = (MySQLConnection)c.getCurrentConnection();
    return mc;
  }
  
  protected MySQLConnection getActiveMySQLConnectionPassive()
  {
    try
    {
      return getActiveMySQLConnection();
    }
    catch (SQLException ex)
    {
      throw new IllegalStateException("Unable to determine active connection", ex);
    }
  }
  
  protected Connection getActiveConnectionPassive()
  {
    try
    {
      return getActiveConnection();
    }
    catch (SQLException ex)
    {
      throw new IllegalStateException("Unable to determine active connection", ex);
    }
  }
  
  protected Connection getActiveConnection()
    throws SQLException
  {
    if (currentConnection != null) {
      return currentConnection;
    }
    if (getCurrentServerGroup() == null) {
      throw SQLError.createSQLException("No server group selected.", "08004", null, getExceptionInterceptor(), this);
    }
    currentConnection = ((ReplicationConnection)serverConnections.get(serverGroup));
    if (currentConnection != null) {
      return currentConnection;
    }
    List<String> masterHost = new ArrayList();
    List<String> slaveHosts = new ArrayList();
    for (Server s : serverGroup.getServers()) {
      if (ServerMode.READ_WRITE.equals(s.getMode())) {
        masterHost.add(s.getHostname() + ":" + s.getPort());
      } else {
        slaveHosts.add(s.getHostname() + ":" + s.getPort());
      }
    }
    Properties info = exposeAsProperties(null);
    info.put("replicationConnectionGroup", serverGroup.getName());
    info.setProperty("user", username);
    info.setProperty("password", password);
    info.setProperty("DBNAME", getCatalog());
    info.setProperty("connectionAttributes", "fabricHaGroup:" + serverGroup.getName());
    currentConnection = new ReplicationConnection(info, info, masterHost, slaveHosts);
    serverConnections.put(serverGroup, currentConnection);
    
    currentConnection.setProxy(this);
    currentConnection.setAutoCommit(autoCommit);
    currentConnection.setReadOnly(readOnly);
    currentConnection.setTransactionIsolation(transactionIsolation);
    return currentConnection;
  }
  
  private void ensureOpen()
    throws SQLException
  {
    if (closed) {
      throw SQLError.createSQLException("No operations allowed after connection closed.", "08003", getExceptionInterceptor());
    }
  }
  
  private void ensureNoTransactionInProgress()
    throws SQLException
  {
    ensureOpen();
    if ((transactionInProgress) && (!autoCommit)) {
      throw SQLError.createSQLException("Not allow while a transaction is active.", "25000", getExceptionInterceptor());
    }
  }
  
  public void close()
    throws SQLException
  {
    closed = true;
    for (Connection c : serverConnections.values()) {
      try
      {
        c.close();
      }
      catc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd