Package org.caffinitas.mapper.core.codec

Examples of org.caffinitas.mapper.core.codec.Binder


                }
            }
        }

        @SuppressWarnings("ResultOfObjectAllocationIgnored") boolean isModified() {
            Binder binder = new Binder(entity.writeDataColumns, true, entity.primaryKeyColumns, PersistMode.UPDATE, true);
            entity.buildModifyBindColumns(instance, binder);

            for (int i = 0; i < columns.length; i++) {
                CqlColumn col = columns[i];
                ByteBuffer val = binder.getBound(col);
                if (val == null) {
                    continue;
                }
                val = val.duplicate();
                ByteBuffer loaded = values[i];
View Full Code Here


            return false;
        }

        @SuppressWarnings("ResultOfObjectAllocationIgnored") ModifyFuture<T> updateIfModified() {
            Binder binder = new Binder(entity.writeDataColumns, true, entity.primaryKeyColumns, PersistMode.UPDATE, true);
            entity.buildModifyBindColumns(instance, binder);

            boolean changed = false;
            for (int i = 0; i < columns.length; i++) {
                CqlColumn col = columns[i];
                ByteBuffer val = binder.getBound(col);
                if (val == null) {
                    continue;
                }
                val = val.duplicate();
                ByteBuffer loaded = values[i];
View Full Code Here

    Object serializeAny(Object o, boolean isStaticColumn, boolean serializeDefault) {
        if (o == null) {
            return null;
        }

        Binder compBinder = new Binder(allColumns, true, null, PersistMode.INSERT, serializeDefault);

        for (MappedAttribute attribute : allAttributes) {
            attribute.bindToStatement(o, compBinder);
        }

        ByteBuffer compValue = compBinder.bindComposite(isStaticColumn);

        return compValue;
    }
View Full Code Here

    Object serializeAny(Object o) {
        if (o == null) {
            return null;
        }

        Binder udtBinder = new Binder(allColumns, true, null, PersistMode.INSERT, true);

        for (MappedAttribute attribute : allAttributes) {
            attribute.bindToStatement(o, udtBinder);
        }

        CUDTValue udtValue = udtDefinition.newValue();
        udtBinder.bindUDT(0, udtValue);

        return udtValue;
    }
View Full Code Here

        // VALUES ( value, value ... )
        // IF NOT EXISTS
        // USING option AND option
        boolean serializeDefault = PersistOption.WriteDefaultValueOption.get(persistOptions, writeNullOnInsert);
        CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
        Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.INSERT, serializeDefault);

        int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

        for (Map.Entry entry : instance.getCluster().entrySet()) {
            binder.reset();

            buildModifyBindColumns(instance, binder, partitionAttributes);
            if (clusteringColumn != null) {
                binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(entry.getKey(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getKey(), binder, clusteringKeyAttributes);
            }
            if (valueColumn != null) {
                binder.setBytesUnsafe(valueColumn, valuePrimitive.serialize(entry.getValue(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getValue(), binder, valueAttributes);
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.INSERT, binder);
            int idx = binder.bindColumns(0, bStmt);
            bindUsingOptions(bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
View Full Code Here

        Set removed = instance.getRemoved();
        if (!removed.isEmpty()) {
            int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

            Binder binder = new Binder(null, true, primaryKeyColumns, PersistMode.DELETE, true);
            for (Object key : removed) {
                binder.reset();

                buildModifyBindColumns(instance, binder, partitionAttributes);
                if (clusteringColumn != null) {
                    binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(key, protocolVersion));
                } else {
                    buildModifyBindColumns(key, binder, clusteringKeyAttributes);
                }
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);
            int idx = binder.bindColumns(0, bStmt);
            bindUsingOptions(bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
            }

            batch.add(bStmt);
        }

        // UPDATE keyspace_name.table_name
        // USING option AND option
        // SET assignment , assignment, ...
        // WHERE row_specification
        // IF column_name = literal AND column_name = literal . . .

        int protocolVersion = persistenceSession.persistenceManager.protocolVersion;

        CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
        Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.UPDATE, true);
        for (Map.Entry entry : instance.getCluster().entrySet()) {
            binder.reset();

            buildModifyBindColumns(instance, binder, partitionAttributes);
            if (clusteringColumn != null) {
                binder.setBytesUnsafe(clusteringColumn, clusteringPrimitive.serialize(entry.getKey(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getKey(), binder, clusteringKeyAttributes);
            }
            if (valueColumn != null) {
                binder.setBytesUnsafe(valueColumn, valuePrimitive.serialize(entry.getValue(), protocolVersion));
            } else {
                buildModifyBindColumns(entry.getValue(), binder, valueAttributes);
            }

            BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.UPDATE, binder);
            int idx = bindUsingOptions(bStmt, persistOptions, 0);
            idx = binder.bindColumns(idx, bStmt);
            bindIfOptions(binder, bStmt, persistOptions, idx);
            statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);

            if (prePersist != null) {
                prePersist.invoke(instance, this, type, bStmt);
View Full Code Here

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        Binder binder = new Binder(null, true, partitionKeyColumns, PersistMode.DELETE, true);
        buildModifyBindColumns(instance, binder, partitionAttributes);
        BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);

        int idx = bindUsingOptions(bStmt, persistOptions, 0);

        binder.bindColumns(idx, bStmt);

        bindIfOptions(binder, bStmt, persistOptions, idx);

        statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);
View Full Code Here

        }

        CqlColumn[] readColumns = readColumns(persistOptions);
        CqlColumn[] pkColumns = partitionKeyColumns;

        Binder binder = new Binder(readColumns, false, pkColumns, null, true);

        int idx = 0;
        try {
            for (CqlColumn col : pkColumns) {
                col.dataTypeMapper.fromObject(binder, col, primaryKey[idx++]);
            }
        } catch (Throwable t) {
            throw new RuntimeException("Invalid primary key element "+Arrays.toString(primaryKey), t);
        }

        PreparedStatement pstmt = preparedStatements.statementFor(session, PreparedStatements.StatementType.SELECT, binder, persistOptions);
        BoundStatement bStmt = pstmt.bind();
        statementOptions.applyRead(bStmt, readConsistencyLevel, persistOptions);
        PersistOption.forBoundStatement(persistOptions, bStmt);

        idx = binder.bindColumns(0, bStmt);

        PersistOption.LimitOption.apply(bStmt, persistOptions, idx);

        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Submitting load for {} : {}", type, bStmt.preparedStatement().getQueryString());
View Full Code Here

                System.arraycopy(aCols, 0, loadColumns, iCol, aColCnt);
                iCol += aColCnt;
            }
        }

        Binder binder = new Binder(loadColumns, false, primaryKeyColumns, null, true);

        buildModifyBindColumns(container, binder);

        Session session = persistenceSession.driverSession();

        PreparedStatement pstmt = preparedStatements
            .statementFor(session, PreparedStatements.StatementType.SELECT, binder, persistOptions);
        BoundStatement bStmt = pstmt.bind();
        statementOptions.applyRead(bStmt, readConsistencyLevel, persistOptions);
        PersistOption.forBoundStatement(persistOptions, bStmt);

        int idx = binder.bindColumns(0, bStmt);

        PersistOption.LimitOption.apply(bStmt, persistOptions, idx);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Lazy load of {} attributes for {}", attrs.length, type);
View Full Code Here

        // VALUES ( value, value ... )
        // IF NOT EXISTS
        // USING option AND option
        boolean serializeDefault = PersistOption.WriteDefaultValueOption.get(persistOptions, writeNullOnInsert);
        CqlColumn[] columns = PersistOption.ColumnRestrictionOption.filter(persistOptions, writeDataColumns);
        Binder binder = new Binder(columns, true, primaryKeyColumns, PersistMode.INSERT, serializeDefault);

        buildModifyBindColumns(instance, binder);

        BoundStatement bStmt =
            buildModifyInitial(persistenceSession.driverSession(), persistOptions, PreparedStatements.StatementType.INSERT, binder);

        int idx = binder.bindColumns(0, bStmt);

        bindUsingOptions(bStmt, persistOptions, idx);

        statementOptions.applyWrite(bStmt, writeConsistencyLevel, serialConsistencyLevel, persistOptions);
View Full Code Here

TOP

Related Classes of org.caffinitas.mapper.core.codec.Binder

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.