app/src/main/java/db/juhaku/juhakudb/core/android/transaction/StoreTransactionTemplate.java
/**
     * Store middle table joins for given item. This is special processing that is being
     * executed after both join parties are stored to database. First existing references is being
     * deleted and then newly coming references is being stored to database for the item.
     *
     * <p>References is being created for given item from given collection of items.</p>
     *
     * @param item T item from table item.
     * @param items {@link Collection} of to table items.
     *
     * @since 1.2.0
     *
     * @hide
     */
Store middle table joins for given item. This is special processing that is being
executed after both join parties are stored to database. First existing references is being
deleted and then newly coming references is being stored to database for the item.

References is being created for given item from given collection of items.





@hide
Store middle table joins for given item . This is special processing that is being executed after both join parties are stored to database . First existing references is being deleted and then newly coming references is being stored to database for the item . References is being created for given item from given collection of items . @hide
private void storeMiddleTable(final T item, Collection<T> items) {
        final Schema middleTable = findMiddleTable(item.getClass(), items.iterator().next().getClass());
        /*
         * Delete existing references by id.
         */
        Query where = getProcessor().createWhere(null, new Filter() {
            @Override
            public void filter(Root root, PredicateBuilder builder) {
                String middleTableJoinColumn = null;
                for (Reference reference : middleTable.getReferences()) {
                    if (reference.getReferenceTableName().equals(resolveTableName(item.getClass()))) {
                        middleTableJoinColumn = reference.getColumnName();
                    }
                }
                builder.eq(middleTableJoinColumn, ReflectionUtils.getIdFieldValue(item));
            }
        });
        getDb().delete(middleTable.getName(), where.getSql(), where.getArgs());
        String fromTable = resolveTableName(item.getClass());
        /*
         * Store middle table references.
         */
        for (T joinItem : items) {
            ContentValues values = new ContentValues();
            for (Reference reference : middleTable.getReferences()) {
                Object value;
                /*
                 * Determine which id is being used to to which reference. If reference table equals
                 * from table get id of the from item otherwise use to id.
                 */
                if (reference.getReferenceTableName().equals(fromTable)) {
                    value = ReflectionUtils.getIdFieldValue(item).toString();
                } else {
                    value = ReflectionUtils.getIdFieldValue(joinItem);
                }
                values.put(reference.getColumnName(), value.toString());
            }
            insertOrReplace(middleTable.getName(), values);
        }
    }
private void storeMiddleTable ( final T item , Collection < T > items ) { final Schema middleTable = findMiddleTable ( item . getClass ( ) , items . iterator ( ) . next ( ) . getClass ( ) ) ; /*
         * Delete existing references by id.
         */ Query where = getProcessor ( ) . createWhere ( null , new Filter ( ) { @ Override public void filter ( Root root , PredicateBuilder builder ) { String middleTableJoinColumn = null ; for ( Reference reference : middleTable . getReferences ( ) ) { if ( reference . getReferenceTableName ( ) . equals ( resolveTableName ( item . getClass ( ) ) ) ) { middleTableJoinColumn = reference . getColumnName ( ) ; } } builder . eq ( middleTableJoinColumn , ReflectionUtils . getIdFieldValue ( item ) ) ; } } ) ; getDb ( ) . delete ( middleTable . getName ( ) , where . getSql ( ) , where . getArgs ( ) ) ; String fromTable = resolveTableName ( item . getClass ( ) ) ; /*
         * Store middle table references.
         */ for ( T joinItem : items ) { ContentValues values = new ContentValues ( ) ; for ( Reference reference : middleTable . getReferences ( ) ) { Object value ; /*
                 * Determine which id is being used to to which reference. If reference table equals
                 * from table get id of the from item otherwise use to id.
                 */ if ( reference . getReferenceTableName ( ) . equals ( fromTable ) ) { value = ReflectionUtils . getIdFieldValue ( item ) . toString ( ) ; } else { value = ReflectionUtils . getIdFieldValue ( joinItem ) ; } values . put ( reference . getColumnName ( ) , value . toString ( ) ) ; } insertOrReplace ( middleTable . getName ( ) , values ) ; } }
Store middle table joins for given item.
Store middle table joins for given item .
// Create content value for each join item as each item represents one row in database.