Search in sources :

Example 1 with DatabaseException

use of net.anweisen.utilities.database.exceptions.DatabaseException in project Utility by anweisen.

the class SQLCountEntries method execute.

@Nonnull
@Override
public Long execute() throws DatabaseException {
    try {
        PreparedStatement statement = database.prepare("SELECT COUNT(*) FROM `" + table + "`");
        ResultSet result = statement.executeQuery();
        if (!result.next()) {
            result.close();
            return 0L;
        }
        long count = result.getLong(1);
        result.close();
        return count;
    } catch (Exception ex) {
        throw new DatabaseException(ex);
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) Nonnull(javax.annotation.Nonnull)

Example 2 with DatabaseException

use of net.anweisen.utilities.database.exceptions.DatabaseException in project Utility by anweisen.

the class SQLDeletion method execute.

@Override
public Void execute() throws DatabaseException {
    try {
        PreparedStatement statement = prepare();
        statement.execute();
        return null;
    } catch (Exception ex) {
        throw new DatabaseException(ex);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) SQLException(java.sql.SQLException) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException)

Example 3 with DatabaseException

use of net.anweisen.utilities.database.exceptions.DatabaseException in project Utility by anweisen.

the class SQLInsertion method execute.

@Override
public Void execute() throws DatabaseException {
    try {
        PreparedStatement statement = prepare();
        statement.execute();
        return null;
    } catch (Exception ex) {
        throw new DatabaseException(ex);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) SQLException(java.sql.SQLException) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException)

Example 4 with DatabaseException

use of net.anweisen.utilities.database.exceptions.DatabaseException in project Utility by anweisen.

the class SQLQuery method execute.

@Nonnull
@Override
public ExecutedQuery execute() throws DatabaseException {
    try {
        PreparedStatement statement = prepare();
        ResultSet result = statement.executeQuery();
        return createExecutedQuery(result);
    } catch (Exception ex) {
        throw new DatabaseException(ex);
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) SQLException(java.sql.SQLException) Nonnull(javax.annotation.Nonnull)

Example 5 with DatabaseException

use of net.anweisen.utilities.database.exceptions.DatabaseException in project Utility by anweisen.

the class MongoDBDatabase method createTable.

@Override
public void createTable(@Nonnull String name, @Nonnull SQLColumn... columns) throws DatabaseException {
    checkConnection();
    boolean collectionExists = listTables().execute().contains(name);
    if (collectionExists)
        return;
    try {
        database.createCollection(name);
    } catch (Exception ex) {
        throw new DatabaseException(ex);
    }
}
Also used : DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException) DatabaseException(net.anweisen.utilities.database.exceptions.DatabaseException)

Aggregations

DatabaseException (net.anweisen.utilities.database.exceptions.DatabaseException)12 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)5 Nonnull (javax.annotation.Nonnull)5 ResultSet (java.sql.ResultSet)4 Document (org.bson.Document)3 Collation (com.mongodb.client.model.Collation)2 ArrayList (java.util.ArrayList)2 MongoDBWhere (net.anweisen.utilities.database.internal.mongodb.where.MongoDBWhere)2 BsonDocument (org.bson.BsonDocument)2 Bson (org.bson.conversions.Bson)2 BasicDBObject (com.mongodb.BasicDBObject)1 DeleteOptions (com.mongodb.client.model.DeleteOptions)1 UpdateOptions (com.mongodb.client.model.UpdateOptions)1 SQLColumn (net.anweisen.utilities.database.SQLColumn)1