Change license to Apache2 and reformat

This commit is contained in:
rbygrave
2012-09-15 00:00:08 +12:00
parent 96ce4c0ddf
commit 7aae897def
560 changed files with 73292 additions and 85907 deletions
@@ -1,71 +1,52 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.ebean.server.type;
import java.sql.Types;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.H2Platform;
import com.avaje.ebeaninternal.server.core.BootupClasses;
import com.avaje.ebeaninternal.server.type.CtCompoundType;
import com.avaje.ebeaninternal.server.type.DefaultTypeManager;
import com.avaje.ebeaninternal.server.type.ScalarDataReader;
import com.avaje.ebeaninternal.server.type.ScalarType;
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
import com.avaje.tests.model.ivo.CMoney;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Money;
public class TestTypeManager extends TestCase {
public void test() {
ServerConfig serverConfig = new ServerConfig();
serverConfig.setDatabasePlatform(new H2Platform());
BootupClasses bootupClasses = new BootupClasses();
DefaultTypeManager typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
CheckImmutableResponse checkImmutable = typeManager.checkImmutable(Money.class);
Assert.assertTrue(checkImmutable.isImmutable());
checkImmutable = typeManager.checkImmutable(CMoney.class);
Assert.assertTrue(checkImmutable.isImmutable());
ScalarDataReader<?> dataReader = typeManager.recursiveCreateScalarDataReader(ExhangeCMoneyRate.class);
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
dataReader = typeManager.recursiveCreateScalarDataReader(CMoney.class);
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(Money.class);
Assert.assertTrue(scalarType.getJdbcType() == Types.DECIMAL);
Assert.assertTrue(!scalarType.isJdbcNative());
Assert.assertEquals(Money.class, scalarType.getType());
}
}
package com.avaje.ebean.server.type;
import java.sql.Types;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.H2Platform;
import com.avaje.ebeaninternal.server.core.BootupClasses;
import com.avaje.ebeaninternal.server.type.CtCompoundType;
import com.avaje.ebeaninternal.server.type.DefaultTypeManager;
import com.avaje.ebeaninternal.server.type.ScalarDataReader;
import com.avaje.ebeaninternal.server.type.ScalarType;
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
import com.avaje.tests.model.ivo.CMoney;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Money;
public class TestTypeManager extends TestCase {
public void test() {
ServerConfig serverConfig = new ServerConfig();
serverConfig.setDatabasePlatform(new H2Platform());
BootupClasses bootupClasses = new BootupClasses();
DefaultTypeManager typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
CheckImmutableResponse checkImmutable = typeManager.checkImmutable(Money.class);
Assert.assertTrue(checkImmutable.isImmutable());
checkImmutable = typeManager.checkImmutable(CMoney.class);
Assert.assertTrue(checkImmutable.isImmutable());
ScalarDataReader<?> dataReader = typeManager.recursiveCreateScalarDataReader(ExhangeCMoneyRate.class);
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
dataReader = typeManager.recursiveCreateScalarDataReader(CMoney.class);
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(Money.class);
Assert.assertTrue(scalarType.getJdbcType() == Types.DECIMAL);
Assert.assertTrue(!scalarType.isJdbcNative());
Assert.assertEquals(Money.class, scalarType.getType());
}
}
@@ -1,38 +1,19 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.basic.encrypt;
import com.avaje.ebean.config.EncryptKey;
public class BasicEncryptKey implements EncryptKey {
private final String key;
public BasicEncryptKey(String key) {
this.key = key;
}
public String getStringValue() {
return key;
}
}
package com.avaje.tests.basic.encrypt;
import com.avaje.ebean.config.EncryptKey;
public class BasicEncryptKey implements EncryptKey {
private final String key;
public BasicEncryptKey(String key) {
this.key = key;
}
public String getStringValue() {
return key;
}
}
@@ -1,59 +1,40 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.el;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.model.basic.Address;
import com.avaje.tests.model.basic.Customer;
public class TestElGetReference extends TestCase {
public void test() {
Address a = new Address();
a.setId((short)12);
a.setLine1("line1");
a.setCity("Auckland");
Customer c0 = new Customer();
c0.setBillingAddress(a);
Customer c1 = new Customer();
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
ElPropertyValue elProp = descriptor.getElGetValue("billingAddress.id");
ElPropertyValue addrLine1Prop = descriptor.getElGetValue("billingAddress.line1");
ElPropertyValue addrCityProp = descriptor.getElGetValue("billingAddress.city");
elProp.elGetReference(c0);
elProp.elGetReference(c1);
addrLine1Prop.elSetValue(c1, "12 someplace", true, false);
addrCityProp.elSetValue(c1, "Auckland", true, false);
}
}
package com.avaje.tests.el;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.model.basic.Address;
import com.avaje.tests.model.basic.Customer;
public class TestElGetReference extends TestCase {
public void test() {
Address a = new Address();
a.setId((short)12);
a.setLine1("line1");
a.setCity("Auckland");
Customer c0 = new Customer();
c0.setBillingAddress(a);
Customer c1 = new Customer();
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
ElPropertyValue elProp = descriptor.getElGetValue("billingAddress.id");
ElPropertyValue addrLine1Prop = descriptor.getElGetValue("billingAddress.line1");
ElPropertyValue addrCityProp = descriptor.getElGetValue("billingAddress.city");
elProp.elGetReference(c0);
elProp.elGetReference(c1);
addrLine1Prop.elSetValue(c1, "12 someplace", true, false);
addrCityProp.elSetValue(c1, "Auckland", true, false);
}
}
@@ -1,54 +1,35 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public abstract class BaseLdapTest extends TestCase {
public void one() {
Assert.assertTrue(true);
}
protected EbeanServer createServer() {
LdapContextFactory contextFactory = new MockContextFactory();
ServerConfig config = new ServerConfig();
config.setName("h2");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
return EbeanServerFactory.create(config);
}
}
package com.avaje.tests.ldap;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public abstract class BaseLdapTest extends TestCase {
public void one() {
Assert.assertTrue(true);
}
protected EbeanServer createServer() {
LdapContextFactory contextFactory = new MockContextFactory();
ServerConfig config = new ServerConfig();
config.setName("h2");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
return EbeanServerFactory.create(config);
}
}
@@ -1,33 +1,14 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import javax.naming.directory.DirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class MockContextFactory implements LdapContextFactory {
public DirContext createContext() {
return new MockDirContext();
}
}
package com.avaje.tests.ldap;
import javax.naming.directory.DirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class MockContextFactory implements LdapContextFactory {
public DirContext createContext() {
return new MockDirContext();
}
}
@@ -1,267 +1,248 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class MockDirContext implements DirContext {
public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void bind(String name, Object obj, Attributes attrs) throws NamingException {
}
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
return null;
}
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
return null;
}
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
BasicAttributes a = new BasicAttributes();
a.put("uid", "rbygraveTest01");
return a;
}
public Attributes getAttributes(Name name) throws NamingException {
return null;
}
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
return null;
}
public Attributes getAttributes(String name) throws NamingException {
return null;
}
public DirContext getSchema(Name name) throws NamingException {
return null;
}
public DirContext getSchema(String name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(Name name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(String name) throws NamingException {
return null;
}
public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
}
public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
}
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
String[] attributesToReturn) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs,
SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons)
throws NamingException {
return null;
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
return null;
}
public void bind(Name name, Object obj) throws NamingException {
}
public void bind(String name, Object obj) throws NamingException {
}
public void close() throws NamingException {
}
public Name composeName(Name name, Name prefix) throws NamingException {
return null;
}
public String composeName(String name, String prefix) throws NamingException {
return null;
}
public Context createSubcontext(Name name) throws NamingException {
return null;
}
public Context createSubcontext(String name) throws NamingException {
return null;
}
public void destroySubcontext(Name name) throws NamingException {
}
public void destroySubcontext(String name) throws NamingException {
}
public Hashtable<?, ?> getEnvironment() throws NamingException {
return null;
}
public String getNameInNamespace() throws NamingException {
return null;
}
public NameParser getNameParser(Name name) throws NamingException {
return null;
}
public NameParser getNameParser(String name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
return null;
}
public Object lookup(Name name) throws NamingException {
return null;
}
public Object lookup(String name) throws NamingException {
return null;
}
public Object lookupLink(Name name) throws NamingException {
return null;
}
public Object lookupLink(String name) throws NamingException {
return null;
}
public void rebind(Name name, Object obj) throws NamingException {
}
public void rebind(String name, Object obj) throws NamingException {
}
public Object removeFromEnvironment(String propName) throws NamingException {
return null;
}
public void rename(Name oldName, Name newName) throws NamingException {
}
public void rename(String oldName, String newName) throws NamingException {
}
public void unbind(Name name) throws NamingException {
}
public void unbind(String name) throws NamingException {
}
}
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class MockDirContext implements DirContext {
public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void bind(String name, Object obj, Attributes attrs) throws NamingException {
}
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
return null;
}
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
return null;
}
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
BasicAttributes a = new BasicAttributes();
a.put("uid", "rbygraveTest01");
return a;
}
public Attributes getAttributes(Name name) throws NamingException {
return null;
}
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
return null;
}
public Attributes getAttributes(String name) throws NamingException {
return null;
}
public DirContext getSchema(Name name) throws NamingException {
return null;
}
public DirContext getSchema(String name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(Name name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(String name) throws NamingException {
return null;
}
public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
}
public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
}
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
String[] attributesToReturn) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs,
SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons)
throws NamingException {
return null;
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
return null;
}
public void bind(Name name, Object obj) throws NamingException {
}
public void bind(String name, Object obj) throws NamingException {
}
public void close() throws NamingException {
}
public Name composeName(Name name, Name prefix) throws NamingException {
return null;
}
public String composeName(String name, String prefix) throws NamingException {
return null;
}
public Context createSubcontext(Name name) throws NamingException {
return null;
}
public Context createSubcontext(String name) throws NamingException {
return null;
}
public void destroySubcontext(Name name) throws NamingException {
}
public void destroySubcontext(String name) throws NamingException {
}
public Hashtable<?, ?> getEnvironment() throws NamingException {
return null;
}
public String getNameInNamespace() throws NamingException {
return null;
}
public NameParser getNameParser(Name name) throws NamingException {
return null;
}
public NameParser getNameParser(String name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
return null;
}
public Object lookup(Name name) throws NamingException {
return null;
}
public Object lookup(String name) throws NamingException {
return null;
}
public Object lookupLink(Name name) throws NamingException {
return null;
}
public Object lookupLink(String name) throws NamingException {
return null;
}
public void rebind(Name name, Object obj) throws NamingException {
}
public void rebind(String name, Object obj) throws NamingException {
}
public Object removeFromEnvironment(String propName) throws NamingException {
return null;
}
public void rename(Name oldName, Name newName) throws NamingException {
}
public void rename(String oldName, String newName) throws NamingException {
}
public void unbind(Name name) throws NamingException {
}
public void unbind(String name) throws NamingException {
}
}
@@ -1,60 +1,41 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class SimpleContextFactory implements LdapContextFactory {
String url;
String principal;
String credentials;
public SimpleContextFactory(String url, String principal, String credentials) {
this.url = url;
this.principal = principal;
this.credentials = credentials;
}
public DirContext createContext() {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS, credentials);
try {
return new InitialDirContext(env);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
}
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class SimpleContextFactory implements LdapContextFactory {
String url;
String principal;
String credentials;
public SimpleContextFactory(String url, String principal, String credentials) {
this.url = url;
this.principal = principal;
this.credentials = credentials;
}
public DirContext createContext() {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS, credentials);
try {
return new InitialDirContext(env);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
}
@@ -1,62 +1,43 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import com.avaje.ebean.config.ldap.LdapAttributeAdapter;
public class SimpleLdapSetAdapater implements LdapAttributeAdapter {
@SuppressWarnings("unchecked")
public Attribute createAttribute(Object beanPropertyValue) {
Set<Long> set = (Set<Long>)beanPropertyValue;
BasicAttribute attr = new BasicAttribute("accounts");
for (Long accVal : set) {
attr.add("acct="+accVal);
}
return attr;
}
public Object readAttribute(Attribute attribute) throws NamingException {
HashSet<Long> set = new HashSet<Long>();
NamingEnumeration<?> all = attribute.getAll();
while (all.hasMoreElements()) {
String s = (String)all.nextElement();
// just trim off the first 5 characters
s = s.substring(5);
set.add(new Long(s));
}
return set;
}
}
package com.avaje.tests.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import com.avaje.ebean.config.ldap.LdapAttributeAdapter;
public class SimpleLdapSetAdapater implements LdapAttributeAdapter {
@SuppressWarnings("unchecked")
public Attribute createAttribute(Object beanPropertyValue) {
Set<Long> set = (Set<Long>)beanPropertyValue;
BasicAttribute attr = new BasicAttribute("accounts");
for (Long accVal : set) {
attr.add("acct="+accVal);
}
return attr;
}
public Object readAttribute(Attribute attribute) throws NamingException {
HashSet<Long> set = new HashSet<Long>();
NamingEnumeration<?> all = attribute.getAll();
while (all.hasMoreElements()) {
String s = (String)all.nextElement();
// just trim off the first 5 characters
s = s.substring(5);
set.add(new Long(s));
}
return set;
}
}
@@ -1,94 +1,75 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import java.util.List;
import javax.naming.NamingException;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
import com.avaje.tests.model.ldap.LDPerson;
import com.avaje.tests.model.ldap.LDPerson.Status;
public class TestLdapQuery extends TestCase {
public void test() throws NamingException {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
// GlobalProperties.put("ebean.ldapContextFactory", MockContextFactory.class.getName());
ServerConfig config = new ServerConfig();
config.setName("ldap");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
// // built automatically from ebean.ldapContextFactory
// LdapContextFactory ldapContextFactory = config.getLdapConfig().getContextFactory();
// Assert.assertNotNull(ldapContextFactory);
LdapContextFactory contextFactory = new MockContextFactory();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
config.getDataSourceConfig().setOffline(true);
config.setDatabasePlatformName("oracle");
EbeanServer server = EbeanServerFactory.create(config);
LDPerson pRob = server.find(LDPerson.class)
.select("userId, cn")
.setId("rbygraveTest01")
.findUnique();
Assert.assertNotNull(pRob);
List<LDPerson> list = server.find(LDPerson.class)
.select("userId,status")
.where().like("userId","lz*").eq("status", LDPerson.Status.ACTIVE)
.findList();
System.out.println(list);
LDPerson p = new LDPerson();
p.setUserId("rbygraveTest01");
p.setStatus(Status.ACTIVE);
p.setCn("Test01");
p.setSn("Testing123");
p.setGivenName("Ban Dana");
p.setUserPassword("qwerty");
server.save(p);
}
}
package com.avaje.tests.ldap;
import java.util.List;
import javax.naming.NamingException;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
import com.avaje.tests.model.ldap.LDPerson;
import com.avaje.tests.model.ldap.LDPerson.Status;
public class TestLdapQuery extends TestCase {
public void test() throws NamingException {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
// GlobalProperties.put("ebean.ldapContextFactory", MockContextFactory.class.getName());
ServerConfig config = new ServerConfig();
config.setName("ldap");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
// // built automatically from ebean.ldapContextFactory
// LdapContextFactory ldapContextFactory = config.getLdapConfig().getContextFactory();
// Assert.assertNotNull(ldapContextFactory);
LdapContextFactory contextFactory = new MockContextFactory();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
config.getDataSourceConfig().setOffline(true);
config.setDatabasePlatformName("oracle");
EbeanServer server = EbeanServerFactory.create(config);
LDPerson pRob = server.find(LDPerson.class)
.select("userId, cn")
.setId("rbygraveTest01")
.findUnique();
Assert.assertNotNull(pRob);
List<LDPerson> list = server.find(LDPerson.class)
.select("userId,status")
.where().like("userId","lz*").eq("status", LDPerson.Status.ACTIVE)
.findList();
System.out.println(list);
LDPerson p = new LDPerson();
p.setUserId("rbygraveTest01");
p.setStatus(Status.ACTIVE);
p.setCn("Test01");
p.setSn("Testing123");
p.setGivenName("Ban Dana");
p.setUserPassword("qwerty");
server.save(p);
}
}
@@ -1,72 +1,53 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.ldap;
import java.util.Arrays;
import junit.framework.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Query;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.ldap.LdapOrmQueryRequest;
import com.avaje.ebeaninternal.server.ldap.LdapQueryDeployHelper;
import com.avaje.tests.model.ldap.LDPerson;
public class TestLdapQueryParse extends BaseLdapTest{
public void test() {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
EbeanServer server = createServer();
Query<LDPerson> query = server.createQuery(LDPerson.class);
query.select("uid, cn, status");
query.where("(cn=rob*)");
query.where()
.raw("(inetUserStatus=Banana)")
.eq("status", LDPerson.Status.ACTIVE)
.eq("sn", "bana");
SpiQuery<LDPerson> sq = (SpiQuery<LDPerson>)query;
SpiEbeanServer spiServer = (SpiEbeanServer)server;
BeanDescriptor<LDPerson> desc = spiServer.getBeanDescriptor(LDPerson.class);
LdapOrmQueryRequest<LDPerson> req = new LdapOrmQueryRequest<LDPerson>(sq, desc, null);
LdapQueryDeployHelper deployHelper = new LdapQueryDeployHelper(req);
String[] sp = deployHelper.getSelectedProperties();
String filterExpr = deployHelper.getFilterExpr();
Object[] filterVals = deployHelper.getFilterValues();
System.out.println("filterExpr: "+filterExpr);
System.out.println("filterVals: "+Arrays.toString(filterVals));
Assert.assertNotNull(sp);
}
}
package com.avaje.tests.ldap;
import java.util.Arrays;
import junit.framework.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Query;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.ldap.LdapOrmQueryRequest;
import com.avaje.ebeaninternal.server.ldap.LdapQueryDeployHelper;
import com.avaje.tests.model.ldap.LDPerson;
public class TestLdapQueryParse extends BaseLdapTest{
public void test() {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
EbeanServer server = createServer();
Query<LDPerson> query = server.createQuery(LDPerson.class);
query.select("uid, cn, status");
query.where("(cn=rob*)");
query.where()
.raw("(inetUserStatus=Banana)")
.eq("status", LDPerson.Status.ACTIVE)
.eq("sn", "bana");
SpiQuery<LDPerson> sq = (SpiQuery<LDPerson>)query;
SpiEbeanServer spiServer = (SpiEbeanServer)server;
BeanDescriptor<LDPerson> desc = spiServer.getBeanDescriptor(LDPerson.class);
LdapOrmQueryRequest<LDPerson> req = new LdapOrmQueryRequest<LDPerson>(sq, desc, null);
LdapQueryDeployHelper deployHelper = new LdapQueryDeployHelper(req);
String[] sp = deployHelper.getSelectedProperties();
String filterExpr = deployHelper.getFilterExpr();
Object[] filterVals = deployHelper.getFilterValues();
System.out.println("filterExpr: "+filterExpr);
System.out.println("filterVals: "+Arrays.toString(filterVals));
Assert.assertNotNull(sp);
}
}
@@ -1,73 +1,54 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CKeyDetail {
@Id
Integer id;
String something;
@ManyToOne
// @JoinColumns({
// @JoinColumn(name="parent_one_key", referencedColumnName="one_key"),
// @JoinColumn(name="parent_two_key", referencedColumnName="two_key")
// })
CKeyParent parent;
public CKeyDetail(){
}
public CKeyDetail(String something){
this.something = something;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
public CKeyParent getParent() {
return parent;
}
public void setParent(CKeyParent parent) {
this.parent = parent;
}
}
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CKeyDetail {
@Id
Integer id;
String something;
@ManyToOne
// @JoinColumns({
// @JoinColumn(name="parent_one_key", referencedColumnName="one_key"),
// @JoinColumn(name="parent_two_key", referencedColumnName="two_key")
// })
CKeyParent parent;
public CKeyDetail(){
}
public CKeyDetail(String something){
this.something = something;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
public CKeyParent getParent() {
return parent;
}
public void setParent(CKeyParent parent) {
this.parent = parent;
}
}
@@ -1,96 +1,77 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
@Entity
public class CKeyParent {
@EmbeddedId
CKeyParentId id;
String name;
@Version
int version;
@ManyToOne(cascade=CascadeType.PERSIST)
CKeyAssoc assoc;
@OneToMany(cascade=CascadeType.PERSIST, mappedBy="parent")
List<CKeyDetail> details;
public CKeyParentId getId() {
return id;
}
public void setId(CKeyParentId id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public CKeyAssoc getAssoc() {
return assoc;
}
public void setAssoc(CKeyAssoc assoc) {
this.assoc = assoc;
}
public List<CKeyDetail> getDetails() {
return details;
}
public void setDetails(List<CKeyDetail> details) {
this.details = details;
}
public void add(CKeyDetail detail) {
if (details == null){
details = new ArrayList<CKeyDetail>();
}
details.add(detail);
}
}
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
@Entity
public class CKeyParent {
@EmbeddedId
CKeyParentId id;
String name;
@Version
int version;
@ManyToOne(cascade=CascadeType.PERSIST)
CKeyAssoc assoc;
@OneToMany(cascade=CascadeType.PERSIST, mappedBy="parent")
List<CKeyDetail> details;
public CKeyParentId getId() {
return id;
}
public void setId(CKeyParentId id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public CKeyAssoc getAssoc() {
return assoc;
}
public void setAssoc(CKeyAssoc assoc) {
this.assoc = assoc;
}
public List<CKeyDetail> getDetails() {
return details;
}
public void setDetails(List<CKeyDetail> details) {
this.details = details;
}
public void add(CKeyDetail detail) {
if (details == null){
details = new ArrayList<CKeyDetail>();
}
details.add(detail);
}
}
@@ -1,71 +1,52 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Embeddable;
@Embeddable
public class CKeyParentId {
Integer oneKey;
String twoKey;
public CKeyParentId() {
}
public CKeyParentId(Integer oneKey, String twoKey){
this.oneKey = oneKey;
this.twoKey = twoKey;
}
public Integer getOneKey() {
return oneKey;
}
public void setOneKey(Integer oneKey) {
this.oneKey = oneKey;
}
public String getTwoKey() {
return twoKey;
}
public void setTwoKey(String twoKey) {
this.twoKey = twoKey;
}
@Override
public boolean equals(Object o) {
if (this == o){
return true;
}
if (!(o instanceof CKeyParentId)){
return false;
}
CKeyParentId otherKey = (CKeyParentId) o;
return otherKey.hashCode() == hashCode();
}
@Override
public int hashCode(){
int hc = getClass().getName().hashCode();
hc = 31 * hc + oneKey;
hc = 31 * hc + twoKey.hashCode();
return hc;
}
}
package com.avaje.tests.model.basic;
import javax.persistence.Embeddable;
@Embeddable
public class CKeyParentId {
Integer oneKey;
String twoKey;
public CKeyParentId() {
}
public CKeyParentId(Integer oneKey, String twoKey){
this.oneKey = oneKey;
this.twoKey = twoKey;
}
public Integer getOneKey() {
return oneKey;
}
public void setOneKey(Integer oneKey) {
this.oneKey = oneKey;
}
public String getTwoKey() {
return twoKey;
}
public void setTwoKey(String twoKey) {
this.twoKey = twoKey;
}
@Override
public boolean equals(Object o) {
if (this == o){
return true;
}
if (!(o instanceof CKeyParentId)){
return false;
}
CKeyParentId otherKey = (CKeyParentId) o;
return otherKey.hashCode() == hashCode();
}
@Override
public int hashCode(){
int hc = getClass().getName().hashCode();
hc = 31 * hc + oneKey;
hc = 31 * hc + twoKey.hashCode();
return hc;
}
}
@@ -1,63 +1,44 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
@Entity
public class ContactNote extends BasicDomain {
private static final long serialVersionUID = 7949702621226333278L;
@ManyToOne
Contact contact;
String title;
@Lob
String note;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
@Entity
public class ContactNote extends BasicDomain {
private static final long serialVersionUID = 7949702621226333278L;
@ManyToOne
Contact contact;
String title;
@Lob
String note;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
@@ -1,51 +1,32 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.joda.time.LocalTime;
@Entity
public class TJodaEntity {
@Id
Integer id;
LocalTime localTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public LocalTime getLocalTime() {
return localTime;
}
public void setLocalTime(LocalTime localTime) {
this.localTime = localTime;
}
}
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.joda.time.LocalTime;
@Entity
public class TJodaEntity {
@Id
Integer id;
LocalTime localTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public LocalTime getLocalTime() {
return localTime;
}
public void setLocalTime(LocalTime localTime) {
this.localTime = localTime;
}
}
@@ -1,49 +1,30 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class TruckRef {
@Id
Integer id;
String something;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
}
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class TruckRef {
@Id
Integer id;
String something;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
}
@@ -1,66 +1,47 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ddd;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Oid;
@Entity
public class DExhEntity {
@Id
Oid<DExhEntity> oid;
ExhangeCMoneyRate exhange;
@Version
Timestamp lastUpdated;
public Oid<DExhEntity> getOid() {
return oid;
}
public void setOid(Oid<DExhEntity> oid) {
this.oid = oid;
}
public ExhangeCMoneyRate getExhange() {
return exhange;
}
public void setExhange(ExhangeCMoneyRate exhange) {
this.exhange = exhange;
}
public Timestamp getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated) {
this.lastUpdated = lastUpdated;
}
}
package com.avaje.tests.model.ddd;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Oid;
@Entity
public class DExhEntity {
@Id
Oid<DExhEntity> oid;
ExhangeCMoneyRate exhange;
@Version
Timestamp lastUpdated;
public Oid<DExhEntity> getOid() {
return oid;
}
public void setOid(Oid<DExhEntity> oid) {
this.oid = oid;
}
public ExhangeCMoneyRate getExhange() {
return exhange;
}
public void setExhange(ExhangeCMoneyRate exhange) {
this.exhange = exhange;
}
public Timestamp getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated) {
this.lastUpdated = lastUpdated;
}
}
@@ -1,49 +1,30 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ivo;
import com.avaje.ebeaninternal.server.type.reflect.KnownImmutable;
public class SimpleKnownImmutable implements KnownImmutable {
public boolean isKnownImmutable(Class<?> cls) {
// Check for all allowed property types...
if (cls.isPrimitive() || String.class.equals(cls) || Object.class.equals(cls)) {
return true;
}
if (java.util.Date.class.equals(cls) || java.sql.Date.class.equals(cls) || java.sql.Timestamp.class.equals(cls)) {
// treat as immutable even through they are not strictly so
return true;
}
if (java.math.BigDecimal.class.equals(cls) || java.math.BigInteger.class.equals(cls)) {
// treat as immutable (contain non-final fields)
return true;
}
if (Integer.class.equals(cls) || Long.class.equals(cls) || Double.class.equals(cls) || Float.class.equals(cls)
|| Short.class.equals(cls) || Byte.class.equals(cls) || Character.class.equals(cls)
|| Boolean.class.equals(cls)) {
return true;
}
return false;
}
}
package com.avaje.tests.model.ivo;
import com.avaje.ebeaninternal.server.type.reflect.KnownImmutable;
public class SimpleKnownImmutable implements KnownImmutable {
public boolean isKnownImmutable(Class<?> cls) {
// Check for all allowed property types...
if (cls.isPrimitive() || String.class.equals(cls) || Object.class.equals(cls)) {
return true;
}
if (java.util.Date.class.equals(cls) || java.sql.Date.class.equals(cls) || java.sql.Timestamp.class.equals(cls)) {
// treat as immutable even through they are not strictly so
return true;
}
if (java.math.BigDecimal.class.equals(cls) || java.math.BigInteger.class.equals(cls)) {
// treat as immutable (contain non-final fields)
return true;
}
if (Integer.class.equals(cls) || Long.class.equals(cls) || Double.class.equals(cls) || Float.class.equals(cls)
|| Short.class.equals(cls) || Byte.class.equals(cls) || Character.class.equals(cls)
|| Boolean.class.equals(cls)) {
return true;
}
return false;
}
}
@@ -1,34 +1,15 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ivo;
public class SysTime {
private final long millis;
public SysTime(long millis){
this.millis = millis;
}
public long getMillis() {
return millis;
}
}
package com.avaje.tests.model.ivo;
public class SysTime {
private final long millis;
public SysTime(long millis){
this.millis = millis;
}
public long getMillis() {
return millis;
}
}
@@ -1,73 +1,54 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ivo.converter;
import com.avaje.ebean.config.CompoundType;
import com.avaje.ebean.config.CompoundTypeProperty;
import com.avaje.tests.model.ivo.CMoney;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Rate;
public class ExhangeCompoundType implements CompoundType<ExhangeCMoneyRate> {
public ExhangeCMoneyRate create(Object[] propertyValues) {
return new ExhangeCMoneyRate((Rate)propertyValues[0], (CMoney)propertyValues[1]);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public CompoundTypeProperty<ExhangeCMoneyRate, ?>[] getProperties() {
CompoundTypeProperty[] props = {new RateProp(), new CMoneyProp()};
return props;
}
static class RateProp implements CompoundTypeProperty<ExhangeCMoneyRate, Rate> {
public String getName() {
return "rate";
}
public Rate getValue(ExhangeCMoneyRate valueObject) {
return valueObject.getRate();
}
public int getDbType() {
return 0;
}
}
static class CMoneyProp implements CompoundTypeProperty<ExhangeCMoneyRate, CMoney> {
public String getName() {
return "cmoney";
}
public CMoney getValue(ExhangeCMoneyRate valueObject) {
return valueObject.getCmoney();
}
public int getDbType() {
return 0;
}
}
}
package com.avaje.tests.model.ivo.converter;
import com.avaje.ebean.config.CompoundType;
import com.avaje.ebean.config.CompoundTypeProperty;
import com.avaje.tests.model.ivo.CMoney;
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
import com.avaje.tests.model.ivo.Rate;
public class ExhangeCompoundType implements CompoundType<ExhangeCMoneyRate> {
public ExhangeCMoneyRate create(Object[] propertyValues) {
return new ExhangeCMoneyRate((Rate)propertyValues[0], (CMoney)propertyValues[1]);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public CompoundTypeProperty<ExhangeCMoneyRate, ?>[] getProperties() {
CompoundTypeProperty[] props = {new RateProp(), new CMoneyProp()};
return props;
}
static class RateProp implements CompoundTypeProperty<ExhangeCMoneyRate, Rate> {
public String getName() {
return "rate";
}
public Rate getValue(ExhangeCMoneyRate valueObject) {
return valueObject.getRate();
}
public int getDbType() {
return 0;
}
}
static class CMoneyProp implements CompoundTypeProperty<ExhangeCMoneyRate, CMoney> {
public String getName() {
return "cmoney";
}
public CMoney getValue(ExhangeCMoneyRate valueObject) {
return valueObject.getCmoney();
}
public int getDbType() {
return 0;
}
}
}
@@ -1,70 +1,51 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ivo.converter;
import org.joda.time.Interval;
import com.avaje.ebean.config.CompoundType;
import com.avaje.ebean.config.CompoundTypeProperty;
public class JodaIntervalCompoundType implements CompoundType<Interval>{
public Interval create(Object[] propertyValues) {
return new Interval((Long)propertyValues[0], (Long)propertyValues[1]);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public CompoundTypeProperty<Interval, ?>[] getProperties() {
CompoundTypeProperty[] props = {new Start(), new End()};
return props;
}
static class Start implements CompoundTypeProperty<Interval, Long> {
public String getName() {
return "startMillis";
}
public Long getValue(Interval valueObject) {
return valueObject.getStartMillis();
}
public int getDbType() {
return java.sql.Types.TIMESTAMP;
}
}
static class End implements CompoundTypeProperty<Interval, Long> {
public String getName() {
return "endMillis";
}
public Long getValue(Interval valueObject) {
return valueObject.getEndMillis();
}
public int getDbType() {
return java.sql.Types.TIMESTAMP;
}
}
}
package com.avaje.tests.model.ivo.converter;
import org.joda.time.Interval;
import com.avaje.ebean.config.CompoundType;
import com.avaje.ebean.config.CompoundTypeProperty;
public class JodaIntervalCompoundType implements CompoundType<Interval>{
public Interval create(Object[] propertyValues) {
return new Interval((Long)propertyValues[0], (Long)propertyValues[1]);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public CompoundTypeProperty<Interval, ?>[] getProperties() {
CompoundTypeProperty[] props = {new Start(), new End()};
return props;
}
static class Start implements CompoundTypeProperty<Interval, Long> {
public String getName() {
return "startMillis";
}
public Long getValue(Interval valueObject) {
return valueObject.getStartMillis();
}
public int getDbType() {
return java.sql.Types.TIMESTAMP;
}
}
static class End implements CompoundTypeProperty<Interval, Long> {
public String getName() {
return "endMillis";
}
public Long getValue(Interval valueObject) {
return valueObject.getEndMillis();
}
public int getDbType() {
return java.sql.Types.TIMESTAMP;
}
}
}
@@ -1,43 +1,24 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ivo.converter;
import java.sql.Timestamp;
import com.avaje.ebean.config.ScalarTypeConverter;
import com.avaje.tests.model.ivo.SysTime;
public class SysTimeConverter implements ScalarTypeConverter<SysTime, Timestamp> {
public SysTime getNullValue() {
return null;
}
public Timestamp unwrapValue(SysTime beanType) {
return new Timestamp(beanType.getMillis());
}
public SysTime wrapValue(Timestamp scalarType) {
return new SysTime(scalarType.getTime());
}
}
package com.avaje.tests.model.ivo.converter;
import java.sql.Timestamp;
import com.avaje.ebean.config.ScalarTypeConverter;
import com.avaje.tests.model.ivo.SysTime;
public class SysTimeConverter implements ScalarTypeConverter<SysTime, Timestamp> {
public SysTime getNullValue() {
return null;
}
public Timestamp unwrapValue(SysTime beanType) {
return new Timestamp(beanType.getMillis());
}
public SysTime wrapValue(Timestamp scalarType) {
return new SysTime(scalarType.getTime());
}
}
@@ -1,149 +1,130 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import org.joda.time.LocalDateTime;
import com.avaje.ebean.annotation.EnumValue;
import com.avaje.ebean.annotation.LdapAttribute;
import com.avaje.ebean.annotation.LdapDomain;
import com.avaje.tests.ldap.SimpleLdapSetAdapater;
@LdapDomain(
baseDn = "ou=avajepeople,o=avajecustomers,dc=avaje,dc=net,dc=nz",
objectclass = "top,organizationalperson,avajeperson,inetadmin,inetorgperson,person,inetuser")
@Entity
public class LDPerson {
public enum Status {
@EnumValue(value = "Active")
ACTIVE,
@EnumValue(value = "Inactive")
INACTIVE
}
@Id
@Column(name = "uid")
private String userId;
@Column(name = "inetUserStatus")
private Status status;
private String cn;
private String sn;
private String givenName;
private String userPassword;
@Basic(fetch=FetchType.LAZY)
private LocalDateTime modifiedTime;
@Basic(fetch=FetchType.LAZY)
@LdapAttribute(adapter=SimpleLdapSetAdapater.class)
private Set<Long> accounts;
public String toString() {
return userId + " " + status;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getGivenName() {
return givenName;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public LocalDateTime getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(LocalDateTime modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Set<Long> getAccounts() {
return accounts;
}
public void setAccounts(Set<Long> accounts) {
this.accounts = accounts;
}
public void addAccount(long accountNumber){
if (accounts == null){
accounts = new HashSet<Long>();
}
accounts.add(accountNumber);
}
}
package com.avaje.tests.model.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import org.joda.time.LocalDateTime;
import com.avaje.ebean.annotation.EnumValue;
import com.avaje.ebean.annotation.LdapAttribute;
import com.avaje.ebean.annotation.LdapDomain;
import com.avaje.tests.ldap.SimpleLdapSetAdapater;
@LdapDomain(
baseDn = "ou=avajepeople,o=avajecustomers,dc=avaje,dc=net,dc=nz",
objectclass = "top,organizationalperson,avajeperson,inetadmin,inetorgperson,person,inetuser")
@Entity
public class LDPerson {
public enum Status {
@EnumValue(value = "Active")
ACTIVE,
@EnumValue(value = "Inactive")
INACTIVE
}
@Id
@Column(name = "uid")
private String userId;
@Column(name = "inetUserStatus")
private Status status;
private String cn;
private String sn;
private String givenName;
private String userPassword;
@Basic(fetch=FetchType.LAZY)
private LocalDateTime modifiedTime;
@Basic(fetch=FetchType.LAZY)
@LdapAttribute(adapter=SimpleLdapSetAdapater.class)
private Set<Long> accounts;
public String toString() {
return userId + " " + status;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getGivenName() {
return givenName;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public LocalDateTime getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(LocalDateTime modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Set<Long> getAccounts() {
return accounts;
}
public void setAccounts(Set<Long> accounts) {
this.accounts = accounts;
}
public void addAccount(long accountNumber){
if (accounts == null){
accounts = new HashSet<Long>();
}
accounts.add(accountNumber);
}
}
@@ -1,40 +1,21 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.build;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.xml.oxm.OxmNode;
import com.avaje.tests.xml.runtime.XoiAttribute;
import com.avaje.tests.xml.runtime.XrAttribute;
public class XbAttribute extends XbBase {
public XbAttribute(OxmNode rootNode, String nodeName, String propertyName){
super(rootNode, nodeName, propertyName);
}
public XoiAttribute create(BeanDescriptor<?> descriptor, boolean parentAssocBean) {
ElPropertyValue prop = descriptor.getElGetValue(propertyName);
return new XrAttribute(nodeName, prop, descriptor, parentAssocBean, formatter, parser);
}
}
package com.avaje.tests.xml.build;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.xml.oxm.OxmNode;
import com.avaje.tests.xml.runtime.XoiAttribute;
import com.avaje.tests.xml.runtime.XrAttribute;
public class XbAttribute extends XbBase {
public XbAttribute(OxmNode rootNode, String nodeName, String propertyName){
super(rootNode, nodeName, propertyName);
}
public XoiAttribute create(BeanDescriptor<?> descriptor, boolean parentAssocBean) {
ElPropertyValue prop = descriptor.getElGetValue(propertyName);
return new XrAttribute(nodeName, prop, descriptor, parentAssocBean, formatter, parser);
}
}
@@ -1,85 +1,66 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.build;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.tests.xml.oxm.OxmNode;
public abstract class XbBase {
protected OxmNode rootNode;
protected final String nodeName;
protected final String propertyName;
protected StringParser parser;
protected StringFormatter formatter;
protected boolean requiresXmlEncoding;
public XbBase(String nodeName) {
this.nodeName = nodeName;
this.propertyName = null;
}
public XbBase(OxmNode rootNode, String nodeName, String propertyName) {
this.rootNode = rootNode;
this.nodeName = nodeName;
this.propertyName = propertyName;
}
public String getNamingConventionNodeName(String propertyName) {
// if (rootNode != null){
// return rootNode.getNamingConventionNodeName(propertyName);
// }
return propertyName;
}
public String getNodeName() {
return nodeName;
}
public String getPropertyName() {
return propertyName;
}
public StringFormatter getFormatter() {
return formatter;
}
public void setFormatter(StringFormatter formatter) {
this.formatter = formatter;
}
public StringParser getParser() {
return parser;
}
public void setParser(StringParser parser) {
this.parser = parser;
}
public boolean isRequiresXmlEncoding() {
return requiresXmlEncoding;
}
public void setRequiresXmlEncoding(boolean requiresXmlEncoding) {
this.requiresXmlEncoding = requiresXmlEncoding;
}
}
package com.avaje.tests.xml.build;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.tests.xml.oxm.OxmNode;
public abstract class XbBase {
protected OxmNode rootNode;
protected final String nodeName;
protected final String propertyName;
protected StringParser parser;
protected StringFormatter formatter;
protected boolean requiresXmlEncoding;
public XbBase(String nodeName) {
this.nodeName = nodeName;
this.propertyName = null;
}
public XbBase(OxmNode rootNode, String nodeName, String propertyName) {
this.rootNode = rootNode;
this.nodeName = nodeName;
this.propertyName = propertyName;
}
public String getNamingConventionNodeName(String propertyName) {
// if (rootNode != null){
// return rootNode.getNamingConventionNodeName(propertyName);
// }
return propertyName;
}
public String getNodeName() {
return nodeName;
}
public String getPropertyName() {
return propertyName;
}
public StringFormatter getFormatter() {
return formatter;
}
public void setFormatter(StringFormatter formatter) {
this.formatter = formatter;
}
public StringParser getParser() {
return parser;
}
public void setParser(StringParser parser) {
this.parser = parser;
}
public boolean isRequiresXmlEncoding() {
return requiresXmlEncoding;
}
public void setRequiresXmlEncoding(boolean requiresXmlEncoding) {
this.requiresXmlEncoding = requiresXmlEncoding;
}
}
@@ -1,86 +1,67 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.build;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.tests.xml.oxm.OxmContext;
import com.avaje.tests.xml.oxm.OxmContextBuilder;
import com.avaje.tests.xml.oxm.OxmNamingConvention;
import com.avaje.tests.xml.runtime.XoiNode;
import com.avaje.tests.xml.runtime.XrContext;
public class XbContextBuilder implements OxmContextBuilder {
private final SpiEbeanServer ebeanServer;
private final OxmNamingConvention namingConvention;
String rootNodeName;
Map<String,XbNode> rootNodes = new HashMap<String,XbNode>();
public XbContextBuilder(SpiEbeanServer ebeanServer, OxmNamingConvention namingConvention){
this.ebeanServer = ebeanServer;
this.namingConvention = namingConvention;
}
protected String getNamingConventionNodeName(String propertyName) {
if (namingConvention != null){
return namingConvention.getNodeName(propertyName);
} else {
return propertyName;
}
}
public XbNode addRootElement(String rootElementName, Class<?> rootType) {
BeanDescriptor<?> descriptor = ebeanServer.getBeanDescriptor(rootType);
XbNode rootNode = new XbNode(rootElementName, descriptor);
rootNodes.put(rootElementName, rootNode);
return rootNode;
}
public OxmContext createContext() {
Map<Class<?>,XoiNode> classNodeMap = new HashMap<Class<?>, XoiNode>(rootNodes.size()+4);
Map<String,XoiNode> tagNodeMap = new HashMap<String, XoiNode>(rootNodes.size()+4);
Iterator<XbNode> it = rootNodes.values().iterator();
while (it.hasNext()) {
XbNode xbNode = it.next();
XoiNode xoiNode = xbNode.createNode();
classNodeMap.put(xbNode.getRootBeanType(), xoiNode);
tagNodeMap.put(xbNode.getRootElementName(), xoiNode);
}
return new XrContext(tagNodeMap, classNodeMap);
}
}
package com.avaje.tests.xml.build;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.tests.xml.oxm.OxmContext;
import com.avaje.tests.xml.oxm.OxmContextBuilder;
import com.avaje.tests.xml.oxm.OxmNamingConvention;
import com.avaje.tests.xml.runtime.XoiNode;
import com.avaje.tests.xml.runtime.XrContext;
public class XbContextBuilder implements OxmContextBuilder {
private final SpiEbeanServer ebeanServer;
private final OxmNamingConvention namingConvention;
String rootNodeName;
Map<String,XbNode> rootNodes = new HashMap<String,XbNode>();
public XbContextBuilder(SpiEbeanServer ebeanServer, OxmNamingConvention namingConvention){
this.ebeanServer = ebeanServer;
this.namingConvention = namingConvention;
}
protected String getNamingConventionNodeName(String propertyName) {
if (namingConvention != null){
return namingConvention.getNodeName(propertyName);
} else {
return propertyName;
}
}
public XbNode addRootElement(String rootElementName, Class<?> rootType) {
BeanDescriptor<?> descriptor = ebeanServer.getBeanDescriptor(rootType);
XbNode rootNode = new XbNode(rootElementName, descriptor);
rootNodes.put(rootElementName, rootNode);
return rootNode;
}
public OxmContext createContext() {
Map<Class<?>,XoiNode> classNodeMap = new HashMap<Class<?>, XoiNode>(rootNodes.size()+4);
Map<String,XoiNode> tagNodeMap = new HashMap<String, XoiNode>(rootNodes.size()+4);
Iterator<XbNode> it = rootNodes.values().iterator();
while (it.hasNext()) {
XbNode xbNode = it.next();
XoiNode xoiNode = xbNode.createNode();
classNodeMap.put(xbNode.getRootBeanType(), xoiNode);
tagNodeMap.put(xbNode.getRootElementName(), xoiNode);
}
return new XrContext(tagNodeMap, classNodeMap);
}
}
@@ -1,163 +1,144 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.build;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.xml.oxm.OxmNode;
import com.avaje.tests.xml.runtime.XoiAttribute;
import com.avaje.tests.xml.runtime.XoiNode;
import com.avaje.tests.xml.runtime.XrCollection;
import com.avaje.tests.xml.runtime.XrNode;
public class XbNode extends XbBase implements OxmNode {
private Map<String,XbAttribute> attributes = new LinkedHashMap<String, XbAttribute>();
private List<XbNode> childNodes = new ArrayList<XbNode>();
private final String rootElementName;
private final BeanDescriptor<?> rootDescriptor;
public XbNode(String rootElementName, BeanDescriptor<?> rootDescriptor) {
super(rootElementName);
this.rootElementName = rootElementName;
this.rootDescriptor = rootDescriptor;
this.rootNode = this;
}
public XbNode(OxmNode rootNode, String propertyName, String nodeName) {
super(rootNode, nodeName, propertyName);
this.rootElementName = null;
this.rootDescriptor = null;
}
public Class<?> getRootBeanType() {
return rootDescriptor.getBeanType();
}
public String getRootElementName() {
return rootElementName;
}
public OxmNode addWrapperElement(String elementName){
return addElement(null, elementName);
}
public OxmNode addElement(String propertyName){
String elementName = getNamingConventionNodeName(propertyName);
return addElement(propertyName, elementName);
}
public OxmNode addElement(String propertyName, String elementName){
XbNode n = new XbNode(rootNode, propertyName, elementName);
childNodes.add(n);
return n;
}
public OxmNode addAttribute(String propertyName){
String attrName = getNamingConventionNodeName(propertyName);
return addAttribute(propertyName, attrName);
}
public OxmNode addAttribute(String propertyName, String attrName){
XbAttribute xbAttribute = attributes.get(attrName);
if (xbAttribute != null){
throw new RuntimeException("Attribute with this name ["+attrName+"]already exists");
}
xbAttribute = new XbAttribute(rootNode, attrName, propertyName);
return this;
}
public XoiNode createNode() {
return createNode(rootDescriptor);
}
protected XoiNode createNode(BeanDescriptor<?> d) {
XoiAttribute[] attrs = new XoiAttribute[attributes.size()];
boolean assocManyProperty = false;
boolean assocOneProperty = false;
ElPropertyValue prop = null;
if (propertyName != null){
prop = d.getElGetValue(propertyName);
if (prop == null){
throw new RuntimeException("Property "+propertyName+" not found from "+d.getFullName());
}
BeanProperty p = prop.getBeanProperty();
if (p instanceof BeanPropertyAssoc<?>){
// move to the relative/target descriptor before
// evaluating the attributes and children for this node
BeanDescriptor<?> targetDescriptor = ((BeanPropertyAssoc<?>)p).getTargetDescriptor();
if (targetDescriptor == null) {
if (EntityType.XMLELEMENT.equals(d.getEntityType())){
Class<?> targetType = p.getPropertyType();
targetDescriptor = d.getBeanDescriptor(targetType);
}
}
if (targetDescriptor != null){
d = targetDescriptor;
}
assocManyProperty = (p instanceof BeanPropertyAssocMany<?>);
assocOneProperty = (p instanceof BeanPropertyAssocOne<?>);
}
}
int i = 0;
for (XbAttribute attrBuilder : attributes.values()) {
XoiAttribute xoAttr = attrBuilder.create(d, assocOneProperty);
attrs[i++] = xoAttr;
}
XoiNode[] children = null;
if (!childNodes.isEmpty()){
children = new XoiNode[childNodes.size()];
for (int j = 0; j < children.length; j++) {
XbNode xbNode = childNodes.get(j);
children[j] = xbNode.createNode(d);
}
}
if (assocManyProperty){
boolean invokeFetch = false;
return new XrCollection(nodeName, prop, children, invokeFetch);
}
if (assocOneProperty){
return new XrNode(nodeName, prop, d, children, attrs);
}
return new XrNode(nodeName, prop, d, formatter, parser, children, attrs);
}
}
package com.avaje.tests.xml.build;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.tests.xml.oxm.OxmNode;
import com.avaje.tests.xml.runtime.XoiAttribute;
import com.avaje.tests.xml.runtime.XoiNode;
import com.avaje.tests.xml.runtime.XrCollection;
import com.avaje.tests.xml.runtime.XrNode;
public class XbNode extends XbBase implements OxmNode {
private Map<String,XbAttribute> attributes = new LinkedHashMap<String, XbAttribute>();
private List<XbNode> childNodes = new ArrayList<XbNode>();
private final String rootElementName;
private final BeanDescriptor<?> rootDescriptor;
public XbNode(String rootElementName, BeanDescriptor<?> rootDescriptor) {
super(rootElementName);
this.rootElementName = rootElementName;
this.rootDescriptor = rootDescriptor;
this.rootNode = this;
}
public XbNode(OxmNode rootNode, String propertyName, String nodeName) {
super(rootNode, nodeName, propertyName);
this.rootElementName = null;
this.rootDescriptor = null;
}
public Class<?> getRootBeanType() {
return rootDescriptor.getBeanType();
}
public String getRootElementName() {
return rootElementName;
}
public OxmNode addWrapperElement(String elementName){
return addElement(null, elementName);
}
public OxmNode addElement(String propertyName){
String elementName = getNamingConventionNodeName(propertyName);
return addElement(propertyName, elementName);
}
public OxmNode addElement(String propertyName, String elementName){
XbNode n = new XbNode(rootNode, propertyName, elementName);
childNodes.add(n);
return n;
}
public OxmNode addAttribute(String propertyName){
String attrName = getNamingConventionNodeName(propertyName);
return addAttribute(propertyName, attrName);
}
public OxmNode addAttribute(String propertyName, String attrName){
XbAttribute xbAttribute = attributes.get(attrName);
if (xbAttribute != null){
throw new RuntimeException("Attribute with this name ["+attrName+"]already exists");
}
xbAttribute = new XbAttribute(rootNode, attrName, propertyName);
return this;
}
public XoiNode createNode() {
return createNode(rootDescriptor);
}
protected XoiNode createNode(BeanDescriptor<?> d) {
XoiAttribute[] attrs = new XoiAttribute[attributes.size()];
boolean assocManyProperty = false;
boolean assocOneProperty = false;
ElPropertyValue prop = null;
if (propertyName != null){
prop = d.getElGetValue(propertyName);
if (prop == null){
throw new RuntimeException("Property "+propertyName+" not found from "+d.getFullName());
}
BeanProperty p = prop.getBeanProperty();
if (p instanceof BeanPropertyAssoc<?>){
// move to the relative/target descriptor before
// evaluating the attributes and children for this node
BeanDescriptor<?> targetDescriptor = ((BeanPropertyAssoc<?>)p).getTargetDescriptor();
if (targetDescriptor == null) {
if (EntityType.XMLELEMENT.equals(d.getEntityType())){
Class<?> targetType = p.getPropertyType();
targetDescriptor = d.getBeanDescriptor(targetType);
}
}
if (targetDescriptor != null){
d = targetDescriptor;
}
assocManyProperty = (p instanceof BeanPropertyAssocMany<?>);
assocOneProperty = (p instanceof BeanPropertyAssocOne<?>);
}
}
int i = 0;
for (XbAttribute attrBuilder : attributes.values()) {
XoiAttribute xoAttr = attrBuilder.create(d, assocOneProperty);
attrs[i++] = xoAttr;
}
XoiNode[] children = null;
if (!childNodes.isEmpty()){
children = new XoiNode[childNodes.size()];
for (int j = 0; j < children.length; j++) {
XbNode xbNode = childNodes.get(j);
children[j] = xbNode.createNode(d);
}
}
if (assocManyProperty){
boolean invokeFetch = false;
return new XrCollection(nodeName, prop, children, invokeFetch);
}
if (assocOneProperty){
return new XrNode(nodeName, prop, d, children, attrs);
}
return new XrNode(nodeName, prop, d, formatter, parser, children, attrs);
}
}
@@ -1,36 +1,17 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.oxm;
import java.io.IOException;
import java.io.Writer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public interface OxmContext {
public void writeBean(Object bean, Document document) throws IOException;
public void writeBean(Object bean, Writer writer) throws IOException;
public Object readBean(Node node);
}
package com.avaje.tests.xml.oxm;
import java.io.IOException;
import java.io.Writer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public interface OxmContext {
public void writeBean(Object bean, Document document) throws IOException;
public void writeBean(Object bean, Writer writer) throws IOException;
public Object readBean(Node node);
}
@@ -1,28 +1,9 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.oxm;
public interface OxmContextBuilder {
public OxmNode addRootElement(String rootElementName, Class<?> rootType);
public OxmContext createContext();
package com.avaje.tests.xml.oxm;
public interface OxmContextBuilder {
public OxmNode addRootElement(String rootElementName, Class<?> rootType);
public OxmContext createContext();
}
@@ -1,33 +1,14 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.oxm;
/**
* Naming convention used in XML to Object mapping.
*
* @author rbygrave
*/
public interface OxmNamingConvention {
/**
* Returns the default node/element/attribute name for the given property name.
*/
public String getNodeName(String propertyName);
}
package com.avaje.tests.xml.oxm;
/**
* Naming convention used in XML to Object mapping.
*
* @author rbygrave
*/
public interface OxmNamingConvention {
/**
* Returns the default node/element/attribute name for the given property name.
*/
public String getNodeName(String propertyName);
}
@@ -1,34 +1,15 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.oxm;
public interface OxmNode {
public OxmNode addWrapperElement(String elementName);
public OxmNode addElement(String propertyName);
public OxmNode addElement(String propertyName, String elementName);
public OxmNode addAttribute(String propertyName);
public OxmNode addAttribute(String propertyName, String attrName);
package com.avaje.tests.xml.oxm;
public interface OxmNode {
public OxmNode addWrapperElement(String elementName);
public OxmNode addElement(String propertyName);
public OxmNode addElement(String propertyName, String elementName);
public OxmNode addAttribute(String propertyName);
public OxmNode addAttribute(String propertyName, String attrName);
}
@@ -1,37 +1,18 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public interface XoiAttribute {
public void writeAttribute(XrOutputWriter o, Object bean, Object value) throws IOException;
public void writeAttribute(XrOutputDocument out, Element e, Object bean, Object value) throws IOException;
public void readNode(Node node, NamedNodeMap attributes, XrReadContext ctx);
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public interface XoiAttribute {
public void writeAttribute(XrOutputWriter o, Object bean, Object value) throws IOException;
public void writeAttribute(XrOutputDocument out, Element e, Object bean, Object value) throws IOException;
public void readNode(Node node, NamedNodeMap attributes, XrReadContext ctx);
}
@@ -1,39 +1,20 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Node;
public interface XoiNode {
public String getNodeName();
public Object createBean(boolean vanillaMode);
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException;
public void writeNode(XrOutputWriter o, Object bean) throws IOException;
public void readNode(Node node, XrReadContext ctx);
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Node;
public interface XoiNode {
public String getNodeName();
public Object createBean(boolean vanillaMode);
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException;
public void writeNode(XrOutputWriter o, Object bean) throws IOException;
public void readNode(Node node, XrReadContext ctx);
}
@@ -1,86 +1,67 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrAttribute extends XrBase implements XoiAttribute {
private boolean parentAssocBean;
/**
* Create as an property based attribute.
*/
public XrAttribute(String attrName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, boolean parentAssocBean, StringFormatter formatter, StringParser parser) {
super(attrName, prop, parentDesc, formatter, parser);
this.parentAssocBean = parentAssocBean;
}
public XrAttribute(String attrName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, boolean parentAssocBean) {
this(attrName, prop, parentDesc, parentAssocBean, null, null);
}
public void writeAttribute(XrOutputDocument out, Element e, Object bean, Object value) throws IOException {
Object beanToUse = parentAssocBean ? value : bean;
Object v = getObjectValue(beanToUse);
String sv = getFormattedValue(v);
Attr attr = out.getDocument().createAttribute(nodeName);
attr.setValue(sv);
e.setAttributeNode(attr);
}
public void writeAttribute(XrOutputWriter o, Object bean, Object value) throws IOException {
Object beanToUse = parentAssocBean ? value : bean;
Object v = getObjectValue(beanToUse);
String sv = getFormattedValue(v);
o.write(" ");
o.write(nodeName);
o.write("=\"");
o.write(sv);
o.write("\"");
}
public void readNode(Node node, NamedNodeMap attributes, XrReadContext ctx) {
Node namedItem = attributes.getNamedItem(nodeName);
if (namedItem != null){
String c = namedItem.getTextContent();
Object v = getParsedValue(c);
setObjectValue(ctx.getBean(), v);
}
}
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrAttribute extends XrBase implements XoiAttribute {
private boolean parentAssocBean;
/**
* Create as an property based attribute.
*/
public XrAttribute(String attrName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, boolean parentAssocBean, StringFormatter formatter, StringParser parser) {
super(attrName, prop, parentDesc, formatter, parser);
this.parentAssocBean = parentAssocBean;
}
public XrAttribute(String attrName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, boolean parentAssocBean) {
this(attrName, prop, parentDesc, parentAssocBean, null, null);
}
public void writeAttribute(XrOutputDocument out, Element e, Object bean, Object value) throws IOException {
Object beanToUse = parentAssocBean ? value : bean;
Object v = getObjectValue(beanToUse);
String sv = getFormattedValue(v);
Attr attr = out.getDocument().createAttribute(nodeName);
attr.setValue(sv);
e.setAttributeNode(attr);
}
public void writeAttribute(XrOutputWriter o, Object bean, Object value) throws IOException {
Object beanToUse = parentAssocBean ? value : bean;
Object v = getObjectValue(beanToUse);
String sv = getFormattedValue(v);
o.write(" ");
o.write(nodeName);
o.write("=\"");
o.write(sv);
o.write("\"");
}
public void readNode(Node node, NamedNodeMap attributes, XrReadContext ctx) {
Node namedItem = attributes.getNamedItem(nodeName);
if (namedItem != null){
String c = namedItem.getTextContent();
Object v = getParsedValue(c);
setObjectValue(ctx.getBean(), v);
}
}
}
@@ -1,107 +1,88 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public abstract class XrBase {
protected final String nodeName;
protected final ElPropertyValue prop;
protected final StringFormatter stringFormatter;
protected final StringParser stringParser;
protected final boolean encode;
protected boolean decreaseDepth = false;
protected BeanDescriptor<?> beanDescriptor;
protected XrBase(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter, StringParser parser) {
if (formatter == null && prop != null){
formatter = prop.getStringFormatter();
}
if (parser == null && prop != null){
parser = prop.getStringParser();
}
this.nodeName = nodeName;
this.prop = prop;
this.stringFormatter = formatter;
this.stringParser = parser;
this.encode = false;
this.beanDescriptor = getBeanDescriptor(parentDesc, prop);
}
private BeanDescriptor<?> getBeanDescriptor(BeanDescriptor<?> parent, ElPropertyValue prop){
if (prop != null){
BeanProperty beanProperty = prop.getBeanProperty();
if (beanProperty instanceof BeanPropertyAssoc<?>){
return ((BeanPropertyAssoc<?>)beanProperty).getTargetDescriptor();
}
}
return parent;
}
protected void setObjectValue(Object bean, Object value){
prop.elSetValue(bean, value, true, false);
}
protected Object getObjectValue(Object bean) {
return prop.elGetValue(bean);
}
protected Object getParsedValue(String value) {
if (value == null || value.length() == 0) {
return null;
}
//FIXME xml decode the string
if (stringParser != null){
return stringParser.parse(value);
}
return value;
}
protected String getFormattedValue(Object value) {
if (value == null) {
return "";
}
String s;
if (stringFormatter == null){
s = value.toString();
} else {
s = stringFormatter.format(value);
}
if (encode){
//FIXME xml encode the string
}
return s;
}
}
package com.avaje.tests.xml.runtime;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public abstract class XrBase {
protected final String nodeName;
protected final ElPropertyValue prop;
protected final StringFormatter stringFormatter;
protected final StringParser stringParser;
protected final boolean encode;
protected boolean decreaseDepth = false;
protected BeanDescriptor<?> beanDescriptor;
protected XrBase(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter, StringParser parser) {
if (formatter == null && prop != null){
formatter = prop.getStringFormatter();
}
if (parser == null && prop != null){
parser = prop.getStringParser();
}
this.nodeName = nodeName;
this.prop = prop;
this.stringFormatter = formatter;
this.stringParser = parser;
this.encode = false;
this.beanDescriptor = getBeanDescriptor(parentDesc, prop);
}
private BeanDescriptor<?> getBeanDescriptor(BeanDescriptor<?> parent, ElPropertyValue prop){
if (prop != null){
BeanProperty beanProperty = prop.getBeanProperty();
if (beanProperty instanceof BeanPropertyAssoc<?>){
return ((BeanPropertyAssoc<?>)beanProperty).getTargetDescriptor();
}
}
return parent;
}
protected void setObjectValue(Object bean, Object value){
prop.elSetValue(bean, value, true, false);
}
protected Object getObjectValue(Object bean) {
return prop.elGetValue(bean);
}
protected Object getParsedValue(String value) {
if (value == null || value.length() == 0) {
return null;
}
//FIXME xml decode the string
if (stringParser != null){
return stringParser.parse(value);
}
return value;
}
protected String getFormattedValue(Object value) {
if (value == null) {
return "";
}
String s;
if (stringFormatter == null){
s = value.toString();
} else {
s = stringFormatter.format(value);
}
if (encode){
//FIXME xml encode the string
}
return s;
}
}
@@ -1,195 +1,176 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.persistence.PersistenceException;
import org.w3c.dom.Node;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionAdd;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrCollection extends XrNode implements XoiNode {
private final boolean invokeFetch;
private final BeanPropertyAssocMany<?> manyProp;
private final String mapKey;
private final BeanDescriptor<?> targetDescriptor;
/**
* Construct with no mapKey and no attributes.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, boolean invokeFetch) {
this(name, prop, children, null, invokeFetch, null);
}
/**
* Construct with no attributes.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, boolean invokeFetch, String mapKey) {
this(name, prop, children, null, invokeFetch, mapKey);
}
/**
* Construct with all options.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, XoiAttribute[] attributes, boolean invokeFetch, String mapKey) {
super(name, prop, null, null, null, children, attributes);
this.invokeFetch = invokeFetch;
this.decreaseDepth = true;
this.mapKey = mapKey;
this.manyProp = (BeanPropertyAssocMany<?>)prop.getBeanProperty();
this.targetDescriptor = manyProp.getTargetDescriptor();
}
@Override
public void readNode(Node node, XrReadContext ctx) {
Object parentBean = ctx.getBean();
// create a List/Set/Map to hold the details
Object details = manyProp.createEmpty(ctx.isVanillaMode());
// Wrapper used to add to the collection
BeanCollectionAdd bcAdd = manyProp.getBeanCollectionAdd(details, mapKey);
Node detailNode = nextElement(node.getFirstChild());
do {
Object detailBean = targetDescriptor.createBean(ctx.isVanillaMode());
ctx.setBean(detailBean);
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].readNode(detailNode, ctx);
}
bcAdd.addBean(detailBean);
detailNode = nextElement(detailNode.getNextSibling());
} while(detailNode != null);
setObjectValue(parentBean, details);
ctx.setBean(parentBean);
}
private Node nextElement(Node node) {
while (node != null) {
int type = node.getNodeType();
if (type == Node.ELEMENT_NODE){
return node;
}
node = node.getNextSibling();
}
return null;
}
@Override
public void writeContent(XrOutputWriter o, Object bean, Object val) throws IOException {
Collection<?> collection = (Collection<?>)val;
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
Object childBean = it.next();
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(o, childBean);
}
}
}
@Override
public void writeContent(XrOutputDocument out, Node e, Object bean, Object value) throws IOException {
Collection<?> collection = (Collection<?>)value;
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
Object childBean = it.next();
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(out, e, childBean);
}
}
}
@Override
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException {
super.writeNode(out, node, bean);
}
// protected void writeNodeChildren(XmlOutputDocument out, Node childNode, Object bean, Object val) throws IOException {
//
// if (hasChildNodes) {
// for (int i = 0; i < childNodes.length; i++) {
// childNodes[i].writeNode(out, childNode, bean);
// }
// }
// }
@Override
protected Object getObjectValue(Object bean) {
Object o = prop.elGetValue(bean);
Collection<?> collection = getDetailsIterator(o);
return collection;
}
/**
* Return the details of the collection or map taking care to avoid
* unnecessary fetching of the data.
*/
private Collection<?> getDetailsIterator(Object o) {
if (o == null) {
return null;
}
if (o instanceof BeanCollection<?>) {
BeanCollection<?> bc = (BeanCollection<?>) o;
if (!invokeFetch && !bc.isPopulated()) {
return null;
}
bc.size();
return bc.getActualDetails();
}
if (o instanceof Map<?,?>) {
// yes, we want the entrySet (to set the keys)
return ((Map<?, ?>) o).entrySet();
} else if (o instanceof Collection<?>) {
return ((Collection<?>) o);
}
String m = "expecting a Map or Collection but got [" + o.getClass().getName() + "]";
throw new PersistenceException(m);
}
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.persistence.PersistenceException;
import org.w3c.dom.Node;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionAdd;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrCollection extends XrNode implements XoiNode {
private final boolean invokeFetch;
private final BeanPropertyAssocMany<?> manyProp;
private final String mapKey;
private final BeanDescriptor<?> targetDescriptor;
/**
* Construct with no mapKey and no attributes.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, boolean invokeFetch) {
this(name, prop, children, null, invokeFetch, null);
}
/**
* Construct with no attributes.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, boolean invokeFetch, String mapKey) {
this(name, prop, children, null, invokeFetch, mapKey);
}
/**
* Construct with all options.
*/
public XrCollection(String name, ElPropertyValue prop, XoiNode[] children, XoiAttribute[] attributes, boolean invokeFetch, String mapKey) {
super(name, prop, null, null, null, children, attributes);
this.invokeFetch = invokeFetch;
this.decreaseDepth = true;
this.mapKey = mapKey;
this.manyProp = (BeanPropertyAssocMany<?>)prop.getBeanProperty();
this.targetDescriptor = manyProp.getTargetDescriptor();
}
@Override
public void readNode(Node node, XrReadContext ctx) {
Object parentBean = ctx.getBean();
// create a List/Set/Map to hold the details
Object details = manyProp.createEmpty(ctx.isVanillaMode());
// Wrapper used to add to the collection
BeanCollectionAdd bcAdd = manyProp.getBeanCollectionAdd(details, mapKey);
Node detailNode = nextElement(node.getFirstChild());
do {
Object detailBean = targetDescriptor.createBean(ctx.isVanillaMode());
ctx.setBean(detailBean);
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].readNode(detailNode, ctx);
}
bcAdd.addBean(detailBean);
detailNode = nextElement(detailNode.getNextSibling());
} while(detailNode != null);
setObjectValue(parentBean, details);
ctx.setBean(parentBean);
}
private Node nextElement(Node node) {
while (node != null) {
int type = node.getNodeType();
if (type == Node.ELEMENT_NODE){
return node;
}
node = node.getNextSibling();
}
return null;
}
@Override
public void writeContent(XrOutputWriter o, Object bean, Object val) throws IOException {
Collection<?> collection = (Collection<?>)val;
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
Object childBean = it.next();
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(o, childBean);
}
}
}
@Override
public void writeContent(XrOutputDocument out, Node e, Object bean, Object value) throws IOException {
Collection<?> collection = (Collection<?>)value;
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
Object childBean = it.next();
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(out, e, childBean);
}
}
}
@Override
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException {
super.writeNode(out, node, bean);
}
// protected void writeNodeChildren(XmlOutputDocument out, Node childNode, Object bean, Object val) throws IOException {
//
// if (hasChildNodes) {
// for (int i = 0; i < childNodes.length; i++) {
// childNodes[i].writeNode(out, childNode, bean);
// }
// }
// }
@Override
protected Object getObjectValue(Object bean) {
Object o = prop.elGetValue(bean);
Collection<?> collection = getDetailsIterator(o);
return collection;
}
/**
* Return the details of the collection or map taking care to avoid
* unnecessary fetching of the data.
*/
private Collection<?> getDetailsIterator(Object o) {
if (o == null) {
return null;
}
if (o instanceof BeanCollection<?>) {
BeanCollection<?> bc = (BeanCollection<?>) o;
if (!invokeFetch && !bc.isPopulated()) {
return null;
}
bc.size();
return bc.getActualDetails();
}
if (o instanceof Map<?,?>) {
// yes, we want the entrySet (to set the keys)
return ((Map<?, ?>) o).entrySet();
} else if (o instanceof Collection<?>) {
return ((Collection<?>) o);
}
String m = "expecting a Map or Collection but got [" + o.getClass().getName() + "]";
throw new PersistenceException(m);
}
}
@@ -1,89 +1,70 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.avaje.tests.xml.oxm.OxmContext;
public class XrContext implements OxmContext {
Map<String,XoiNode> tagToNodeMap;
Map<Class<?>,XoiNode> classToNodeMap;
public XrContext(Map<String,XoiNode> tagToNodeMap, Map<Class<?>,XoiNode> classToNodeMap) {
this.tagToNodeMap = tagToNodeMap;
this.classToNodeMap = classToNodeMap;
}
public void writeBean(Object bean, Document document) throws IOException {
XoiNode xoiNode = getXoiNode(bean);
XrOutputDocument out = new XrOutputDocument(document);
xoiNode.writeNode(out, null, bean);
}
public void writeBean(Object bean, Writer writer) throws IOException {
XoiNode xoiNode = getXoiNode(bean);
XrOutputWriter o = new XrOutputWriter(writer);
xoiNode.writeNode(o, bean);
}
public Object readBean(Node node) {
XoiNode xoiNode = getXoiNode(node.getNodeName());
Object bean = xoiNode.createBean(false);
XrReadContext ctx = new XrReadContext(bean);
xoiNode.readNode(node, ctx);
return ctx.getBean();
}
private XoiNode getXoiNode(Object bean) {
Class<?> cls = bean.getClass();
XoiNode xoiNode = classToNodeMap.get(cls);
if (xoiNode == null){
throw new RuntimeException("No handler for type "+cls);
} else {
return xoiNode;
}
}
private XoiNode getXoiNode(String nodeName) {
XoiNode xoiNode = tagToNodeMap.get(nodeName);
if (xoiNode == null){
throw new RuntimeException("No handler for node "+nodeName);
} else {
return xoiNode;
}
}
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.avaje.tests.xml.oxm.OxmContext;
public class XrContext implements OxmContext {
Map<String,XoiNode> tagToNodeMap;
Map<Class<?>,XoiNode> classToNodeMap;
public XrContext(Map<String,XoiNode> tagToNodeMap, Map<Class<?>,XoiNode> classToNodeMap) {
this.tagToNodeMap = tagToNodeMap;
this.classToNodeMap = classToNodeMap;
}
public void writeBean(Object bean, Document document) throws IOException {
XoiNode xoiNode = getXoiNode(bean);
XrOutputDocument out = new XrOutputDocument(document);
xoiNode.writeNode(out, null, bean);
}
public void writeBean(Object bean, Writer writer) throws IOException {
XoiNode xoiNode = getXoiNode(bean);
XrOutputWriter o = new XrOutputWriter(writer);
xoiNode.writeNode(o, bean);
}
public Object readBean(Node node) {
XoiNode xoiNode = getXoiNode(node.getNodeName());
Object bean = xoiNode.createBean(false);
XrReadContext ctx = new XrReadContext(bean);
xoiNode.readNode(node, ctx);
return ctx.getBean();
}
private XoiNode getXoiNode(Object bean) {
Class<?> cls = bean.getClass();
XoiNode xoiNode = classToNodeMap.get(cls);
if (xoiNode == null){
throw new RuntimeException("No handler for type "+cls);
} else {
return xoiNode;
}
}
private XoiNode getXoiNode(String nodeName) {
XoiNode xoiNode = tagToNodeMap.get(nodeName);
if (xoiNode == null){
throw new RuntimeException("No handler for node "+nodeName);
} else {
return xoiNode;
}
}
}
@@ -1,229 +1,210 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrNode extends XrBase implements XoiNode {
protected final boolean assocBeanValue;
protected final XoiAttribute[] attributes;
protected final boolean hasAttributes;
protected final String beginTag;
protected final String beginTagEnd;
protected final String endTag;
protected final XoiNode[] childNodes;
protected final boolean hasChildNodes;
public XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, XoiNode[] childNodes, XoiAttribute[] attributes) {
this(nodeName, prop, parentDesc, null, null, childNodes, attributes, true);
}
public XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter,
StringParser parser, XoiNode[] childNodes, XoiAttribute[] attributes) {
this(nodeName, prop, parentDesc, formatter,parser, childNodes, attributes, false);
}
/**
* Create as a property based node.
*/
private XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter,
StringParser parser, XoiNode[] childNodes, XoiAttribute[] attributes, boolean assocBeanValue) {
super(nodeName, prop, parentDesc, formatter, parser);
this.assocBeanValue = assocBeanValue;
this.attributes = attributes;
this.hasAttributes = (attributes != null && attributes.length > 0);
this.childNodes = childNodes;
this.hasChildNodes = (childNodes!= null && childNodes.length > 0);
boolean selfClosing = false;
this.beginTagEnd = selfClosing ? "/>" : ">";
this.beginTag = "<" + nodeName;
this.endTag = selfClosing ? "" : "</" + nodeName + ">";
}
public String toString() {
return nodeName;
}
public Object createBean(boolean vanillaMode) {
return beanDescriptor.createBean(vanillaMode);
}
public String getNodeName() {
return nodeName;
}
public void readNode(Node node, XrReadContext ctx) {
Object parentBean = null;
if (assocBeanValue){
parentBean = ctx.getBean();
Object childBean = beanDescriptor.createBean(ctx.isVanillaMode());
setObjectValue(parentBean, childBean);
ctx.setBean(childBean);
} else if (prop != null){
String c = node.getTextContent();
Object v = getParsedValue(c);
setObjectValue(ctx.getBean(), v);
}
if (hasAttributes){
NamedNodeMap attrs = node.getAttributes();
for (int i = 0; i < attributes.length; i++) {
attributes[i].readNode(node, attrs, ctx);
}
}
if (hasChildNodes){
readChildNodes(node, ctx);
}
if (parentBean != null){
ctx.setBean(parentBean);
}
}
private void readChildNodes(Node node, XrReadContext ctx) {
Node childNode = node.getFirstChild();
int pos = -1;
do {
for (; ++pos < childNodes.length;) {
if (childNode.getNodeName().equals(childNodes[pos].getNodeName())) {
childNodes[pos].readNode(childNode, ctx);
break;
} else {
System.out.println("no element for " + childNodes[pos].getNodeName());
}
}
childNode = childNode.getNextSibling();
} while (childNode != null);
}
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException {
Object val = prop == null ? null : getObjectValue(bean);
Node childNode;
if (nodeName == null){
childNode = node;
} else {
Element element = out.getDocument().createElement(nodeName);
childNode = element;
out.appendChild(node, element);
if (hasAttributes) {
for (int i = 0; i < attributes.length; i++) {
attributes[i].writeAttribute(out, element, bean, val);
}
}
}
writeContent(out, childNode, bean, val);
}
public void writeNode(XrOutputWriter o, Object bean) throws IOException {
Object val = null;
if (prop != null){
val = getObjectValue(bean);
if (val == null && !hasAttributes && !hasChildNodes){
return;
}
}
o.increaseDepth();
o.write(beginTag);
if (hasAttributes) {
for (int i = 0; i < attributes.length; i++) {
attributes[i].writeAttribute(o, bean, val);
}
}
o.write(beginTagEnd);
writeContent(o, bean, val);
if (hasChildNodes){
o.decreaseDepth(true);
} else {
o.decreaseDepth(decreaseDepth);
}
o.write(endTag);
}
public void writeContent(XrOutputDocument out, Node e, Object bean, Object value) throws IOException {
if (!assocBeanValue && value != null){
String sv = getFormattedValue(value);
//TODO encode string
e.setTextContent(sv);
}
if (hasChildNodes) {
Object beanToPass = assocBeanValue ? value : bean;
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(out, e, beanToPass);
}
}
}
public void writeContent(XrOutputWriter o, Object bean, Object value) throws IOException {
if (!assocBeanValue && value != null){
String sv = getFormattedValue(value);
o.writeEncoded(sv);
}
if (hasChildNodes) {
Object beanToPass = assocBeanValue ? value : bean;
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(o, beanToPass);
}
}
}
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
public class XrNode extends XrBase implements XoiNode {
protected final boolean assocBeanValue;
protected final XoiAttribute[] attributes;
protected final boolean hasAttributes;
protected final String beginTag;
protected final String beginTagEnd;
protected final String endTag;
protected final XoiNode[] childNodes;
protected final boolean hasChildNodes;
public XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, XoiNode[] childNodes, XoiAttribute[] attributes) {
this(nodeName, prop, parentDesc, null, null, childNodes, attributes, true);
}
public XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter,
StringParser parser, XoiNode[] childNodes, XoiAttribute[] attributes) {
this(nodeName, prop, parentDesc, formatter,parser, childNodes, attributes, false);
}
/**
* Create as a property based node.
*/
private XrNode(String nodeName, ElPropertyValue prop, BeanDescriptor<?> parentDesc, StringFormatter formatter,
StringParser parser, XoiNode[] childNodes, XoiAttribute[] attributes, boolean assocBeanValue) {
super(nodeName, prop, parentDesc, formatter, parser);
this.assocBeanValue = assocBeanValue;
this.attributes = attributes;
this.hasAttributes = (attributes != null && attributes.length > 0);
this.childNodes = childNodes;
this.hasChildNodes = (childNodes!= null && childNodes.length > 0);
boolean selfClosing = false;
this.beginTagEnd = selfClosing ? "/>" : ">";
this.beginTag = "<" + nodeName;
this.endTag = selfClosing ? "" : "</" + nodeName + ">";
}
public String toString() {
return nodeName;
}
public Object createBean(boolean vanillaMode) {
return beanDescriptor.createBean(vanillaMode);
}
public String getNodeName() {
return nodeName;
}
public void readNode(Node node, XrReadContext ctx) {
Object parentBean = null;
if (assocBeanValue){
parentBean = ctx.getBean();
Object childBean = beanDescriptor.createBean(ctx.isVanillaMode());
setObjectValue(parentBean, childBean);
ctx.setBean(childBean);
} else if (prop != null){
String c = node.getTextContent();
Object v = getParsedValue(c);
setObjectValue(ctx.getBean(), v);
}
if (hasAttributes){
NamedNodeMap attrs = node.getAttributes();
for (int i = 0; i < attributes.length; i++) {
attributes[i].readNode(node, attrs, ctx);
}
}
if (hasChildNodes){
readChildNodes(node, ctx);
}
if (parentBean != null){
ctx.setBean(parentBean);
}
}
private void readChildNodes(Node node, XrReadContext ctx) {
Node childNode = node.getFirstChild();
int pos = -1;
do {
for (; ++pos < childNodes.length;) {
if (childNode.getNodeName().equals(childNodes[pos].getNodeName())) {
childNodes[pos].readNode(childNode, ctx);
break;
} else {
System.out.println("no element for " + childNodes[pos].getNodeName());
}
}
childNode = childNode.getNextSibling();
} while (childNode != null);
}
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException {
Object val = prop == null ? null : getObjectValue(bean);
Node childNode;
if (nodeName == null){
childNode = node;
} else {
Element element = out.getDocument().createElement(nodeName);
childNode = element;
out.appendChild(node, element);
if (hasAttributes) {
for (int i = 0; i < attributes.length; i++) {
attributes[i].writeAttribute(out, element, bean, val);
}
}
}
writeContent(out, childNode, bean, val);
}
public void writeNode(XrOutputWriter o, Object bean) throws IOException {
Object val = null;
if (prop != null){
val = getObjectValue(bean);
if (val == null && !hasAttributes && !hasChildNodes){
return;
}
}
o.increaseDepth();
o.write(beginTag);
if (hasAttributes) {
for (int i = 0; i < attributes.length; i++) {
attributes[i].writeAttribute(o, bean, val);
}
}
o.write(beginTagEnd);
writeContent(o, bean, val);
if (hasChildNodes){
o.decreaseDepth(true);
} else {
o.decreaseDepth(decreaseDepth);
}
o.write(endTag);
}
public void writeContent(XrOutputDocument out, Node e, Object bean, Object value) throws IOException {
if (!assocBeanValue && value != null){
String sv = getFormattedValue(value);
//TODO encode string
e.setTextContent(sv);
}
if (hasChildNodes) {
Object beanToPass = assocBeanValue ? value : bean;
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(out, e, beanToPass);
}
}
}
public void writeContent(XrOutputWriter o, Object bean, Object value) throws IOException {
if (!assocBeanValue && value != null){
String sv = getFormattedValue(value);
o.writeEncoded(sv);
}
if (hasChildNodes) {
Object beanToPass = assocBeanValue ? value : bean;
for (int i = 0; i < childNodes.length; i++) {
childNodes[i].writeNode(o, beanToPass);
}
}
}
}
@@ -1,51 +1,32 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class XrOutputDocument {
private final Document document;
public XrOutputDocument(Document document) {
this.document = document;
}
public Document getDocument() {
return document;
}
public void appendChild(Node node, Node newChild) {
if (node != null){
node.appendChild(newChild);
} else {
node = document.getDocumentElement();
if (node == null){
document.appendChild(newChild);
} else {
node.appendChild(newChild);
}
}
}
}
package com.avaje.tests.xml.runtime;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class XrOutputDocument {
private final Document document;
public XrOutputDocument(Document document) {
this.document = document;
}
public Document getDocument() {
return document;
}
public void appendChild(Node node, Node newChild) {
if (node != null){
node.appendChild(newChild);
} else {
node = document.getDocumentElement();
if (node == null){
document.appendChild(newChild);
} else {
node.appendChild(newChild);
}
}
}
}
@@ -1,67 +1,48 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.io.Writer;
public class XrOutputWriter {
final Writer writer;
public XrOutputWriter(Writer writer) {
this.writer = writer;
}
public void writeXml(Object o){
}
public void write(String s) throws IOException {
writer.write(s);
}
public void writeEncoded(String s) throws IOException {
writer.write(s);
}
int depth = -1;
public void increaseDepth() throws IOException {
depth += 1;
indent();
}
public void decreaseDepth(boolean indent) throws IOException {
if (indent) {
indent();
}
depth -= 1;
}
private void indent() throws IOException {
writer.write("\n");
for (int j = 0; j < depth; j++) {
writer.write(" ");
}
}
}
package com.avaje.tests.xml.runtime;
import java.io.IOException;
import java.io.Writer;
public class XrOutputWriter {
final Writer writer;
public XrOutputWriter(Writer writer) {
this.writer = writer;
}
public void writeXml(Object o){
}
public void write(String s) throws IOException {
writer.write(s);
}
public void writeEncoded(String s) throws IOException {
writer.write(s);
}
int depth = -1;
public void increaseDepth() throws IOException {
depth += 1;
indent();
}
public void decreaseDepth(boolean indent) throws IOException {
if (indent) {
indent();
}
depth -= 1;
}
private void indent() throws IOException {
writer.write("\n");
for (int j = 0; j < depth; j++) {
writer.write(" ");
}
}
}
@@ -1,48 +1,29 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.xml.runtime;
public class XrReadContext {
private boolean vanillaMode;
private Object bean;
public XrReadContext(Object bean) {
this.bean = bean;
}
public Object getBean() {
return bean;
}
public void setBean(Object bean) {
this.bean = bean;
}
public boolean isVanillaMode() {
return vanillaMode;
}
public void setVanillaMode(boolean vanillaMode) {
this.vanillaMode = vanillaMode;
}
}
package com.avaje.tests.xml.runtime;
public class XrReadContext {
private boolean vanillaMode;
private Object bean;
public XrReadContext(Object bean) {
this.bean = bean;
}
public Object getBean() {
return bean;
}
public void setBean(Object bean) {
this.bean = bean;
}
public boolean isVanillaMode() {
return vanillaMode;
}
public void setVanillaMode(boolean vanillaMode) {
this.vanillaMode = vanillaMode;
}
}