@Override
  public List<DNS53HostedZone> getAllHostedZones() {
    List<DNS53HostedZone> result = new LinkedList<DNS53HostedZone>();

    String query = "SELECT * FROM msi.zones;";
    try {
      Statement stmt = this.sqlConnection.createStatement();
      ResultSet rs = stmt.executeQuery(query);
      while (rs.next()) {
        DNS53HostedZone temp = new DNS53HostedZone();
        temp.setId(rs.getString("ID"));
        temp.setAccount(rs.getLong("accountId"));
        temp.setCallerRefernce(rs.getString("callerReference"));
        temp.setComment(rs.getString("comment"));
        temp.setName(rs.getString("name"));
        temp.setTableName(rs.getString("tableName"));
        result.add(temp);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return result;
  }
  /**
   * Populate the new hosted zone data into MySQL database
   *
   * @param domainName name of the hosted zone
   * @param callerRef unique caller reference for this request
   * @param comment user's comment for this request
   * @return ID of the new hosted zone (automatically issued); "DUPLICATE_NAME" is returned if
   *     target name already exists
   * @throws InternalErrorException
   */
  @Override
  public List<String> createHostedZone(
      final Session session, String domainName, String callerRef, String comment, long acid)
      throws ErrorResponse {
    List<String> result = new LinkedList<String>();
    // String tableName = acid + callerRef;
    String tableName = "B" + UUID.randomUUID().toString().replace("-", "").toUpperCase();
    if (callerReferenceIsUsed(callerRef, acid)) {
      result.add("DUPLICATE_REFERENCE");
      return result; // response: signal that the name is already in use
    }
    String domainNameDot = domainName;
    if (domainName.charAt(domainName.length() - 1) != '.') {
      domainNameDot += ".";
    } else {
      domainName = domainName.substring(0, domainName.length() - 1);
    }

    if (domainExists(domainNameDot, acid)) {
      result.add("DUPLICATE_NAME");
      return result;
    }
    String query =
        "CREATE TABLE `"
            + tableName
            + "` ("
            + "		  name varchar(255) default NULL,"
            + "		  ttl int(11) default NULL,"
            + "		  rdtype varchar(255) default NULL,"
            + "		  rdata varchar(255) default NULL"
            + "		) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
    try {
      Statement stmt = this.sqlConnection.createStatement();
      stmt.executeUpdate(query);
      stmt.close();
    } catch (SQLException e) {
      System.err.println("Failed to create a new schema in MySQL database.");
      e.printStackTrace();
      throw DNS53Faults.InternalError(); // just put some bogus UUID
      // unless RequestID becomes
      // important this layer
    }
    // insert this new ID-name mapping entry including caller reference and
    // comment
    String uniqueID = "Z" + UUID.randomUUID().toString().replace("-", "").toUpperCase();
    final DNS53HostedZone zone = new DNS53HostedZone();
    zone.setId(uniqueID);
    zone.setName(domainNameDot);
    zone.setCallerRefernce(callerRef);
    zone.setComment(comment);
    zone.setAccount(acid);
    zone.setTableName(tableName);
    session.save(zone);

    addRecord(
        tableName,
        domainName,
        259200,
        "SOA",
        domainName + ". hostmaster." + domainName + ". 200309181 28800 7200 86400 28800");
    DNS53ResourceRecord recordSOA = new DNS53ResourceRecord();
    recordSOA.setName(domainNameDot);
    recordSOA.setTtl(259200);
    recordSOA.setRdata(
        domainName + ". hostmaster." + domainName + ". 200309181 28800 7200 86400 28800");
    recordSOA.setRdtype("SOA");
    recordSOA.setZoneId(uniqueID);
    recordSOA.setZoneName(domainNameDot);
    session.save(recordSOA);

    addRecord(tableName, domainName, 259200, "NS", "ns0." + domainName + ".");
    DNS53ResourceRecord recordNS0 = new DNS53ResourceRecord();
    recordNS0.setName(domainNameDot);
    recordNS0.setTtl(259200);
    recordNS0.setRdata("ns0." + domainName + ".");
    recordNS0.setRdtype("NS");
    recordNS0.setZoneId(uniqueID);
    recordNS0.setZoneName(domainNameDot);
    session.save(recordNS0);

    addRecord(tableName, domainName, 259200, "NS", "ns1." + domainName + ".");
    DNS53ResourceRecord recordNS1 = new DNS53ResourceRecord();
    recordNS1.setName(domainNameDot);
    recordNS1.setTtl(259200);
    recordNS1.setRdata("ns1." + domainName + ".");
    recordNS1.setRdtype("NS");
    recordNS1.setZoneId(uniqueID);
    recordNS1.setZoneName(domainNameDot);
    session.save(recordNS1);

    final String nameserverIp =
        (String) ConfigurationUtil.getConfiguration(Arrays.asList(new String[] {"DNS_IP"}));
    String ns0name = "ns0." + domainName;
    String ns1name = "ns1." + domainName;
    String ns0nameDot = "ns0." + domainNameDot;
    String ns1nameDot = "ns1." + domainNameDot;
    addRecord(tableName, ns0name, 259200, "A", nameserverIp);
    DNS53ResourceRecord recordA0 = new DNS53ResourceRecord();
    recordA0.setName(ns0nameDot);
    recordA0.setTtl(259200);
    recordA0.setRdata(nameserverIp);
    recordA0.setRdtype("A");
    recordA0.setZoneId(uniqueID);
    recordA0.setZoneName(domainNameDot);
    session.save(recordA0);

    addRecord(tableName, ns1name, 259200, "A", nameserverIp);
    DNS53ResourceRecord recordA1 = new DNS53ResourceRecord();
    recordA1.setName(ns1nameDot);
    recordA1.setTtl(259200);
    recordA1.setRdata(nameserverIp);
    recordA1.setRdtype("A");
    recordA1.setZoneId(uniqueID);
    recordA1.setZoneName(domainNameDot);
    session.save(recordA1);

    result.add(uniqueID);
    result.add(tableName);
    result.add(ns0name);
    result.add(ns1name);

    session.save(zone);

    return result;
  }