Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on Instantiator in preparation for composite-user-type work
- Loading branch information
Showing
26 changed files
with
526 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...e-core/src/main/java/org/hibernate/metamodel/internal/AbstractDynamicMapInstantiator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.metamodel.internal; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.metamodel.spi.Instantiator; | ||
|
||
/** | ||
* Base support for dynamic-map instantiators | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public abstract class AbstractDynamicMapInstantiator implements Instantiator { | ||
public static final String TYPE_KEY = "$type$"; | ||
|
||
private final String roleName; | ||
|
||
public AbstractDynamicMapInstantiator(String roleName) { | ||
if ( roleName == null ) { | ||
throw new IllegalArgumentException( "`roleName` passed to dynamic-map instantiator cannot be null" ); | ||
} | ||
this.roleName = roleName; | ||
} | ||
|
||
public String getRoleName() { | ||
return roleName; | ||
} | ||
|
||
@Override | ||
public boolean isInstance(Object object, SessionFactoryImplementor sessionFactory) { | ||
if ( object instanceof Map ) { | ||
//noinspection rawtypes | ||
final String type = (String) ( (Map) object ).get( TYPE_KEY ); | ||
return isSameRole( type ); | ||
} | ||
|
||
// todo (6.0) : should this be an exception instead? | ||
return false; | ||
} | ||
|
||
protected boolean isSameRole(String type) { | ||
return roleName.equals( type ); | ||
} | ||
|
||
@Override | ||
public boolean isSameClass(Object object, SessionFactoryImplementor sessionFactory) { | ||
return isInstance( object, sessionFactory ); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
protected Map generateDataMap() { | ||
final Map map = new HashMap(); | ||
//noinspection unchecked | ||
map.put( TYPE_KEY, roleName ); | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 0 additions & 131 deletions
131
hibernate-core/src/main/java/org/hibernate/metamodel/internal/DynamicMapInstantiator.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
...core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.metamodel.internal; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.mapping.Component; | ||
import org.hibernate.metamodel.spi.EmbeddableInstantiator; | ||
|
||
/** | ||
* Support for instantiating embeddables as dynamic-map representation | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class EmbeddableInstantiatorDynamicMap | ||
extends AbstractDynamicMapInstantiator | ||
implements EmbeddableInstantiator { | ||
public EmbeddableInstantiatorDynamicMap(Component bootDescriptor) { | ||
super( bootDescriptor.getRoleName() ); | ||
} | ||
|
||
@Override | ||
public Object instantiate(Supplier<Object[]> valuesAccess, SessionFactoryImplementor sessionFactory) { | ||
return generateDataMap(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...e/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.metamodel.internal; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.metamodel.spi.EmbeddableInstantiator; | ||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; | ||
|
||
import static org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer; | ||
|
||
/** | ||
* Support for instantiating embeddables as POJO representation | ||
* using bytecode optimizer | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class EmbeddableInstantiatorPojoOptimized extends AbstractPojoInstantiator implements EmbeddableInstantiator { | ||
private final InstantiationOptimizer instantiationOptimizer; | ||
|
||
public EmbeddableInstantiatorPojoOptimized( | ||
JavaTypeDescriptor<?> javaTypeDescriptor, | ||
InstantiationOptimizer instantiationOptimizer) { | ||
super( javaTypeDescriptor.getJavaTypeClass() ); | ||
this.instantiationOptimizer = instantiationOptimizer; | ||
} | ||
|
||
@Override | ||
public Object instantiate(Supplier<Object[]> valuesAccess, SessionFactoryImplementor sessionFactory) { | ||
return instantiationOptimizer.newInstance(); | ||
} | ||
} |
Oops, something went wrong.