Added code to check if a named field has been modified, added code to
check if all the modified fields are within a particular subset of fields. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1209 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
//
|
//
|
||||||
// $Id: FieldMask.java,v 1.2 2002/05/11 20:29:27 mdb Exp $
|
// $Id: FieldMask.java,v 1.3 2003/08/26 04:49:05 eric Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
// under the terms of the GNU Lesser General Public License as published
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
@@ -22,6 +22,8 @@ package com.samskivert.jdbc.jora;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides support for doing partial updates to objects in a JORA table.
|
* Provides support for doing partial updates to objects in a JORA table.
|
||||||
@@ -81,6 +83,36 @@ public class FieldMask
|
|||||||
return _modified[index];
|
return _modified[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the field with the specified name is modifed.
|
||||||
|
*/
|
||||||
|
public final boolean isModified (String fieldName)
|
||||||
|
{
|
||||||
|
Integer index = (Integer)_descripMap.get(fieldName);
|
||||||
|
if (index == null) {
|
||||||
|
String errmsg = "Passed in field not in mask.";
|
||||||
|
throw new IllegalArgumentException(errmsg);
|
||||||
|
}
|
||||||
|
return _modified[index.intValue()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a subset of the fields represented by this field mask.
|
||||||
|
* Returns true only if the modified fields intersect the subsetFields.
|
||||||
|
*/
|
||||||
|
public final boolean onlySubSetModified (HashSet subsetFields)
|
||||||
|
{
|
||||||
|
Iterator itr = _descripMap.keySet().iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
String field = (String)itr.next();
|
||||||
|
if (isModified(field) && (!subsetFields.contains(field))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the specified field as modified.
|
* Marks the specified field as modified.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user