Package com.foundationdb.ais.model

Examples of com.foundationdb.ais.model.PrimaryKey


class PrimaryKeyIsNotNull implements AISValidation {

    @Override
    public void validate(AkibanInformationSchema ais, AISValidationOutput output) {
        for (Table table : ais.getTables().values()) {
            PrimaryKey index = table.getPrimaryKeyIncludingInternal();
            if(index == null) {
                continue; // Checked by TableHasPrimaryKey
            }
            for (Column column : index.getColumns()) {
                if (column.getNullable()) {
                    output.reportFailure(new AISValidationFailure (
                            new PrimaryKeyNullColumnException (table.getName(), column.getName())));
                }
            }
View Full Code Here


        // Lots of checking, the more the merrier
        final Table cTable = ais.getTable( ddl().getTableName(session(), cId) );
        {
            assertEquals("c.columns.size()", 2, cTable.getColumns().size());
            assertEquals("c.indexes.size()", 1, cTable.getIndexes().size());
            PrimaryKey pk = cTable.getPrimaryKey();
            List<Column> expectedPkCols = Arrays.asList( cTable.getColumn("cid") );
            assertEquals("pk cols", expectedPkCols, pk.getColumns());
            assertSame("pk index", cTable.getIndex("PRIMARY"), pk.getIndex());
            assertEquals("pk index cols size", 1, pk.getIndex().getKeyColumns().size());

            assertEquals("parent join", null, cTable.getParentJoin());
            assertEquals("child joins.size", 1, cTable.getChildJoins().size());
        }
        final Table oTable = ais.getTable( ddl().getTableName(session(), oId) );
        {
            assertEquals("c.columns.size()", 2, oTable.getColumns().size());
            assertEquals("c.indexes.size()", 2, oTable.getIndexes().size());
            PrimaryKey pk = oTable.getPrimaryKey();
            List<Column> expectedPkCols = Arrays.asList( oTable.getColumn("oid") );
            assertEquals("pk cols", expectedPkCols, pk.getColumns());
            assertSame("pk index", oTable.getIndex("PRIMARY"), pk.getIndex());
            assertEquals("pk index cols size", 1, pk.getIndex().getKeyColumns().size());

            assertNotNull("parent join is null", oTable.getParentJoin());
            assertSame("parent join", cTable.getChildJoins().get(0), oTable.getParentJoin());
            assertEquals("child joins.size", 1, oTable.getChildJoins().size());
        }
        final Table iTable = ais.getTable( ddl().getTableName(session(), iId) );
        {
            assertEquals("c.columns.size()", 3, iTable.getColumns().size());
            assertEquals("c.indexes.size()", 2, iTable.getIndexes().size());
            PrimaryKey pk = iTable.getPrimaryKey();
            List<Column> expectedPkCols = Arrays.asList( iTable.getColumn("iid") );
            assertEquals("pk cols", expectedPkCols, pk.getColumns());
            assertSame("pk index", iTable.getIndex("PRIMARY"), pk.getIndex());
            assertEquals("pk index cols size", 1, pk.getIndex().getKeyColumns().size());

            assertNotNull("parent join is null", iTable.getParentJoin());
            assertSame("parent join", oTable.getChildJoins().get(0), iTable.getParentJoin());
            assertEquals("child joins.size", 0, iTable.getChildJoins().size());
        }
View Full Code Here

    protected static void checkTable(Table table, TupleUsage usage,
                                     List<String> illegal) {
        switch (usage) {
        case KEY_ONLY:
            PrimaryKey pkey = table.getPrimaryKeyIncludingInternal();
            for (Column column : pkey.getColumns()) {
                checkColumn(column, illegal);
            }
            break;
        case KEY_AND_ROW:
            for (Column column : table.getColumnsIncludingInternal()) {
View Full Code Here

        return exprs;
    }

    protected RowStream assembleReturningProject(RowStream stream, Table table) {
        if(table.getPrimaryKey() != null) {
            PrimaryKey key = table.getPrimaryKey();
            int size  = key.getIndex().getKeyColumns().size();
            List<TPreparedExpression> pExpressions = new ArrayList<>(size);
            for(IndexColumn column : key.getIndex().getKeyColumns()) {
                int fieldIndex = column.getColumn().getPosition();
                pExpressions.add(new TPreparedField(stream.rowType.typeAt(fieldIndex), fieldIndex));
            }
            stream.operator = API.project_Table(stream.operator,
                                                stream.rowType,
View Full Code Here

     *   Index Scan (table, pk-> ?[, ?...])
     */
    public static Operator generateBranchPlan (AkibanInformationSchema ais, Table table) {
        final Operator indexScan = generateIndexScan(ais, table);
        final Schema schema = SchemaCache.globalSchema(ais);
        PrimaryKey pkey = table.getPrimaryKeyIncludingInternal();
        IndexRowType indexType = schema.indexRowType(pkey.getIndex());
        return generateBranchPlan(table, indexScan, indexType);
    }
View Full Code Here

     * @param table
     * @return Operator plan for the Index scan
     */
    private static Operator generateIndexScan (AkibanInformationSchema ais, Table table) {
        final Schema schema = SchemaCache.globalSchema(ais);
        PrimaryKey pkey = table.getPrimaryKeyIncludingInternal();
        final int nkeys = pkey.getColumns().size();
        IndexRowType indexType = schema.indexRowType(pkey.getIndex());

        List<TPreparedExpression> pexprs = new ArrayList<>(nkeys);
        for (int i = 0; i < nkeys; i++) {
            pexprs.add(new TPreparedParameter(i, indexType.typeAt(i)));
        }
View Full Code Here

       
        if (context.table.getPrimaryKey() == null) {
            throw new NoSuchIndexException(Index.PRIMARY);
        }
       
        PrimaryKey pkIndex = context.table.getPrimaryKey();
        int pkFields = 0;
        Iterator<Entry<String,JsonNode>> i = node.fields();
        while (i.hasNext()) {
            Entry<String,JsonNode> field = i.next();
            if (field.getValue().isContainerNode()) {
                throw new InvalidChildCollectionException(field.getKey());
            } else if (field.getValue().isValueNode()) {
                Column column = getColumn (context.table, field.getKey());
                if (field.getValue().isNull()) {
                    context.allValues.put(column, null);
                } else {
                    context.allValues.put (column, field.getValue().asText());
                }
                if (pkIndex.getColumns().contains(column)) {
                    pkFields++;
                    // NB: PATCH requires all PK columns to be specified. As there is no
                    // DEFAULT but they also can't actually be NULL, treat it as not present.
                    if (field.getValue().isNull()) {
                        context.allValues.remove(column);
                        i.remove();
                    }
                }
            }
        }
       
        if (pkIndex.getColumns().size() != pkFields) {
            throw new KeyColumnMissingException(pkIndex.getIndex().getIndexName().toString());
        }
        Row row = determineExistance (context);
        if (row != null) {
            runUpdate (appender, context, row);
        } else {
View Full Code Here

TOP

Related Classes of com.foundationdb.ais.model.PrimaryKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.