Skip to content

Commit cf903b7

Browse files
stalepsebersole
authored andcommitted
HHH-8354 - New dirty-checking options based on bytecode enhancement
1 parent d476eb7 commit cf903b7

29 files changed

+2457
-192
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.bytecode.enhance.spi;
25+
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
29+
/**
30+
* @author <a href="mailto:[email protected]">Ståle W. Pedersen</a>
31+
*/
32+
public class CollectionTracker {
33+
34+
private Map<String, Integer> tracker;
35+
36+
public CollectionTracker() {
37+
tracker = new HashMap<String, Integer>();
38+
}
39+
40+
public void add(String name, int size) {
41+
tracker.put(name, size);
42+
}
43+
44+
public int getSize(String name) {
45+
Integer size = tracker.get(name);
46+
if(size == null)
47+
return -1;
48+
else
49+
return size;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.bytecode.enhance.spi;
25+
26+
import org.hibernate.engine.spi.CompositeOwner;
27+
28+
/**
29+
* small low memory class to keep references to composite owners
30+
*
31+
* @author <a href="mailto:[email protected]">Ståle W. Pedersen</a>
32+
*/
33+
public class CompositeOwnerTracker {
34+
35+
private String[] names;
36+
private CompositeOwner[] owners;
37+
private int size = 0;
38+
39+
public CompositeOwnerTracker() {
40+
names = new String[1];
41+
owners = new CompositeOwner[1];
42+
}
43+
44+
public void add(String name, CompositeOwner owner) {
45+
for(int i=0; i<size;i++) {
46+
if(names[i].equals(name)) {
47+
owners[i] = owner;
48+
return;
49+
}
50+
}
51+
if ( size >= names.length) {
52+
String[] tmpNames = new String[size+1];
53+
System.arraycopy(names, 0, tmpNames, 0, size);
54+
names = tmpNames;
55+
CompositeOwner[] tmpOwners = new CompositeOwner[size+1];
56+
System.arraycopy(owners, 0, tmpOwners, 0, size);
57+
owners = tmpOwners;
58+
}
59+
names[size] = name;
60+
owners[size] = owner;
61+
size++;
62+
}
63+
64+
public void callOwner(String fieldName) {
65+
for(int i=0; i < size;i++) {
66+
owners[i].$$_hibernate_trackChange(names[i]+fieldName);
67+
}
68+
}
69+
70+
public void removeOwner(String name) {
71+
for(int i=0; i<size;i++) {
72+
if(names[i].equals(name)) {
73+
if(i < size) {
74+
for(int j=i; j < size-1;j++) {
75+
names[j] = names[j+1];
76+
owners[j] = owners[j+1];
77+
}
78+
names[size-1] = null;
79+
owners[size-1] = null;
80+
size--;
81+
}
82+
}
83+
}
84+
}
85+
}

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java

+7
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,11 @@ public interface EnhancementContext {
121121
* @return {@code true} if the field is lazy loadable; {@code false} otherwise.
122122
*/
123123
public boolean isLazyLoadable(CtField field);
124+
125+
/**
126+
*
127+
* @param field the field to check
128+
* @return {@code true} if the field is mapped
129+
*/
130+
public boolean isMappedCollection(CtField field);
124131
}

0 commit comments

Comments
 (0)