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

cn.originx.infix.oracle12.OracleReflector Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package cn.originx.infix.oracle12;

import cn.originx.infix.oracle12.cv.OracleStatement;
import cn.originx.infix.oracle12.cv.OracleWord;
import io.vertx.tp.atom.cv.em.KeyType;
import io.vertx.tp.modular.jdbc.AoConnection;
import io.vertx.tp.modular.metadata.AbstractReflector;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class OracleReflector extends AbstractReflector implements OracleStatement, OracleWord {


    OracleReflector(final AoConnection connection) {
        super(connection);
    }

    @Override
    public ConcurrentMap getConstraints(final String tableName) {
        final ConcurrentMap constraints = new ConcurrentHashMap<>();
        final String sql = MessageFormat.format(OracleStatement.R_CONSTRAINTS, this.connection.getDatabase().getInstance(), tableName);
        final String[] cols = {Metadata.CONSTRAINT_NAME, Metadata.CONSTRAINT_TYPE};
        final List> results = this.connection.select(sql, cols);
        results.forEach(row -> {
            final Object type = row.get(Metadata.CONSTRAINT_TYPE);
            if (null != type) {
                final Object name = row.get(Metadata.CONSTRAINT_NAME);
                if ("U".equalsIgnoreCase(type.toString())) {
                    // Unique约束名
                    constraints.put(name.toString(), KeyType.UNIQUE);
                } else if ("P".equalsIgnoreCase(type.toString())) {
                    // 主键特殊约束名
                    constraints.put(name.toString(), KeyType.PRIMARY);
                }
            }
        });
        return constraints;
    }

    @Override
    public  List getColumns(final String tableName) {
        final String sql = MessageFormat.format(OracleStatement.R_COLUMNS, this.connection.getDatabase().getInstance(), tableName);
        return this.connection.select(sql, Metadata.COLUMN);
    }

    @Override
    public List> getColumnDetail(final String tableName) {
        return new ArrayList<>();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy