예제 #1
0
 public String removeFromDB() {
   if (!wordExists()) {
     return String.valueOf(
         ChatColor.RED
             + "The word "
             + ChatColor.GOLD
             + word.getName()
             + ChatColor.RED
             + " does not exist!");
   } else {
     // ResultSet rs = null;
     if (sqltype.equals(SQLType.SQLite)) {
       sqlite.query(Query.DELETE_FROM.value() + "name='" + word.getName() + "'");
     }
     if (sqltype.equals(SQLType.MySQL)) {
       mysql.query(Query.DELETE_FROM.value() + "name='" + word.getName() + "'");
     }
     /*if (rs.equals(null)){
     	return String.valueOf(ChatColor.RED+"Error occured while deleting the word '"+word.getName()+"' Please check console for more info.");
     }*/
     return String.valueOf(
         ChatColor.GREEN
             + "Word "
             + ChatColor.GOLD
             + word.getName()
             + ChatColor.GREEN
             + " has been deleted.");
   }
 }
예제 #2
0
 public SQLWord(WordRank plugin, Word word) {
   this.plugin = plugin;
   this.word = word;
   this.sqltype = plugin.sqtype;
   if (sqltype.equals(SQLType.SQLite)) sqlite = plugin.sqlite;
   if (sqltype.equals(SQLType.MySQL)) mysql = plugin.mysql;
 }
예제 #3
0
 public String addToDB() {
   if (wordExists()) {
     return String.valueOf(
         ChatColor.RED
             + "The word "
             + ChatColor.GOLD
             + word.getName()
             + ChatColor.RED
             + " already exists!");
   } else {
     try {
       Connection con = null;
       if (sqltype.equals(SQLType.SQLite)) con = sqlite.getConnection();
       if (sqltype.equals(SQLType.MySQL)) con = mysql.getConnection();
       PreparedStatement p = con.prepareStatement(Query.INSERT_INTO.value());
       p.setString(1, word.getName());
       p.setString(2, word.getGroup());
       p.addBatch();
       con.setAutoCommit(false);
       p.executeBatch();
       con.setAutoCommit(true);
       return String.valueOf(
           ChatColor.GREEN
               + "Word "
               + ChatColor.GOLD
               + word.getName()
               + ChatColor.GREEN
               + " has been successfully added!");
     } catch (SQLException e) {
       plugin.sendErr(
           "Error while adding the word '"
               + word.getName()
               + "' to the database. Error message: "
               + e.getMessage()
               + " ERROR CODE: "
               + e.getErrorCode());
       e.printStackTrace();
       return String.valueOf(
           ChatColor.RED
               + "Error adding the word '"
               + ChatColor.GOLD
               + word.getName()
               + ChatColor.RED
               + "' Please check the console for more info.");
     } catch (Exception e) {
       plugin.sendErr(
           "Unknown error while adding the word "
               + word.getName()
               + " to the database. Stacktrace:");
       e.printStackTrace();
       return String.valueOf(
           ChatColor.RED
               + "Error adding the word '"
               + ChatColor.GOLD
               + word.getName()
               + ChatColor.RED
               + "' Please check the console for more info.");
     }
   }
 }
예제 #4
0
  public String getWordGroup() {
    ResultSet rs = null;

    if (sqltype.equals(SQLType.SQLite))
      rs = sqlite.query(Query.SELECT_GROUPNAME.value() + " name='" + word.getName() + "'");
    if (sqltype.equals(SQLType.MySQL))
      rs = mysql.query(Query.SELECT_GROUPNAME.value() + "name='" + word.getName() + "'");
    try {
      String s = null;
      while (rs.next()) {
        s = rs.getString(1);
      }
      return s;
    } catch (SQLException e) {
      plugin.sendErr(
          "SQLException while getting the word "
              + word.getName()
              + "'s group from the database. Error message: "
              + e.getMessage()
              + " ERROR CODE: "
              + e.getErrorCode());
      e.printStackTrace();
      return null;
    }
  }
예제 #5
0
  @Override
  public IType getType(String fullyQualifiedName) {
    int lastDot = fullyQualifiedName.lastIndexOf('.');
    if (lastDot == -1) {
      return null;
    }
    // TODO - AHK - What do we do if there's a table named "Transaction"?
    // TODO - AHK - Is it really our job to do any caching at all?
    String namespace = fullyQualifiedName.substring(0, lastDot);
    String relativeName = fullyQualifiedName.substring(lastDot + 1);
    DatabaseImpl databaseImpl = _typeDataByNamespace.get().get(namespace);
    if (databaseImpl == null) {
      SQLFileInfo data = _sqlFilesByName.get().get(fullyQualifiedName);
      if (data != null) {
        SQLType sqlType = new SQLType(data, this);
        addTypeForFile(data.getSqlFile(), sqlType);
        return sqlType.getTypeReference();
      } else {
        return null;
      }
    }

    IType rVal = null;
    if (TransactionType.TYPE_NAME.equals(relativeName)) {
      // TODO - AHK - Turn that into a type reference
      rVal = new TransactionType(databaseImpl, this).getTypeReference();
    } else if (DatabaseAccessType.TYPE_NAME.equals(relativeName)) {
      rVal = new DatabaseAccessType(databaseImpl, this).getTypeReference();
    } else {
      IDBTable dbTable = databaseImpl.getTable(relativeName);
      if (dbTable != null) {
        rVal = new DBType(this, dbTable).getTypeReference();
      }
    }

    if (rVal != null) {
      addTypeForFile(databaseImpl.getDdlFile(), rVal);
    }
    return rVal;
  }
예제 #6
0
  public ArrayList<String> getWords() {
    ResultSet rs = null;
    ArrayList<String> w = new ArrayList<String>();

    if (sqltype.equals(SQLType.SQLite)) rs = sqlite.query(Query.SELECT_NAME.value());
    if (sqltype.equals(SQLType.MySQL)) rs = mysql.query(Query.SELECT_NAME.value());
    try {
      while (rs.next()) {
        w.add(rs.getString(1));
      }
      return w;
    } catch (SQLException e) {
      if (e.getMessage().contains("Illegal operation on empty result")) return null;
      plugin.send(
          "SQLException while getting words from the database. Error message: "
              + e.getMessage()
              + " ERROR CODE: "
              + e.getErrorCode());
      e.printStackTrace();
    }
    return null;
  }
예제 #7
0
 /**
  * bindValue
  *
  * @param ps a {@link java.sql.PreparedStatement} object.
  * @param parameterIndex a int.
  * @param value a T object.
  * @throws java.sql.SQLException if any.
  */
 public final void bindValue(PreparedStatement ps, int parameterIndex, T value)
     throws SQLException {
   m_sqlType.bindParam(ps, parameterIndex, value);
 }
예제 #8
0
 /**
  * getValueAsString
  *
  * @param value a T object.
  * @return a {@link java.lang.String} object.
  */
 public final String getValueAsString(T value) {
   return m_sqlType.getValueAsString(value);
 }
예제 #9
0
 /**
  * formatValue
  *
  * @param value a T object.
  * @return a {@link java.lang.String} object.
  */
 public String formatValue(T value) {
   return m_sqlType.formatValue(value);
 }
예제 #10
0
파일: Database.java 프로젝트: AKSW/SINA
 /** Formats an object appropriately (provided that its class is in java2SQL) */
 public String format(Object o) {
   SQLType t = getSQLType(o.getClass());
   if (t == null) t = getSQLType(String.class);
   return (t.format(o.toString()));
 }
예제 #11
0
파일: Database.java 프로젝트: AKSW/SINA
 /** Returns an SQLType for the given Type as defined in java.sql.Types with a scale */
 public SQLType getSQLType(int t, int scale) {
   SQLType s = getSQLType(t);
   s.scale = scale;
   return (s);
 }