Java Code Examples for net.sf.cglib.proxy.NoOp#INSTANCE
The following examples show how to use
net.sf.cglib.proxy.NoOp#INSTANCE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassByImplementationBenchmark.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Performs a benchmark of an interface implementation using cglib. * * @return The created instance, in order to avoid JIT removal. */ @Benchmark public ExampleInterface benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new FixedValue() { public Object loadObject() { return null; } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleInterface) enhancer.create(); }
Example 2
Source File: SeiFactoryImpl.java From tomee with Apache License 2.0 | 6 votes |
public Remote createServiceEndpoint() throws ServiceException { //TODO figure out why this can't be called in readResolve! // synchronized (this) { // if (!initialized) { // initialize(); // initialized = true; // } // } Service service = ((ServiceImpl) serviceImpl).getService(); GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, location); Callback callback = new ServiceEndpointMethodInterceptor(serviceEndpoint, sortedOperationInfos, credentialsName); Callback[] callbacks = new Callback[]{NoOp.INSTANCE, callback}; Enhancer.registerCallbacks(serviceEndpointClass, callbacks); try { return (Remote) constructor.newInstance(new Object[]{serviceEndpoint}); } catch (InvocationTargetException e) { throw (ServiceException) new ServiceException("Could not construct service instance", e.getTargetException()).initCause(e); } }
Example 3
Source File: DalTransactionManager.java From das with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(targetClass); enhancer.setClassLoader(targetClass.getClassLoader()); enhancer.setCallbackFilter(new TransactionalCallbackFilter()); Callback[] callbacks = new Callback[] {new DasTransactionInterceptor(), NoOp.INSTANCE}; enhancer.setCallbacks(callbacks); enhancer.setInterfaces(new Class[] {TransactionalIntercepted.class}); return (T) enhancer.create(); }
Example 4
Source File: ComponentInstantiationPostProcessor.java From cosmic with Apache License 2.0 | 5 votes |
public ComponentInstantiationPostProcessor() { _callbacks = new Callback[2]; _callbacks[0] = NoOp.INSTANCE; _callbacks[1] = new InterceptorDispatcher(); _callbackFilter = new InterceptorFilter(); }
Example 5
Source File: DalTransactionManager.java From dal with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(targetClass); enhancer.setClassLoader(targetClass.getClassLoader()); enhancer.setCallbackFilter(new TransactionalCallbackFilter()); Callback[] callbacks = new Callback[] {new DalTransactionInterceptor(), NoOp.INSTANCE}; enhancer.setCallbacks(callbacks); enhancer.setInterfaces(new Class[] {TransactionalIntercepted.class}); return (T) enhancer.create(); }
Example 6
Source File: ProxyEventCallbackFilter.java From flux with Apache License 2.0 | 5 votes |
@Override protected Object getCallback(Method method) { if(method.getName().equals("name") && method.getReturnType().equals(String.class)) { return getNameCallback(); } if (method.getName().equals("getRealClassName") && method.getReturnType().equals(String.class)) { return getRealClassName(); } return NoOp.INSTANCE; }
Example 7
Source File: ComponentInstantiationPostProcessor.java From cloudstack with Apache License 2.0 | 5 votes |
public ComponentInstantiationPostProcessor() { _callbacks = new Callback[2]; _callbacks[0] = NoOp.INSTANCE; _callbacks[1] = new InterceptorDispatcher(); _callbackFilter = new InterceptorFilter(); }
Example 8
Source File: GenericDaoBase.java From cosmic with Apache License 2.0 | 4 votes |
protected GenericDaoBase() { super(); final Type t = getClass().getGenericSuperclass(); if (t instanceof ParameterizedType) { _entityBeanType = (Class<T>) ((ParameterizedType) t).getActualTypeArguments()[0]; } else if (((Class<?>) t).getGenericSuperclass() instanceof ParameterizedType) { _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) t).getGenericSuperclass()).getActualTypeArguments()[0]; } else { _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) ((Class<?>) t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0]; } s_daoMaps.put(_entityBeanType.getCanonicalName(), this); final Class<?>[] interfaceClasses = _entityBeanType.getInterfaces(); if (interfaceClasses != null) { for (final Class<?> interfaceClass : interfaceClasses) { s_daoMaps.put(interfaceClass.getCanonicalName(), this); } } logDetectedDaos(); _table = DbUtil.getTableName(_entityBeanType); final SqlGenerator generator = new SqlGenerator(_entityBeanType); _partialSelectSql = generator.buildSelectSql(false); _count = generator.buildCountSql(); _distinctIdSql = generator.buildDistinctIdSql(); _partialQueryCacheSelectSql = generator.buildSelectSql(true); _embeddedFields = generator.getEmbeddedFields(); _insertSqls = generator.buildInsertSqls(); final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause(); _discriminatorClause = dc.first().length() == 0 ? null : dc.first(); _discriminatorValues = dc.second(); _idAttributes = generator.getIdAttributes(); _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null; _tables = generator.buildTableReferences(); _allAttributes = generator.getAllAttributes(); _allColumns = generator.getAllColumns(); _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true)); _removeSql = generator.buildRemoveSql(); _deleteSqls = generator.buildDeleteSqls(); _removed = generator.getRemovedAttribute(); _tgs = generator.getTableGenerators(); _ecAttributes = generator.getElementCollectionAttributes(); TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class); if (tg != null) { _tgs.put(tg.name(), tg); } tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class); if (tg != null) { _tgs.put(tg.name(), tg); } final Callback[] callbacks = new Callback[]{NoOp.INSTANCE, new UpdateBuilder(this)}; _enhancer = new Enhancer(); _enhancer.setSuperclass(_entityBeanType); _enhancer.setCallbackFilter(s_callbackFilter); _enhancer.setCallbacks(callbacks); _factory = (Factory) _enhancer.create(); _searchEnhancer = new Enhancer(); _searchEnhancer.setSuperclass(_entityBeanType); _searchEnhancer.setCallback(new UpdateBuilder(this)); if (s_logger.isTraceEnabled()) { s_logger.trace("Select SQL: " + _partialSelectSql.first().toString()); s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); s_logger.trace("Select by Id SQL: " + _selectByIdSql); s_logger.trace("Table References: " + _tables); s_logger.trace("Insert SQLs:"); for (final Pair<String, Attribute[]> insertSql : _insertSqls) { s_logger.trace(insertSql.first()); } s_logger.trace("Delete SQLs"); for (final Pair<String, Attribute[]> deletSql : _deleteSqls) { s_logger.trace(deletSql.first()); } s_logger.trace("Collection SQLs"); for (final Attribute attr : _ecAttributes) { final EcInfo info = (EcInfo) attr.attache; s_logger.trace(info.insertSql); s_logger.trace(info.selectSql); } } setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM); }
Example 9
Source File: GenericDaoBase.java From cloudstack with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") protected GenericDaoBase() { super(); Type t = getClass().getGenericSuperclass(); if (t instanceof ParameterizedType) { _entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0]; } else if (((Class<?>)t).getGenericSuperclass() instanceof ParameterizedType) { _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)t).getGenericSuperclass()).getActualTypeArguments()[0]; } else { _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)((Class<?>)t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0]; } s_daoMaps.put(_entityBeanType, this); Class<?>[] interphaces = _entityBeanType.getInterfaces(); if (interphaces != null) { for (Class<?> interphace : interphaces) { s_daoMaps.put(interphace, this); } } _table = DbUtil.getTableName(_entityBeanType); final SqlGenerator generator = new SqlGenerator(_entityBeanType); _partialSelectSql = generator.buildSelectSql(false); _count = generator.buildCountSql(); _distinctIdSql= generator.buildDistinctIdSql(); _partialQueryCacheSelectSql = generator.buildSelectSql(true); _embeddedFields = generator.getEmbeddedFields(); _insertSqls = generator.buildInsertSqls(); final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause(); _discriminatorClause = dc.first().length() == 0 ? null : dc.first(); _discriminatorValues = dc.second(); _idAttributes = generator.getIdAttributes(); _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null; _tables = generator.buildTableReferences(); _allAttributes = generator.getAllAttributes(); _allColumns = generator.getAllColumns(); _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true)); _removeSql = generator.buildRemoveSql(); _deleteSqls = generator.buildDeleteSqls(); _removed = generator.getRemovedAttribute(); _tgs = generator.getTableGenerators(); _ecAttributes = generator.getElementCollectionAttributes(); TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class); if (tg != null) { _tgs.put(tg.name(), tg); } tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class); if (tg != null) { _tgs.put(tg.name(), tg); } Callback[] callbacks = new Callback[] {NoOp.INSTANCE, new UpdateBuilder(this)}; _enhancer = new Enhancer(); _enhancer.setSuperclass(_entityBeanType); _enhancer.setCallbackFilter(s_callbackFilter); _enhancer.setCallbacks(callbacks); _factory = (Factory)_enhancer.create(); _searchEnhancer = new Enhancer(); _searchEnhancer.setSuperclass(_entityBeanType); _searchEnhancer.setCallback(new UpdateBuilder(this)); if (s_logger.isTraceEnabled()) { s_logger.trace("Select SQL: " + _partialSelectSql.first().toString()); s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); s_logger.trace("Select by Id SQL: " + _selectByIdSql); s_logger.trace("Table References: " + _tables); s_logger.trace("Insert SQLs:"); for (final Pair<String, Attribute[]> insertSql : _insertSqls) { s_logger.trace(insertSql.first()); } s_logger.trace("Delete SQLs"); for (final Pair<String, Attribute[]> deletSql : _deleteSqls) { s_logger.trace(deletSql.first()); } s_logger.trace("Collection SQLs"); for (Attribute attr : _ecAttributes) { EcInfo info = (EcInfo)attr.attache; s_logger.trace(info.insertSql); s_logger.trace(info.selectSql); } } setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM); }