All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.abubusoft.kripton.android.annotation.BindSqlAdapter Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright 2015, 2017 Francesco Benincasa ([email protected]).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.abubusoft.kripton.android.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.abubusoft.kripton.android.SqlTypeAdapter;

/**
 * 

* The Interface BindSqlAdapter. This annotation decorates a field to use a * particular SQL Type Adapter to customize persistence on an SQLite table. A * type adapter must implements SqlTypeAdapter interface. It has two parameter * type: the first is the field type (in our example is Bitmap), the second is * the type that we want to use as replacement and that will be used to store * data into an SQLite table column. It implements three methods: *

* *
    *
  • toJava: converts data retrieved from an SQLite table into a * field.
  • *
  • toData: converts a field into data to store into an SQLite * table.
  • *
  • toString: used if you want to use a field as query's * parameter (SQLite wrapper for Android convert all SQL parameter used in where * condition in its string representation). Attributes
  • adapter: SQLite Type * Adapter class *

    Usage

    * *
     * @BindSqlType
     * public class Person {
     * 	public long id;
     * 
     * 	@BindSqlAdapter(adapter = BitmapTypeAdapter.class)
     * 	public Bitmap image;
     * }
     * 
    * *

    * And the associated SQL type adapter: *

    * *
     * public class BitmapTypeAdapter implements SqlTypeAdapter<Bitmap, byte[]> {
     * 
     * 	@Override
     * 	public Bitmap toJava(byte[] dataValue) {
     * 		if (dataValue == null)
     * 			return null;
     * 		return BitmapFactory.decodeByteArray(dataValue, 0, dataValue.length);
     * 	}
     * 
     * 	@Override
     * 	public byte[] toData(Bitmap bitmap) {
     * 		if (bitmap == null)
     * 			return null;
     * 
     * 		ByteArrayOutputStream stream = new ByteArrayOutputStream();
     * 		bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
     * 		return stream.toByteArray();
     * 	}
     * 
     * 	@Override
     * 	public String toString(Bitmap javaValue) {
     * 		throw (new KriptonRuntimeException("Unsupported operation!"));
     * 	}
     * }
     * 
    */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface BindSqlAdapter { /** * Adapter class used to convert bean attribute into column value and * viceversa. * * @return the adapter */ Class> adapter(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy