How can I setup NHibernate Validator with Spring.net as IoC?
I am already using Spring.net integration with NHibernate and can't get AutoRegisterListeners to work.
What I need is to setup NHV to validate entities automatically upon Update/Save instead of having to call Validate method every time and use Spring.net with ISharedEngineProvider to make sure optimal performance.
After looking around a lot I found this one: http://forum.springframework.net/showthread.php?t=5286
I'm repeating it here for others to find it easier that I did!:
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate20">
<!-- the usual properties ... -->
<!-- event listeners -->
<property name="EventListeners">
<dictionary>
<entry key="PreUpdate">
<object type="NHibernate.Validator.Event.ValidatePreUpdateEventListener, NHibernate.Validator" />
</entry>
<entry key="PreInsert">
<object type="NHibernate.Validator.Event.ValidatePreInsertEventListener, NHibernate.Validator" />
</entry>
</dictionary>
</property> </object>
Related
I would like to know if it is possible to push property in the cache hazelcast.
I work with a distributed environment and would like properties to be shared across all environments. Is it possible?
My current configuration for loading properties is as follows:
<bean id="propertiesConfigurer" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="systemPropertiesMode" value="2"/>
<property name="properties" ref="allProperties" />
</bean>
Thank you
You can simply use the distributed data structures of Hazelcast (i.e. IMap) and put any data you want as long as you make them serializable.
Yes, you can create a distributed map with entries as <String, Properties>. Each entry will keep a set of properties. Or, you can create a simple distributed map with entries as <String, String> and use this map as a set of properties.
I have the following context configuration:
<bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:conf.properties</value>
</list>
</property>
</bean>
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="properties" ref="propertiesFactory"/>
</bean>
<bean id="messageThrottlerHolder" class="foo.bar.common.MessageThrottlerHolder"/>
<bean id="cassandraRoute" class="foo.bar.routes.CassandraRouteBuilder"/>
Then in both classes: MessageThrottlerHolder and in CassandraRouteBuilder there is:
#BeanInject
Properties properties;
Wonderful.
But CassandraRouteBuilder may/could use properties without NPE, as properties are well initialized.
On the other hand the MessageThrottlerHolder is not able to use properties as in the constructor properties are null and there is no way to initialize them.
How can I check why properties are null?
What can be wrong, that #BeanInject somehow does not initialize properties?
You are doing this wrong if you think that Properties are somehow Camel property placeholder or anything like that.
Camel's #BeanInject is for looking up bean in the Camel register via a bean name/id, as a poor-mans Spring IoC. If you are using Spring then you can use the Spring #Autowired or whatever they have for that.
If you want to access properties from the properties placeholder, then you can inject CamelContext and use its API for resolving: http://static.javadoc.io/org.apache.camel/camel-core/2.20.0/org/apache/camel/CamelContext.html#resolvePropertyPlaceholders-java.lang.String-
Or use Camel's #PropertyInject instead where you specify the key name to lookup. I am not sure if Spring has any similar annotation for looking up properties, as you have turned on the camel-spring bridge. You can also try to look into that.
I'm declaring a Broker via the amq:broker namespace, but I'm wondering if similar to a regular spring bean with abstract="true", is it possible to create an abstract Broker "parent" bean and have children which inherit it's properties and complete it?
<amq:broker id="parentBroker" brokerName="parentBroker" useJmx="true" persistent="true" advisorySupport="true" abstract="true">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:61636" />
</amq:transportConnectors>
</amq:broker>
<amq:broker id="childBroker" parent="parentBroker">
<amq:persistenceAdapter>
<amq:kahaDB directory="/somewhere/kahadb" journalMaxFileLength="32mb" />
</amq:persistenceAdapter>
</amq:broker>
I guess not, you'd just have to use regular Spring 's then?
How is it possible to register a component in Castle Windsor 3.0 with PerWcfOperation lifestyle? I could only find examples of registering components in code.
Here is my config:
<castle>
<facilities>
<facility id="wcf"
type="Castle.Facilities.WcfIntegration.WcfFacility, Castle.Facilities.WcfIntegration" />
</facilities>
<components>
<component id="Settings"
service="SomeNamespace.IApplicationSettings, SomeAssembly"
type="SomeOtherNamespace.ApplicationSettings, SomeOtherAssembly"
lifestyle="PerWcfOperation" />
</components>
</castle>
When I try to do it as in the config above, I get ConvertException 'Could not convert from 'PerWcfOperation' to Castle.Core.LifestyleType.'
It's not supported because XML configuration is considered legacy.
Use configuration in code instead.
XML and code are generally mostly equivalent (where that's possible) although this case is an exception - there's currently no way out of the box to specify scoped lifestyle (and that is what per-wcf-operation lifestyle is) in XML.
Obviously that doesn't mean there's no way to get this working. With a simple IContributeComponentModelConstruction you can implement support for that in a few LOC.
I am trying to parse response from an OData REST service. When response is in JSON format, it is easy to use ReadAsJsonDataContract method from WCF REST starter kit. However things seem to be more complicated in case the response is an Atom feed. This is an example:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<entry xml:base="http://localhost:64172/BookshopService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<id>http://localhost:64172/BookshopService.svc/Books(89)</id>
<title type="text"></title>
<updated>2010-11-08T09:44:21Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Books" href="Books(89)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/OrderLines" type="application/atom+xml;type=feed" title="OrderLines" href="Books(89)/OrderLines" />
<category term="BookshopModel.Books" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">89</d:Id>
<d:Author>Martin Fowler</d:Author>
<d:Title>Analysis Patterns</d:Title>
<d:Price m:type="Edm.Decimal">50.20</d:Price>
</m:properties>
</content>
</entry>
So the actual object is serialized in "content/m:properties" element. And of course this can't be handled by DataContractSerializer that expects a different schema.
Does anyone know what technique can be used to deserialize the content of OData atom m:properties element?
WCF Data Services has a client which can be used to consume the responses and materialize CLR object from those. Take a look at the System.Data.Services.Client.DataServiceContext class and all related classes.
In fact, in VS you can "Add Service Reference" to your OData services and it will generate client-side classes for the services as well as a derived class from the DataServiceContext for you to use.
If you already have the client side classes you can use the DataServiceContext.Execute<T> method to issue any query and materialize its results into the client side types.