Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2012 Clarion Media, LLC
   * 
   * 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.clarionmedia.infinitum.orm.sqlite.impl;
 
 import java.util.Date;
 import java.util.Map;
 
 

This implementation of com.clarionmedia.infinitum.orm.ObjectMapper provides methods to map domain models to SQLite table columns and vice versa.

Author(s):
Tyler Treat
Version:
1.0 02/13/12
Since:
1.0
 
 public class SqliteMapper extends ObjectMapper {
 
 	private Map<Class<?>, SqliteTypeAdapter<?>> mTypeAdapters;

Constructs a new SqliteMapper.
 
 	public SqliteMapper() {
 	}
 
 		// We do not map transient classes!
 			return null;
 		SqliteModelMap ret = new SqliteModelMap(model);
 		ContentValues values = new ContentValues();
 		for (Field field : .getPersistentFields(model.getClass())) {
 			// Don't map primary keys if they are autoincrementing
 				continue;
 			// Map relationships
 				mapRelationship(retmodelfield);
 				continue;
 			}
 			// Map Field values
 			mapField(valuesmodelfield);
 		}
 		ret.setContentValues(values);
 		return ret;
 	}

Retrieves a com.clarionmedia.infinitum.orm.sqlite.SqliteTypeAdapter for the given java.lang.Class.

Parameters:
type the Class to retrieve a SqliteTypeResolver for
Returns:
SqliteTypeResolver for the given type
Throws:
com.clarionmedia.infinitum.orm.exception.InvalidMappingException if no SqliteTypeResolver exists for the given Class
	@SuppressWarnings("unchecked")
	public <T> SqliteTypeAdapter<T> resolveType(Class<T> typethrows InvalidMappingException {
		type = Primitives.unwrap(type);
			return (SqliteTypeAdapter<T>) .get(type);
		throw new InvalidMappingException(String.format("Cannot map '%s' to a database column."type.getSimpleName()));
	}
	public <T> void registerTypeAdapter(Class<T> typeTypeAdapter<T> adapter) {
		if (adapter instanceof SqliteTypeAdapter)
			.put(type, (SqliteTypeAdapter<T>) adapter);
	}
	}
	public boolean isTextColumn(Field f) {
	}

Retrieves the SQLite data type associated with the given java.lang.reflect.Field.

Parameters:
field theField to retrieve the SQLite data type for
Returns:
SqliteDataType that matches the given Field
		SqliteDataType ret = null;
		Class<?> c = Primitives.unwrap(field.getType());
		return ret;
	}

Retrieves the SQLite data type associated with the given java.lang.Object.

Parameters:
object the Object to retrieve the SQLite data type for
Returns:
SqliteDataType that matches the given Object
		SqliteDataType ret = null;
		Class<?> c = Primitives.unwrap(object.getClass());
		return ret;
	}
	// Map Field value to ContentValues
	private void mapField(ContentValues valuesObject modelField fieldthrows InvalidMappingException {
		if (AbstractProxy.isAopProxy(model)) {
			model = AbstractProxy.getProxy(model).getTarget();
		}
		Object val = .getFieldValue(modelfield);
		resolveType(field.getType()).mapObjectToColumn(valcolNamevalues);
	}
New to GrepCode? Check out our FAQ X