All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.topia.persistence.support.TopiaSqlDllSupport Maven / Gradle / Ivy

The newest version!
package org.nuiton.topia.persistence.support;

/*-
 * #%L
 * ObServe Toolkit :: ToPIA Extension
 * %%
 * Copyright (C) 2017 - 2018 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * Created by tchemit on 05/05/2018.
 *
 * @author Tony Chemit - [email protected]
 */
public interface TopiaSqlDllSupport {

    String getClassifier();

    String getUniqueConstraintName(TopiaSqlSupport tx, String tableName, String columnName);

    String getFirstTableUniqueConstraintName(TopiaSqlSupport tx, String tableName);

    Set getConstraintNames(TopiaSqlSupport tx, String tableName);

    Set getForeignKeyConstraintNames(TopiaSqlSupport tx, String tableName);

    String getForeignKeyConstraintName(TopiaSqlSupport tx, String schemaName, String tableName, String columnName, boolean mustExists);

    Set getUniqueKeyConstraintNames(TopiaSqlSupport tx, String tableName);

    Set removeFK(TopiaSqlSupport tx, String tableName);

    String removeFK(TopiaSqlSupport tx, String schemaName, String tableName, String columnName);

    Optional removeFKIfExists(TopiaSqlSupport tx, String schemaName, String tableName, String columnName);

    Set removeUK(TopiaSqlSupport tx, String tableName);


    static Set selectAllAsSet(TopiaSqlSupport tx, String sql) {
        return new LinkedHashSet<>(selectAll(tx, sql));
    }

    static List selectAll(TopiaSqlSupport tx, String sql) {
        return tx.findMultipleResult(new TopiaSqlQuery() {
            @Override
            public PreparedStatement prepareQuery(Connection connection) throws SQLException {
                return connection.prepareStatement(sql);
            }

            @Override
            public String prepareResult(ResultSet set) throws SQLException {
                return set.getString(1);
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy