1 25 package com.mysql.jdbc; 26 27 import java.rmi.server.UID ; 28 import java.sql.SQLException ; 29 import java.sql.Savepoint ; 30 31 38 public class MysqlSavepoint implements Savepoint { 39 private static String getUniqueId() { 40 String uidStr = new UID ().toString(); 42 43 int uidLength = uidStr.length(); 44 45 StringBuffer safeString = new StringBuffer (uidLength); 46 47 for (int i = 0; i < uidLength; i++) { 48 char c = uidStr.charAt(i); 49 50 if (Character.isLetter(c) || Character.isDigit(c)) { 51 safeString.append(c); 52 } else { 53 safeString.append('_'); 54 } 55 } 56 57 return safeString.toString(); 58 } 59 60 private String savepointName; 61 62 70 MysqlSavepoint() throws SQLException { 71 this(getUniqueId()); 72 } 73 74 83 MysqlSavepoint(String name) throws SQLException { 84 if (name == null || name.length() == 0) { 85 throw new SQLException ("Savepoint name can not be NULL or empty", 86 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 87 } 88 89 this.savepointName = name; 90 } 91 92 95 public int getSavepointId() throws SQLException { 96 throw new SQLException ("Only named savepoints are supported.", 97 SQLError.SQL_STATE_DRIVER_NOT_CAPABLE); 98 } 99 100 103 public String getSavepointName() throws SQLException { 104 return this.savepointName; 105 } 106 } 107 | Popular Tags |