|
From: <one...@us...> - 2003-01-24 16:16:36
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister
In directory sc8-pr-cvs1:/tmp/cvs-serv13407/sf/hibernate/persister
Modified Files:
AbstractEntityPersister.java ClassPersister.java
EntityPersister.java
Log Message:
added mutable attribute to <property> element
Index: AbstractEntityPersister.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/AbstractEntityPersister.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** AbstractEntityPersister.java 24 Jan 2003 13:07:17 -0000 1.6
--- AbstractEntityPersister.java 24 Jan 2003 16:15:58 -0000 1.7
***************
*** 100,103 ****
--- 100,104 ----
private transient final String[] propertyNames;
private transient final Type[] propertyTypes;
+ private transient final boolean[] propertyMutability;
private transient final String versionPropertyName;
***************
*** 243,247 ****
*/
public int[] findDirty(Object[] x, Object[] y, Object owner, SessionImplementor session) throws HibernateException {
! int[] props = TypeFactory.findDirty( propertyTypes, x, y, owner, session.getFactory() );
if ( props==null) {
return null;
--- 244,248 ----
*/
public int[] findDirty(Object[] x, Object[] y, Object owner, SessionImplementor session) throws HibernateException {
! int[] props = TypeFactory.findDirty( propertyTypes, x, y, propertyMutability, owner, session.getFactory() );
if ( props==null) {
return null;
***************
*** 601,604 ****
--- 602,606 ----
propertyTypes = new Type[hydrateSpan];
propertyNames = new String[hydrateSpan];
+ propertyMutability = new boolean[hydrateSpan];
getters = new ReflectHelper.Getter[hydrateSpan];
setters = new ReflectHelper.Setter[hydrateSpan];
***************
*** 617,620 ****
--- 619,623 ----
setters[i] = ReflectHelper.getSetter( mappedClass, propertyNames[i] );
propertyTypes[i] = prop.getType();
+ propertyMutability[i] = prop.isMutable();
cascadeStyles[i] = prop.cascade();
***************
*** 691,694 ****
--- 694,701 ----
}
+ public boolean[] getPropertyMutability() {
+ return propertyMutability;
+ }
+
}
Index: ClassPersister.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/ClassPersister.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ClassPersister.java 15 Jan 2003 12:49:01 -0000 1.4
--- ClassPersister.java 24 Jan 2003 16:15:59 -0000 1.5
***************
*** 235,238 ****
--- 235,240 ----
public String[] getPropertyNames();
+ public boolean[] getPropertyMutability();
+
/**
* Get the cascade styles of the propertes (optional operation)
Index: EntityPersister.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/EntityPersister.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** EntityPersister.java 24 Jan 2003 13:07:17 -0000 1.9
--- EntityPersister.java 24 Jan 2003 16:15:59 -0000 1.10
***************
*** 22,25 ****
--- 22,26 ----
import java.sql.SQLException;
import java.util.ArrayList;
+ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
***************
*** 308,318 ****
* Generate the SQL that updates a row by id (and version)
*/
! protected String generateUpdateString() {
! return new Update()
.setTableName( getTableName() )
! .addColumns( getColumnNames() )
.setPrimaryKeyColumnNames( getIdentifierColumnNames() )
! .setVersionColumnName( getVersionColumnName() )
! .toStatementString();
}
--- 309,322 ----
* Generate the SQL that updates a row by id (and version)
*/
! protected String generateUpdateString(boolean[] includeProperty) {
! Update update = new Update()
.setTableName( getTableName() )
! //.addColumns( getColumnNames() )
.setPrimaryKeyColumnNames( getIdentifierColumnNames() )
! .setVersionColumnName( getVersionColumnName() );
! for ( int i=0; i<hydrateSpan; i++ ) {
! if ( includeProperty[i] ) update.addColumns( propertyColumnNames[i] );
! }
! return update.toStatementString();
}
***************
*** 336,340 ****
* Marshall the fields of a persistent instance to a prepared statement
*/
! protected int dehydrate(Serializable id, Object[] fields, PreparedStatement st, SessionImplementor session) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) log.trace("Dehydrating entity: " + getClassName() + '#' + id);
--- 340,344 ----
* Marshall the fields of a persistent instance to a prepared statement
*/
! protected int dehydrate(Serializable id, Object[] fields, boolean[] includeProperty, PreparedStatement st, SessionImplementor session) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) log.trace("Dehydrating entity: " + getClassName() + '#' + id);
***************
*** 342,347 ****
int index = 1;
for (int j=0; j<hydrateSpan; j++) {
! getPropertyTypes()[j].nullSafeSet( st, fields[j], index, session );
! index += propertyColumnSpans[j];
}
--- 346,353 ----
int index = 1;
for (int j=0; j<hydrateSpan; j++) {
! if ( includeProperty[j] ) {
! getPropertyTypes()[j].nullSafeSet( st, fields[j], index, session );
! index += propertyColumnSpans[j];
! }
}
***************
*** 406,409 ****
--- 412,421 ----
}
+ private boolean[] allProperties() {
+ boolean[] result = new boolean[hydrateSpan];
+ Arrays.fill(result, true);
+ return result;
+ }
+
/**
* Persist an object
***************
*** 424,428 ****
// insert was issued (cos of foreign key constraints). Not necessarily the object's current state
! dehydrate(id, fields, statement, session);
session.getBatcher().addToBatch(1);
--- 436,440 ----
// insert was issued (cos of foreign key constraints). Not necessarily the object's current state
! dehydrate(id, fields, allProperties(), statement, session);
session.getBatcher().addToBatch(1);
***************
*** 451,455 ****
try {
! dehydrate(null, fields, statement, session);
statement.executeUpdate();
}
--- 463,467 ----
try {
! dehydrate(null, fields, allProperties(), statement, session);
statement.executeUpdate();
}
***************
*** 541,545 ****
*/
public void update(Serializable id, Object[] fields, int[] dirtyFields, Object oldVersion, Object object, SessionImplementor session) throws SQLException, HibernateException {
!
if ( log.isTraceEnabled() ) {
log.trace("Updating entity: " + getClassName() + '#' + id);
--- 553,560 ----
*/
public void update(Serializable id, Object[] fields, int[] dirtyFields, Object oldVersion, Object object, SessionImplementor session) throws SQLException, HibernateException {
! doUpdate(id, fields, getPropertyMutability(), oldVersion, object, sqlUpdate(), session);
! }
!
! protected void doUpdate(Serializable id, Object[] fields, boolean[] includeProperty, Object oldVersion, Object object, String sql, SessionImplementor session) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) {
log.trace("Updating entity: " + getClassName() + '#' + id);
***************
*** 549,554 ****
if (!hasColumns) return;
- //Render the SQL query
- String sql = sqlUpdate();
final PreparedStatement statement;
if ( isVersioned() ) {
--- 564,567 ----
***************
*** 563,567 ****
//Now write the values of fields onto the prepared statement
! int versionParam = dehydrate(id, fields, statement, session);
if ( isVersioned() ) {
--- 576,580 ----
//Now write the values of fields onto the prepared statement
! int versionParam = dehydrate(id, fields, includeProperty, statement, session);
if ( isVersioned() ) {
***************
*** 700,704 ****
insertString = generateInsertString(false);
identityInsertString = isIdentifierAssignedByInsert() ? generateInsertString(true) : null;
! updateString = generateUpdateString();
String lockString = generateLockString();
--- 713,717 ----
insertString = generateInsertString(false);
identityInsertString = isIdentifierAssignedByInsert() ? generateInsertString(true) : null;
! updateString = generateUpdateString( getPropertyMutability() );
String lockString = generateLockString();
|