[JBossCache] - PojoCache, Serializable object and cluster
by jacek187
Question: should be changes made in simple serializable objects propagatet when using PojoCache?
Why in prestented code testPojo fails with error:
junit.framework.AssertionFailedError: expected:<2> but was:<1>
and testTreeCache success?
| package org.jboss.cache.aop;
|
| import java.util.Properties;
|
| import javax.naming.Context;
|
| import junit.framework.TestCase;
|
| import org.jboss.cache.CacheException;
| import org.jboss.cache.PropertyConfigurator;
|
| public class PojoCacheSerializableTest extends TestCase {
| PojoCache cache_;
|
| PojoCache cache1_;
|
| public PojoCacheSerializableTest(String name) {
| super(name);
| }
|
| protected void setUp() throws Exception {
| super.setUp();
| Properties prop = new Properties();
| prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
| cache_ = new PojoCache();
| PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
| config.configure(cache_, "META-INF/replSync-service.xml");
|
| cache1_ = new PojoCache();
| config.configure(cache1_, "META-INF/replSync-service.xml");
| cache_.start();
| cache1_.start();
| }
|
| protected void tearDown() throws Exception {
| super.tearDown();
| cache_.stop();
| cache1_.stop();
| }
|
| public void testPojo() throws CacheException {
| SimplePojo simplePojo = new SimplePojo();
| simplePojo.setStatus(1);
| cache_.putObject("a/b/c/d", simplePojo);
|
| SimplePojo simplePojo2 = (SimplePojo) cache1_.getObject("a/b/c/d");
| simplePojo2.setStatus(2);
| cache1_.putObject("a/b/c/d", simplePojo2);
|
| SimplePojo simplePojo3 = (SimplePojo) cache_.getObject("a/b/c/d");
| assertEquals(2, simplePojo3.getStatus());
| }
|
| public void testTreeCache() throws CacheException {
| SimplePojo simplePojo = new SimplePojo();
| simplePojo.setStatus(1);
| cache_.put("a/b/c/d", "key", simplePojo);
|
| SimplePojo simplePojo1 = (SimplePojo) cache1_.get("a/b/c/d", "key");
| simplePojo1.setStatus(2);
| cache1_.put("a/b/c/d", "key", simplePojo1);
|
| SimplePojo simplePojo2 = (SimplePojo) cache_.get("a/b/c/d", "key");
| assertEquals(2, simplePojo2.getStatus());
| }
| }
|
|
SimplePojo
| package org.jboss.cache.aop;
|
| import java.io.Serializable;
|
| import org.jboss.cache.aop.annotation.InstanceOfPojoCacheable;
| public class SimplePojo implements Serializable{
| private int status;
| public int getStatus() {
| return status;
| }
| public void setStatus(int status) {
| this.status = status;
| }
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029760#4029760
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029760
19Â years, 1Â month
[JBoss Seam] - Re: How to Inject app properties to bean transient method
by sherkan777
"petemuir" wrote : <h:column>
| | <h:outputText value="#{messages['sex.youngMane']}" rendered="#{entity.sex and entity.howOld eq 20}" />
| | </h:column>
Isn't better to get string directly from method?
Maybe u not understod my think.
I have field like int in each entity bean and collection of those beans.
and iterating my collection on page i want to get from application resources some string, dependent of my int flag.
like
| public int getAge() {
| ....
| }
|
| @Transient
| public String getName() {
| int age = getAge();
| String tempString = "";
| switch(age) {
| case(1) :
| tempString = messages.("age.veryYoung");
| break;
| case(2) :
| tempString = messages.("age.twoYearsOld");
| break;
| }
| return tempString;
| }
|
| |
| |
| | and in <h:dataTable
| |
| | | <h:column>
| | | <h:outputText value="currentBean.name" />
| | | </h:column>
| | |
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029752#4029752
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029752
19Â years, 1Â month
[EJB 3.0] - CMP Entity and foreign keys
by kstrunk
Hi,
I'm just wondering how JBoss handles foreign key constraints. I have an entity with a OneToOne-Mapping and CascaseType.ALL set, but in the database schema no cascade delete is set.
Here's a code fragement:
| @Entity
| @Table(name = "Users")
| public class User implements Serializable {
| private int id;
|
| private ChatInfo chatInfo;
|
| @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, optional = false)
| public ChatInfo getChatInfo() {
| return chatInfo;
| }
|
| public void setChatInfo(ChatInfo chatInfo) {
| this.chatInfo = chatInfo;
| }
| }
|
| @Entity
| @Table(name = "ChatInfo")
| public class ChatInfo implements Serializable {
| private int id;
|
| @Id
| @GeneratedValue(strategy = GenerationType.IDENTITY)
| @JoinColumn(name = "id", referencedColumnName = "chatinfo_id", table = "users", updatable = false, nullable = false)
| public int getId() {
| return id;
| }
|
| protected void setId(int id) {
| this.id = id;
| }
|
| }
|
When I look on the database schema there I see "ON DELETE NO ACTION" at the foreign key constraint, but I had expected "ON DELETE CASCADE". Can anybode explain this?
| CREATE TABLE users
| (
| id int4 NOT NULL DEFAULT nextval('users_id_seq'::regclass),
| chatinfo_id int4 NOT NULL,
| CONSTRAINT users_pkey PRIMARY KEY (id),
| CONSTRAINT fk4e39de8d7cb3bff FOREIGN KEY (chatinfo_id)
| REFERENCES chatinfo (id) MATCH SIMPLE
| ON UPDATE NO ACTION ON DELETE NO ACTION,
| )
|
I use JBoss 4.0.5 and a Postgres 8.1 database.
Best regards,
Strunker
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029750#4029750
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029750
19Â years, 1Â month