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


Java ConstraintType类代码示例

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


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

示例1: cloneConstraints

import org.voltdb.types.ConstraintType; //导入依赖的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.types.ConstraintType; //导入依赖的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: ConstraintFailureException

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 * Constructor for deserializing an exception returned from the EE.
 * @param exceptionBuffer
 */
public ConstraintFailureException(ByteBuffer exceptionBuffer) {
    super(exceptionBuffer);
    type = ConstraintType.get(exceptionBuffer.getInt());
    try {
        tableName = FastDeserializer.readString(exceptionBuffer);
    }
    catch (IOException e) {
        // implies that the EE created an invalid constraint
        // failure, which would be a corruption/defect.
        throw new ServerFaultException("Unexpected error when deserializing exception from EE", e);
    }
    if (exceptionBuffer.hasRemaining()) {
        int tableSize = exceptionBuffer.getInt();
        buffer = ByteBuffer.allocate(tableSize);
        //Copy the exception details.
        exceptionBuffer.get(buffer.array());
    } else {
        buffer = ByteBuffer.allocate(0);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:25,代码来源:ConstraintFailureException.java

示例4: getForeignKeyParent

import org.voltdb.types.ConstraintType; //导入依赖的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

示例5: getPrimaryKeyIndex

import org.voltdb.types.ConstraintType; //导入依赖的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

示例6: testCreateSchemaCatalog

import org.voltdb.types.ConstraintType; //导入依赖的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

示例7: getPrimaryKeys

import org.voltdb.types.ConstraintType; //导入依赖的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

示例8: ConstraintFailureException

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 * Constructor for deserializing an exception returned from the EE.
 * @param exceptionBuffer
 */
public ConstraintFailureException(ByteBuffer exceptionBuffer) {
    super(exceptionBuffer);
    type = ConstraintType.get(exceptionBuffer.getInt());
    try {
        tableName = FastDeserializer.readString(exceptionBuffer);
    }
    catch (IOException e) {
        // implies that the EE created an invalid constraint
        // failure, which would be a corruption/defect.
        VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
    }
    if (exceptionBuffer.hasRemaining()) {
        int tableSize = exceptionBuffer.getInt();
        buffer = ByteBuffer.allocate(tableSize);
        //Copy the exception details.
        exceptionBuffer.get(buffer.array());
    } else {
        buffer = ByteBuffer.allocate(0);
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:25,代码来源:ConstraintFailureException.java

示例9: getForeignKeyDependents

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 * Returns all the columns for this table that have a foreign key dependency
 * on another table
 * 
 * @param catalog_tbl
 * @return
 */
public static Collection<Column> getForeignKeyDependents(Table catalog_tbl) {
    Set<Column> found = new ListOrderedSet<Column>();
    for (Column catalog_col : catalog_tbl.getColumns()) {
        assert (catalog_col != null);
        if (!catalog_col.getConstraints().isEmpty()) {
            // System.out.println(catalog_col + ": " +
            // CatalogUtil.getConstraints(catalog_col.getConstraints()));
            if (!CatalogUtil.findAll(CatalogUtil.getConstraints(catalog_col.getConstraints()), "type", ConstraintType.FOREIGN_KEY.getValue()).isEmpty()) {
                found.add(catalog_col);
            }
        }
    } // FOR
    return (found);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:22,代码来源:CatalogUtil.java

示例10: setForeignKeyConstraints

import org.voltdb.types.ConstraintType; //导入依赖的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

示例11: testToSchema

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 *
 */
public void testToSchema() {
    String search_str = "";

    // Simple check to make sure things look ok...
    for (Table catalog_tbl : catalog_db.getTables()) {
        String sql = CatalogUtil.toSchema(catalog_tbl);
        assertTrue(sql.startsWith("CREATE TABLE " + catalog_tbl.getTypeName()));

        // Columns
        for (Column catalog_col : catalog_tbl.getColumns()) {
            assertTrue(sql.indexOf(catalog_col.getTypeName()) != -1);
        }

        // Constraints
        for (Constraint catalog_const : catalog_tbl.getConstraints()) {
            ConstraintType const_type = ConstraintType.get(catalog_const.getType());
            Index catalog_idx = catalog_const.getIndex();
            // 2011-07-15: Skip all foreign keys
            if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) continue;
            assertNotNull("Missing index for " + catalog_const.fullName(), catalog_idx);
            List<ColumnRef> columns = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");

            if (!columns.isEmpty()) {
                search_str = "";
                String add = "";
                for (ColumnRef catalog_colref : columns) {
                    search_str += add + catalog_colref.getColumn().getTypeName();
                    add = ", ";
                }
                assertTrue(sql.indexOf(search_str) != -1);
            }

            switch (const_type) {
                case PRIMARY_KEY:
                    assertTrue(sql.indexOf("PRIMARY KEY") != -1);
                    break;
                case FOREIGN_KEY:
                    search_str = "REFERENCES " + catalog_const.getForeignkeytable().getTypeName();
                    assertTrue(sql.indexOf(search_str) != -1);
                    break;
            }
        }
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:48,代码来源:TestCatalogUtil.java

示例12: testForeignKeys

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
public void testForeignKeys() {
    String schemaPath = "";
    try {
        final URL url = new TPCCProjectBuilder().getDDLURL(true);
        schemaPath = URLDecoder.decode(url.getPath(), "UTF-8");
    } catch (final UnsupportedEncodingException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    final String simpleProject =
        "<?xml version=\"1.0\"?>\n" +
        "<project>" +
        "<database name='database'>" +
        "<schemas><schema path='" + schemaPath + "' /></schemas>" +
        "<procedures><procedure class='org.voltdb.compiler.procedures.TPCCTestProc' /></procedures>" +
        "</database>" +
        "</project>";

    //System.out.println(simpleProject);

    final File projectFile = VoltProjectBuilder.writeStringToTempFile(simpleProject);
    final String projectPath = projectFile.getPath();

    final VoltCompiler compiler = new VoltCompiler();
    final ClusterConfig cluster_config = new ClusterConfig(1, 1, 0, "localhost");

    final Catalog catalog = compiler.compileCatalog(projectPath, cluster_config);
    assertNotNull(catalog);

    // Now check that CUSTOMER correctly references DISTRICT
    //  (1) Make sure CUSTOMER has a fkey constraint
    //  (2) Make sure that each source column in CUSTOMER points to the constraint
    //  (3) Make sure that the fkey constraint points to DISTRICT
    final Database catalog_db = catalog.getClusters().get("cluster").getDatabases().get("database");
    assertNotNull(catalog_db);

    final Table cust_table = catalog_db.getTables().get("CUSTOMER");
    assertNotNull(cust_table);
    final Table dist_table = catalog_db.getTables().get("DISTRICT");
    assertNotNull(dist_table);

    // In the code below, we will refer to the column that is pointed to by another column
    // in the dependency as the parent, and the column with the fkey constraint as the child
    boolean found = false;
    for (final Constraint catalog_const : cust_table.getConstraints()) {
        final ConstraintType const_type = ConstraintType.get(catalog_const.getType());
        if (const_type == ConstraintType.FOREIGN_KEY) {
            found = true;
            assertEquals(dist_table, catalog_const.getForeignkeytable());
            assertEquals(catalog_const.getForeignkeycols().size(), 2);

            for (final ColumnRef catalog_parent_colref : catalog_const.getForeignkeycols()) {

                // We store the name of the child column in the name of the ColumnRef catalog
                // object to the parent
                final Column catalog_child_col = cust_table.getColumns().get(catalog_parent_colref.getTypeName());
                assertNotNull(catalog_child_col);
                // Lame
                boolean found_const_for_child = false;
                for (final ConstraintRef catalog_constref : catalog_child_col.getConstraints()) {
                    if (catalog_constref.getConstraint().equals(catalog_const)) {
                        found_const_for_child = true;
                        break;
                    }
                }
                assertTrue(found_const_for_child);

                final Column catalog_parent_col = catalog_parent_colref.getColumn();
                assertEquals(dist_table, catalog_parent_col.getParent());
            }
            break;
        }
    }
    assertTrue(found);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:77,代码来源:TestVoltCompiler.java

示例13: sqlForDefaultProc

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
public String sqlForDefaultProc(Procedure defaultProc) {
    String name = defaultProc.getClassname();
    String[] parts = name.split("\\.");
    String action = parts[1];

    Table table = defaultProc.getPartitiontable();
    Column partitionColumn = defaultProc.getPartitioncolumn();

    final CatalogMap<Constraint> constraints = table.getConstraints();
    final Iterator<Constraint> it = constraints.iterator();
    Constraint pkey = null;
    while (it.hasNext()) {
        Constraint constraint = it.next();
        if (constraint.getType() == ConstraintType.PRIMARY_KEY.getValue()) {
            pkey = constraint;
            break;
        }
    }

    switch(action) {
    case "select":
        assert (defaultProc.getSinglepartition());
        return generateCrudSelect(table, partitionColumn, pkey);
    case "insert":
        if (defaultProc.getSinglepartition()) {
            return generateCrudInsert(table, partitionColumn);
        }
        else {
            return generateCrudReplicatedInsert(table);
        }
    case "update":
        if (defaultProc.getSinglepartition()) {
            return generateCrudUpdate(table, partitionColumn, pkey);
        }
        else {
            return generateCrudReplicatedUpdate(table, pkey);
        }
    case "delete":
        if (defaultProc.getSinglepartition()) {
            return generateCrudDelete(table, partitionColumn, pkey);
        }
        else {
            return generateCrudReplicatedDelete(table, pkey);
        }
    case "upsert":
        if (defaultProc.getSinglepartition()) {
            return generateCrudUpsert(table, partitionColumn);
        }
        else {
            return generateCrudReplicatedUpsert(table, pkey);
        }
    default:
        throw new RuntimeException("Invalid input to default proc SQL generator.");
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:56,代码来源:DefaultProcedureManager.java

示例14: testToSchema

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 *
 */
public void testToSchema() {
    String search_str = "";

    // Simple check to make sure things look ok...
    for (Table catalog_tbl : catalog_db.getTables()) {
        StringBuilder sb = new StringBuilder();
        CatalogSchemaTools.toSchema(sb, catalog_tbl, null, null);
        String sql = sb.toString();
        assertTrue(sql.startsWith("CREATE TABLE " + catalog_tbl.getTypeName()));

        // Columns
        for (Column catalog_col : catalog_tbl.getColumns()) {
            assertTrue(sql.indexOf(catalog_col.getTypeName()) != -1);
        }

        // Constraints
        for (Constraint catalog_const : catalog_tbl.getConstraints()) {
            ConstraintType const_type = ConstraintType.get(catalog_const.getType());
            Index catalog_idx = catalog_const.getIndex();
            List<ColumnRef> columns = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");

            if (!columns.isEmpty()) {
                search_str = "";
                String add = "";
                for (ColumnRef catalog_colref : columns) {
                    search_str += add + catalog_colref.getColumn().getTypeName();
                    add = ", ";
                }
                assertTrue(sql.indexOf(search_str) != -1);
            }

            switch (const_type) {
                case PRIMARY_KEY:
                    assertTrue(sql.indexOf("PRIMARY KEY") != -1);
                    break;
                case FOREIGN_KEY:
                    search_str = "REFERENCES " + catalog_const.getForeignkeytable().getTypeName();
                    assertTrue(sql.indexOf(search_str) != -1);
                    break;
            }
        }
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:47,代码来源:TestCatalogUtil.java

示例15: getType

import org.voltdb.types.ConstraintType; //导入依赖的package包/类
/**
 * Get the type of constraint violation that occurred
 * @return Type of constraint violation
 */
public ConstraintType getType() {
    return type;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:8,代码来源:ConstraintFailureException.java


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