当前位置: 首页>>代码示例>>Java>>正文


Java Constraint类代码示例

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


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

示例1: cloneConstraints

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * @param src_db
 * @param dest_db
 */
public static void cloneConstraints(Database src_db, Database dest_db) {
    Catalog dest_catalog = dest_db.getCatalog();
    for (Table src_tbl : src_db.getTables()) {
        Table dest_tbl = dest_db.getTables().get(src_tbl.getName());
        if (dest_tbl != null) {
            for (Constraint src_cons : src_tbl.getConstraints()) {
                // Only clone FKEY constraint if the other table is in the catalog
                ConstraintType cons_type = ConstraintType.get(src_cons.getType());
                if (cons_type != ConstraintType.FOREIGN_KEY || (cons_type == ConstraintType.FOREIGN_KEY && dest_db.getTables().get(src_cons.getForeignkeytable().getName()) != null)) {
                    Constraint dest_cons = clone(src_cons, dest_catalog);
                    assert (dest_cons != null);
                }
            } // FOR
        }
    } // FOR
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:CatalogCloner.java

示例2: getForeignKeyParent

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * @param from_column
 * @return
 */
public static Column getForeignKeyParent(Column from_column) {
    assert (from_column != null);
    final CatalogUtil.Cache cache = CatalogUtil.getCatalogCache(from_column);
    Column to_column = cache.FOREIGNKEY_PARENT.get(from_column);

    if (to_column == null) {
        for (Constraint catalog_const : CatalogUtil.getConstraints(from_column.getConstraints())) {
            if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) {
                assert (!catalog_const.getForeignkeycols().isEmpty());
                for (ColumnRef catalog_col_ref : catalog_const.getForeignkeycols()) {
                    if (catalog_col_ref.getName().equals(from_column.getName())) {
                        assert (to_column == null);
                        to_column = catalog_col_ref.getColumn();
                        break;
                    }
                } // FOR
                if (to_column != null)
                    break;
            }
        } // FOR
        cache.FOREIGNKEY_PARENT.put(from_column, to_column);
    }
    return (to_column);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:CatalogUtil.java

示例3: getForeignKeyParent

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * 
 * @param from_column
 * @return
 */
public static Column getForeignKeyParent(Column from_column) {
    assert(from_column != null);
    Column to_column = null;
    
    for (Constraint catalog_const : CatalogUtil.getConstraints(from_column.getConstraints())) {
        if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) {
            assert(!catalog_const.getForeignkeycols().isEmpty());
            for (ColumnRef catalog_col_ref : catalog_const.getForeignkeycols()) {
                if (catalog_col_ref.getName().equals(from_column.getName())) {
                    assert(to_column == null);
                    to_column = catalog_col_ref.getColumn();
                    break;
                }
            } // FOR
            if (to_column != null) break;
        }
    } // FOR
    return (to_column);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:25,代码来源:CatalogUtil.java

示例4: getPrimaryKeyIndex

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * For a given Table catalog object, return the PrimaryKey Index catalog object
 * @param catalogTable
 * @return The index representing the primary key.
 * @throws Exception if the table does not define a primary key
 */
public static Index getPrimaryKeyIndex(Table catalogTable) throws Exception {

    // We first need to find the pkey constraint
    Constraint catalog_constraint = null;
    for (Constraint c : catalogTable.getConstraints()) {
        if (c.getType() == ConstraintType.PRIMARY_KEY.getValue()) {
            catalog_constraint = c;
            break;
        }
    }
    if (catalog_constraint == null) {
        throw new Exception("ERROR: Table '" + catalogTable.getTypeName() + "' does not have a PRIMARY KEY constraint");
    }

    // And then grab the index that it is using
    return (catalog_constraint.getIndex());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:24,代码来源:CatalogUtil.java

示例5: testCreateSchemaCatalog

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * testCreateSchemaCatalog
 */
public void testCreateSchemaCatalog() throws Exception {
    Catalog s_catalog = new TPCEProjectBuilder().getSchemaCatalog(false);
    assertNotNull(s_catalog);
    Database s_catalog_db = CatalogUtil.getDatabase(s_catalog);
    assertNotNull(catalog_db);

    // ADDRESS should point to ZIP_CODE
    Table address = s_catalog_db.getTables().get(TPCEConstants.TABLENAME_ADDRESS);
    assertNotNull(address);
    Table zipcode = s_catalog_db.getTables().get(TPCEConstants.TABLENAME_ZIP_CODE);
    assertNotNull(zipcode);

    for (Constraint catalog_const : address.getConstraints()) {
        if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) {
            assertEquals(zipcode, catalog_const.getForeignkeytable());
            assertEquals(1, catalog_const.getForeignkeycols().size());
            break;
        }
    } // FOR
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:24,代码来源:TestTPCEProjectBuilder.java

示例6: getPrimaryKeys

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
VoltTable getPrimaryKeys()
{
    VoltTable results = new VoltTable(PRIMARYKEYS_SCHEMA);
    for (Table table : m_database.getTables())
    {
        for (Constraint c : table.getConstraints())
        {
            if (c.getType() == ConstraintType.PRIMARY_KEY.getValue())
            {
                for (ColumnRef column : c.getIndex().getColumns())
                {
                    results.addRow(null,
                                   null, // table schema
                                   table.getTypeName(), // table name
                                   column.getTypeName(), // column name
                                   column.getRelativeIndex(), // key_seq
                                   c.getTypeName() // PK_NAME
                                  );
                }
            }
        }
    }
    return results;
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:25,代码来源:JdbcDatabaseMetaDataGenerator.java

示例7: generateCrudPKeyWhereClause

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Helper to generate a WHERE pkey_col1 = ?, pkey_col2 = ? ...; clause.
 * @param partitioncolumn partitioning column for the table
 * @param pkey constraint from the catalog
 * @param paramoffset 0-based counter of parameters in the full sql statement so far
 * @param sb string buffer accumulating the sql statement
 * @return offset in the index of the partition column
 */
private int generateCrudPKeyWhereClause(Column partitioncolumn,
        Constraint pkey, StringBuilder sb)
{
    // Sort the catalog index columns by index column order.
    ArrayList<ColumnRef> indexColumns = new ArrayList<ColumnRef>(pkey.getIndex().getColumns().size());
    for (ColumnRef c : pkey.getIndex().getColumns()) {
        indexColumns.add(c);
    }
    Collections.sort(indexColumns, new ColumnRefComparator());

    boolean first = true;
    int partitionOffset = -1;

    sb.append(" WHERE ");
    for (ColumnRef pkc : indexColumns) {
        if (!first) sb.append(" AND ");
        first = false;
        sb.append("(" + pkc.getColumn().getName() + " = ?" + ")");
        if (pkc.getColumn() == partitioncolumn) {
            partitionOffset = pkc.getIndex();
        }
    }
    return partitionOffset;

}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:34,代码来源:DefaultProcedureManager.java

示例8: getConstraints

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Return the real Constraint objects for the ConstraintRefs
 * @param map
 * @return
 */
public static Collection<Constraint> getConstraints(Iterable<ConstraintRef> map) {
    List<Constraint> ret = new ArrayList<Constraint>();
    if (map != null) {
        for (ConstraintRef ref : map) {
            Constraint catalog_item = ref.getConstraint();
            assert(catalog_item != null);
            ret.add(catalog_item);
        }
    }
    return (ret);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:17,代码来源:CatalogUtil.java

示例9: generateCrudDelete

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Create a statement like:
 *  "delete from <table> where {<pkey-column =?>...}"
 */
private String generateCrudDelete(Table table, Column partitioncolumn, Constraint pkey) {
    StringBuilder sb = new StringBuilder();
    sb.append("DELETE FROM " + table.getTypeName());

    generateCrudPKeyWhereClause(partitioncolumn, pkey, sb);
    sb.append(';');

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:14,代码来源:DefaultProcedureManager.java

示例10: generateCrudUpdate

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Create a statement like:
 * "update <table> set {<each-column = ?>...} where {<pkey-column = ?>...}
 */
private String generateCrudUpdate(Table table, Column partitioncolumn, Constraint pkey) {
    StringBuilder sb = new StringBuilder();
    sb.append("UPDATE " + table.getTypeName() + " SET ");

    generateCrudExpressionColumns(table, sb);
    generateCrudPKeyWhereClause(partitioncolumn, pkey, sb);
    sb.append(';');

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:15,代码来源:DefaultProcedureManager.java

示例11: generateCrudReplicatedUpdate

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Create a statement like:
 *  "update <table> set {<each-column = ?>...} where {<pkey-column = ?>...}
 *  for a replicated table.
 */
private String generateCrudReplicatedUpdate(Table table, Constraint pkey)
{
    StringBuilder sb = new StringBuilder();
    sb.append("UPDATE " + table.getTypeName() + " SET ");

    generateCrudExpressionColumns(table, sb);
    generateCrudPKeyWhereClause(null, pkey, sb);
    sb.append(';');

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:17,代码来源:DefaultProcedureManager.java

示例12: generateCrudReplicatedDelete

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Create a statement like:
 *  "delete from <table> where {<pkey-column =?>...}"
 * for a replicated table.
 */
private String generateCrudReplicatedDelete(Table table, Constraint pkey)
{
    StringBuilder sb = new StringBuilder();
    sb.append("DELETE FROM " + table.getTypeName());

    generateCrudPKeyWhereClause(null, pkey, sb);
    sb.append(';');

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:16,代码来源:DefaultProcedureManager.java

示例13: generateCrudReplicatedUpsert

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
private String generateCrudReplicatedUpsert(Table table, Constraint pkey)
{
    StringBuilder sb = new StringBuilder();
    sb.append("UPSERT INTO " + table.getTypeName() + " VALUES ");

    generateCrudColumnList(table, sb);
    sb.append(";");

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:11,代码来源:DefaultProcedureManager.java

示例14: generateCrudSelect

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
/**
 * Create a statement like:
 *  "select * from <table> where pkey_col1 = ?, pkey_col2 = ? ... ;"
 */
private String generateCrudSelect(Table table, Column partitioncolumn, Constraint pkey)
{
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT * FROM " + table.getTypeName());

    generateCrudPKeyWhereClause(partitioncolumn, pkey, sb);
    sb.append(';');

    return sb.toString();
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:15,代码来源:DefaultProcedureManager.java

示例15: setForeignKeyConstraints

import org.voltdb.catalog.Constraint; //导入依赖的package包/类
public static void setForeignKeyConstraints(Table catalog_tbl, Map<String, String> fkeys) throws Exception {
    final Database catalog_db = (Database) catalog_tbl.getParent();

    Map<Table, Constraint> table_const_map = new HashMap<Table, Constraint>();
    for (Entry<String, String> entry : fkeys.entrySet()) {
        String column = entry.getKey();
        String fkey[] = entry.getValue().split("\\.");
        Column catalog_col = catalog_tbl.getColumns().get(column);
        Table catalog_fkey_tbl = catalog_db.getTables().get(fkey[0]);
        Column catalog_fkey_col = catalog_fkey_tbl.getColumns().get(fkey[1]);

        if (catalog_fkey_tbl == null) {
            throw new Exception("ERROR: The foreign key table for '" + fkey[0] + "." + fkey[1] + "' is null");
        } else if (catalog_fkey_col == null) {
            throw new Exception("ERROR: The foreign key column for '" + fkey[0] + "." + fkey[1] + "' is null");
        }

        Constraint catalog_const = null;
        if (table_const_map.containsKey(catalog_fkey_tbl)) {
            catalog_const = table_const_map.get(catalog_fkey_tbl);
        } else {
            String fkey_name = "SYS_FK_" + FKEY_COUNTER++;
            catalog_const = catalog_tbl.getConstraints().get(fkey_name);
            if (catalog_const == null) {
                catalog_const = catalog_tbl.getConstraints().add(fkey_name);
                catalog_const.setType(ConstraintType.FOREIGN_KEY.getValue());
                catalog_const.setForeignkeytable(catalog_fkey_tbl);
            } else {
                LOG.info("Foreign Key '" + fkey_name + "' already exists for table '" + catalog_tbl.getName() + "'. Skipping...");
                continue;
            }
        }

        //
        // Add the parent ColumnRef to the Constraint
        // The name of the column ref is the name of the column in this
        // table, which then points
        // to the column in the foreign table
        //
        ColumnRef catalog_fkey_col_ref = catalog_const.getForeignkeycols().add(catalog_col.getName());
        catalog_fkey_col_ref.setColumn(catalog_fkey_col);

        //
        // Add the ConstraintRef to the child Column
        //
        ConstraintRef catalog_const_ref = catalog_col.getConstraints().add(catalog_const.getName());
        catalog_const_ref.setConstraint(catalog_const);

        LOG.debug("Added foreign key constraint from '" + catalog_tbl.getName() + "." + column + "' to '" + fkey[0] + "." + fkey[1] + "'");
        table_const_map.put(catalog_fkey_tbl, catalog_const);
    } // FOR
    return;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:54,代码来源:ForeignKeysUtil.java


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