• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Column类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中schemacrawler.schema.Column的典型用法代码示例。如果您正苦于以下问题:Java Column类的具体用法?Java Column怎么用?Java Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Column类属于schemacrawler.schema包,在下文中一共展示了Column类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: isJoinTable

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * Uses heuristics to determine whether a table is a join table.
 * <p>
 * A table is identified as a join table if every column is part of a foreign key or part of the primary key. Furthermore the primary may only consist of
 * a single column or every column has to be part of a foreign key.
 *
 * @param table The table to check
 * @return {@code true} if the table is probably a join table, false otherwise
 */
public static boolean isJoinTable(final Table table) {
    if (table.getPrimaryKey() == null) {
        return false;
    }
    final boolean hasMultipartFK = (table.getPrimaryKey().getColumns().size() > 1);
    for (final Column column : table.getColumns()) {
        if (hasMultipartFK) {
            // has to be both
            if (!(column.isPartOfForeignKey() && column.isPartOfPrimaryKey())) {
                return false;
            }
        } else {
            // If there is a single column that is not part of a foreign key and not the primary key, it needs a separate class
            if (!column.isPartOfForeignKey() && !column.isPartOfPrimaryKey()) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:30,代码来源:TableExtractor.java


示例2: extractColumnModel

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * Fills a {@link ColumnModel} with information from a {@link Column}.
 * @param column The column
 * @return The filled model
 */
public ColumnModel extractColumnModel(Column column) {
    LOG.debug("Extracting model for column {}", column.getName());
    ColumnModel model = new ColumnModel();
    model.setName(this.nameProvider.getMethodNameForColumn(column));
    model.setDbName(ModelUtil.removeQuotes(column.getName()));
    model.setDbTableName(column.getParent().getName());
    model.setDbFullTableName(column.getParent().getFullName());

    model.setSqlType(column.getColumnDataType().getName());
    model.setSqlTypeInt(column.getColumnDataType().getJavaSqlType().getJavaSqlType());
    String javaDataTypeName = dataTypeProvider.getCanonicalDataTypeName(column);
    model.setJavaTypeName(javaDataTypeName);
    model.setNotNull(!column.isNullable());
    model.setPartOfPrimaryKey(column.isPartOfPrimaryKey());
    model.setPartOfForeignKey(column.isPartOfForeignKey());
    model.setExplicitAttribute(explicitAttributeDecider.isExplicitAttribute(column));
    model.setUnique(column.isPartOfUniqueIndex() || column.isPartOfPrimaryKey());

    model.setConvenienceSetters(convenienceSetterProvider.getConvenienceSetters(column, javaDataTypeName));

    return model;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:28,代码来源:ColumnExtractor.java


示例3: getCanonicalDataTypeName

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public String getCanonicalDataTypeName(final Column column) {
    if (typeMappings.getTableMappings() != null) {
        final HashMap<String, String> tableMap = typeMappings.getTableMappings().get(column.getParent().getFullName());
        if (tableMap != null) {
            final String className = tableMap.get(column.getName());
            if (className != null) {
                return className;
            }
        }
    }
    final HashMap<String, String> defaultMappings = typeMappings.getDefaultTypeMappings();
    if (defaultMappings != null) {
        List<String> variants = DataTypePrecisionHelper.getDataTypeWithAllPrecisionVariants(column);
        for (final String variant : variants) {
            final String defaultType = defaultMappings.get(variant);
            if (defaultType != null) {
                return defaultType;
            }
        }
    }
    return fallbackProvider.getCanonicalDataTypeName(column);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:24,代码来源:JsonFileDataTypeProvider.java


示例4: testGetDataTypeBySqlName

import schemacrawler.schema.Column; //导入依赖的package包/类
@Test
public void testGetDataTypeBySqlName() throws Exception {
    TypeMappings typeMappings = new TypeMappings();
    typeMappings.setDefaultTypeMappings(Arrays.asList(
            new DefaultTypeMapping("DECIMAL", "java.lang.Long"),
            new DefaultTypeMapping("DECIMAL(1)", "java.lang.Boolean")
    ));

    ColumnDataType cdt = Mockito.mock(ColumnDataType.class);
    Mockito.when(cdt.getName()).thenReturn("DECIMAL");
    Column column1 = Mockito.mock(Column.class);
    Mockito.when(column1.getColumnDataType()).thenReturn(cdt);
    Mockito.when(column1.getSize()).thenReturn(1);
    Mockito.when(column1.getDecimalDigits()).thenReturn(0);

    Column column2 = Mockito.mock(Column.class);
    Mockito.when(column2.getColumnDataType()).thenReturn(cdt);
    Mockito.when(column2.getSize()).thenReturn(10);
    Mockito.when(column2.getSize()).thenReturn(0);

    XmlFileDataTypeProvider dataTypeProvider = new XmlFileDataTypeProvider(typeMappings, new DefaultDataTypeProvider());

    Assert.assertEquals("java.lang.Boolean", dataTypeProvider.getDataTypeBySqlType(column1));
    Assert.assertEquals("java.lang.Long", dataTypeProvider.getDataTypeBySqlType(column2));
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:26,代码来源:XmlFileDataTypeProviderTest.java


示例5: toNodeSpec

import schemacrawler.schema.Column; //导入依赖的package包/类
protected NodeSpec toNodeSpec(EntitySpec entitySpec, Column column) {
    NodeSpec nodeSpec = new NodeSpec();
    nodeSpec.setName( getNodeName( column ));
    if (nodeSpec.getName().equals("id")) {
        nodeSpec.setPrimaryKey(true);
    }
    nodeSpec.setColumnName( column.getName());
    nodeSpec.setJdbcType( getNodeType( column ));
    nodeSpec.setJavaType( getJavaType( nodeSpec.getJdbcType() ));
    nodeSpec.setNullable( column.isNullable() ? Nullable.NULL : Nullable.NOT_NULL);
    if (nodeSpec.getJavaType() == JavaType.STRING) {
        nodeSpec.setLength( column.getSize() );
    }
    else if (nodeSpec.getJavaType() == JavaType.BIGDECIMAL) {
        nodeSpec.setPrecision( column.getSize() );
        nodeSpec.setScale( column.getDecimalDigits());
    }
    nodeSpec.setEntity(entitySpec);
    nodeSpecs.put(column, nodeSpec);
    return nodeSpec;
}
 
开发者ID:scottysinclair,项目名称:barleydb,代码行数:22,代码来源:FromDatabaseSchemaToSpecification.java


示例6: lint

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * The lint that does the job
 * @param table table
 * @param connection connection
 */
@Override
protected void lint(final Table table, final Connection connection) throws SchemaCrawlerException{

    try (Statement stmt = connection.createStatement()){

        List<Column> columns = getColumns(table);
        int columnDataType;
        int count;
        int distinctCount;

        for (Column column : columns) {
            columnDataType = column.getColumnDataType().getJavaSqlType().getJavaSqlType();
            if(columnDataType == Types.BINARY || columnDataType == Types.BLOB) {
                inspectBlobData(stmt, table, column);
            }
        }
    }catch (SQLException ex) {
        LOGGER.severe(ex.getMessage());
        throw new SchemaCrawlerException(ex.getMessage(), ex);
    }

}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:28,代码来源:LinterCompressBlob.java


示例7: findMismatchedForeignKeys

import schemacrawler.schema.Column; //导入依赖的package包/类
private void findMismatchedForeignKeys(final Table table){
    
    if (table != null && !(table instanceof View))
    {
        for (final ForeignKey foreignKey: table.getImportedForeignKeys())
        {
            for (final ForeignKeyColumnReference columnReference: foreignKey)
            {
                final Column pkColumn = columnReference.getPrimaryKeyColumn();
                final Column fkColumn = columnReference.getForeignKeyColumn();
                if (!pkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName().equals(fkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName())
                        || pkColumn.getSize() != fkColumn.getSize())
                {
                    addTableLint(table, "Foreign key data type ("+fkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName()+") "
                            + "does not match Primary key ("+pkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName()+").", foreignKey);
                    break;
                }
            }
        }
    }
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:22,代码来源:LinterForeignKeyMismatchLazy.java


示例8: lint

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * The lint that does the job
 *
 * @param table      table
 * @param connection connection
 */
@Override
protected void lint(final Table table, final Connection connection) throws SchemaCrawlerException {
    try {
        if ("PostgreSQL".equalsIgnoreCase(connection.getMetaData().getDatabaseProductName()) && "9.4".compareTo(connection.getMetaData().getDatabaseProductVersion()) <= 0) {
            List<Column> columns = getColumns(table);
            for (Column column : columns) {
                LOGGER.log(Level.INFO, "Checking {0}...", column.getFullName() + " - " + column.getColumnDataType().getDatabaseSpecificTypeName());
                if (Objects.equals("bytea", column.getColumnDataType().getDatabaseSpecificTypeName())) {
                    addLint(table, getDescription(), column.getFullName());
                }
            }
        }
    } catch (SQLException ex) {
        LOGGER.severe(ex.getMessage());
        throw new SchemaCrawlerException(ex.getMessage(), ex);
    }
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:24,代码来源:LinterByteaTypeColumn.java


示例9: getSelectCount

import schemacrawler.schema.Column; //导入依赖的package包/类
private static int getSelectCount(Statement stmt, Table table, Column column) throws SchemaCrawlerException{
    String tableName = table.getName().replaceAll("\"", "");
    String columnName = column.getName().replaceAll("\"", "");

    String sql = "select count (\"" + columnName + "\") as countRow from \"" + tableName +"\"";
    LOGGER.log(Level.CONFIG, "SQL : {0}", sql);

    int count = 0;
    try(ResultSet rs = stmt.executeQuery(sql)){
        if(rs.next()){
            count = rs.getInt("countRow");
        }
    }catch (SQLException ex) {
        LOGGER.severe(ex.getMessage());
        throw new SchemaCrawlerException(ex.getMessage(), ex);
    }
    return count;
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:19,代码来源:LinterBooleanContent.java


示例10: getSelectDistinctCount

import schemacrawler.schema.Column; //导入依赖的package包/类
private static int getSelectDistinctCount(Statement stmt, Table table, Column column) throws SchemaCrawlerException{
    String tableName = table.getName().replaceAll("\"", "");
    String columnName = column.getName().replaceAll("\"", "");
    
    String sql = "select count (distinct \"" + columnName + "\") as countDistinctRow from \"" + tableName +"\"";
    LOGGER.log(Level.CONFIG, "SQL : {0}", sql);
    
    int count = 0;
    try(ResultSet rs = stmt.executeQuery(sql)){
        if(rs.next()){
            count = rs.getInt("countDistinctRow");
        }
    }catch (SQLException ex) {
        LOGGER.severe(ex.getMessage());
        throw new SchemaCrawlerException(ex.getMessage(), ex);
    }
    return count;
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:19,代码来源:LinterBooleanContent.java


示例11: isExplicitAttribute

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public boolean isExplicitAttribute(Column column) {
    String tableName = column.getParent().getName();
    String columnName = column.getName();

    return explicitDataByTableRegex.keySet().stream()
            .filter(tableName::matches)
            .flatMap(tableNameRegex -> {
                if (explicitDataByTableRegex.get(tableNameRegex).attributes == null) {
                    return null;
                }
                return Arrays.stream(explicitDataByTableRegex.get(tableNameRegex).attributes);
            })
            .anyMatch(columnName::matches);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:16,代码来源:JsonFileExplicitAttributeDecider.java


示例12: matchesColumns

import schemacrawler.schema.Column; //导入依赖的package包/类
private static boolean matchesColumns(final String[] regexes, final ForeignKey foreignKey) {
    /*return foreignKey.getColumnReferences().stream()
            .map(ForeignKeyColumnReference::getForeignKeyColumn)
            .map(Column::getName)
            .anyMatch(name -> name.matches(regex));*/
    List<String> columnNames = foreignKey.getColumnReferences().stream()
            .map(ForeignKeyColumnReference::getForeignKeyColumn)
            .map(Column::getName)
            .collect(Collectors.toList());
    if (columnNames.size() != regexes.length) {
        return false;
    }
    final Stack<Integer> usedFields = new Stack<>();
    for (final String colName : columnNames) {
        boolean foundMatch = false;
        for (int i = 0; i < regexes.length; i++) {
            if (!usedFields.contains(i)) {
                foundMatch = colName.matches(regexes[i]);
                if (foundMatch) {
                    usedFields.push(i);
                    break;
                }
            }
        }
        if (!foundMatch) {
            return false;
        }
    }
    return true;

}
 
开发者ID:btc-ag,项目名称:redg,代码行数:32,代码来源:JsonFileExplicitAttributeDecider.java


示例13: getMethodNameForColumn

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public String getMethodNameForColumn(final Column column) {
    if (mappings.containsKey(column.getParent().getName())) {
        if (mappings.get(column.getParent().getName()).getColumns() != null &&
                mappings.get(column.getParent().getName()).getColumns().containsKey(column.getName())) {
            return mappings.get(column.getParent().getName()).getColumns().get(column.getName());
        }
    }
    return null;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:11,代码来源:JsonFileNameProvider.java


示例14: getMethodNameForReference

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * Generates an appropriate method name for a foreign key
 * @param foreignKey The database foreign key
 * @return The generated name
 */
@Override
public String getMethodNameForReference(final ForeignKey foreignKey) {
    final Column c = foreignKey.getColumnReferences().get(0).getForeignKeyColumn();
    // check if only one-column fk
    if (foreignKey.getColumnReferences().size() == 1) {
        return getMethodNameForColumn(c) + getClassNameForTable(c.getReferencedColumn().getParent());
    }

    final StringBuilder nameBuilder = new StringBuilder();
    final List<String> words = new ArrayList<>(Arrays.asList(foreignKey.getName()
            .toLowerCase()
            .replaceAll("(^[0-9]+|[^a-z0-9_-])", "") // Delete every not-alphanumeric or _/- character and numbers at beginning
            .split("_")));
    words.removeAll(Arrays.asList("fk", "", null)); // removes FK_ prefix and empty entries
    final List<String> tableWords = new ArrayList<>(Arrays.asList(c.getParent().getName()
            .toLowerCase()
            .replaceAll("(^[0-9]+|[^a-z0-9_-])", "") // Delete every not-alphanumeric or _/- character and numbers at beginning
            .split("_")));
    words.removeAll(tableWords);
    nameBuilder.append(words.get(0));
    for (int i = 1; i < words.size(); i++) {
        String word = words.get(i);

        nameBuilder.append(word.substring(0, 1).toUpperCase());
        nameBuilder.append(word.substring(1));
    }
    return nameBuilder.toString();
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:34,代码来源:DefaultNameProvider.java


示例15: getMethodNameForColumn

import schemacrawler.schema.Column; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public String getMethodNameForColumn(final Column column) {
    this.wasUsedBefore = true;
    for (final NameProvider provider : providers) {
        final String name = provider.getMethodNameForColumn(column);
        if (Objects.nonNull(name)) {
            return name;
        }
    }
    return this.fallbackProvider.getMethodNameForColumn(column);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:15,代码来源:MultiProviderNameProvider.java


示例16: getMethodNameForForeignKeyColumn

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public String getMethodNameForForeignKeyColumn(ForeignKey foreignKey, Column primaryKeyColumn, Column foreignKeyColumn) {
    this.wasUsedBefore = true;
    for (final NameProvider provider : providers) {
        final String name = provider.getMethodNameForForeignKeyColumn(foreignKey, primaryKeyColumn, foreignKeyColumn);
        if (Objects.nonNull(name)) {
            return name;
        }
    }
    return this.fallbackProvider.getMethodNameForForeignKeyColumn(foreignKey, primaryKeyColumn, foreignKeyColumn);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:12,代码来源:MultiProviderNameProvider.java


示例17: getCanonicalDataTypeName

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public String getCanonicalDataTypeName(final Column column) {
    String dataTypeByName = getDataTypeByName(column.getParent().getName(), column.getName());
    String dataTypeByType = getDataTypeBySqlType(column);
    return dataTypeByName != null ? dataTypeByName :
            dataTypeByType != null ? dataTypeByType : fallbackDataTypeProvider.getCanonicalDataTypeName(column);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:8,代码来源:XmlFileDataTypeProvider.java


示例18: getDataTypeBySqlType

import schemacrawler.schema.Column; //导入依赖的package包/类
String getDataTypeBySqlType(final Column column) {
    List<String> variants = DataTypePrecisionHelper.getDataTypeWithAllPrecisionVariants(column);
    return variants.stream()
            .map(variant ->
                    typeMappings.getDefaultTypeMappings().stream()
                            .filter(dtm -> dtm.getSqlType().replaceAll("\\s", "").toUpperCase().equals(variant.toUpperCase()))
                            .findFirst().orElse(null))
            .filter(Objects::nonNull)
            .map(DefaultTypeMapping::getJavaType)
            .findFirst().orElse(null);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:12,代码来源:XmlFileDataTypeProvider.java


示例19: getConvenienceSetters

import schemacrawler.schema.Column; //导入依赖的package包/类
@Override
public List<ConvenienceSetterModel> getConvenienceSetters(Column column, String javaDataTypeName) {
    return this.convenienceSetterConfig.getConvenienceSetterConfigs().stream()
            .filter(dataTypeConvenienceSetterConfig -> dataTypeConvenienceSetterConfig.getJavaDataTypeName().equals(javaDataTypeName))
            .flatMap(dataTypeConvenienceSetterConfig -> dataTypeConvenienceSetterConfig.getConvenienceSetters().stream())
            .collect(Collectors.toList());
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:8,代码来源:XmlFileConvenienceSetterProvider.java


示例20: getConvenienceSetters

import schemacrawler.schema.Column; //导入依赖的package包/类
@Test
public void getConvenienceSetters() throws Exception {
    InputStream stream = this.getClass().getResourceAsStream("XmlFileConvencienceSetterProviderTest.xml");
    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");

    XmlFileConvenienceSetterProvider provider = new XmlFileConvenienceSetterProvider(reader);

    Assert.assertEquals(1, provider.getConvenienceSetters(Mockito.mock(Column.class), "java.util.Date").size());
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:10,代码来源:XmlFileConvenienceSetterProviderTest.java



注:本文中的schemacrawler.schema.Column类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DtlsConnectorConfig类代码示例发布时间:2022-05-22
下一篇:
Java GZIPResponseStream类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap