001: /**
002: * Copyright (C) 2007 NetMind Consulting Bt.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 3 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package hu.netmind.persistence;
018:
019: import java.util.*;
020: import hu.netmind.persistence.parser.*;
021:
022: /**
023: * Classes implementing this interface can handle custom attribute types
024: * aside from primitive types.
025: * @author Brautigam Robert
026: * @version Revision: $Revision$
027: */
028: public interface TypeHandler {
029: /**
030: * Ensure that the table or tables (if there are some) backing this
031: * attribute exist.
032: * @param parentInfo The ClassInfo of the container class.
033: * @param attributeName The attribute name of the handled attribute.
034: * @param create Whether to physically create the tables or not.
035: */
036: void ensureTableExists(ClassInfo parentInfo, String attributeName,
037: boolean create);
038:
039: /**
040: * Get the attribute types that are representing this type
041: * in the original object.
042: */
043: Map getAttributeTypes(String attributeName);
044:
045: /**
046: * Determine whether the two values differ.
047: */
048: boolean hasChanged(ClassInfo info, Object obj,
049: String attributeName, Map dbAttributes);
050:
051: /**
052: * Get the umarshalled instance.
053: * @param classInfo The info of the parent object.
054: * @param obj The object itself.
055: * @param attributeName The name of the attribute in question.
056: * @param marshalledValues All the values of the parent object.
057: * @param timeControl The time control in which the parent was selected.
058: */
059: Object unmarshallType(ClassInfo classInfo, Object obj,
060: String attributeName, Map marshalledValues,
061: TimeControl timeControl);
062:
063: /**
064: * Save the changes occured.
065: * @param classInfo The class info of the parent object.
066: * @param current The parent object.
067: * @param attributeName The name of the attribute about to save.
068: * @param transaction The transaction the saves must occur in.
069: * @param currentSerial The serial id the current saved are in.
070: * @param oldValue The old value as known by the object tracker.
071: * @param newValue The new value.
072: * @param waitingObjects List of object on which this operation depends on.
073: * This is writable.
074: * @param events The events the type save generated.
075: * @param changedAttributes The attributes need to be updated in the
076: * database.
077: * @param dbAttributes The database attributes.
078: * @param updatedAttributes The attributes that need to be updated
079: * in the object tracker.
080: * @return The new object of the attribute.
081: */
082: Object save(ClassInfo classInfo, Object current,
083: String attributeName, Transaction transaction,
084: Long currentSerial, Object oldValue, Object newValue,
085: Set waitingObjects, List events, Map changedAttributes,
086: Map dbAttributes);
087:
088: /**
089: * Called when all save operations have completed, and all dependent
090: * objects were saved.
091: */
092: void postSave(Object value);
093:
094: /**
095: * Create the approriate symbol entry when parsing a query.
096: */
097: WhereResolver.SymbolTableEntry getSymbolEntry(
098: AttributeSpecifier spec,
099: WhereResolver.SymbolTableEntry previousEntry,
100: ClassInfo previousInfo, ReferenceTerm previousTerm)
101: throws ParserException;
102:
103: /**
104: * Determine the next class info after the given specifier.
105: */
106: ClassInfo getSymbolInfo(WhereResolver.SymbolTableEntry entry,
107: AttributeSpecifier spec) throws ParserException;
108: }
|