- Non-transient detached state

- Customizable LoginWindow
- HSQLDB now starts in window
This commit is contained in:
Konstantin Krivopustov 2009-01-22 11:37:05 +00:00
parent ba89ac87dc
commit 096e549498
11 changed files with 108 additions and 35 deletions

View File

@ -26,7 +26,7 @@
<maximumStackSize value="32" />
<properties />
</buildFile>
<buildFile url="file://$PROJECT_DIR$/db/init/db-build.xml">
<buildFile url="file://$PROJECT_DIR$/db/db-build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />

View File

@ -1,14 +1,14 @@
<?xml version="1.0"?>
<project name="cuba-db">
<property name="project.dir" location="../.."/>
<property name="project.dir" location=".."/>
<property name="root.dir" location="${project.dir}/.."/>
<import file="${root.dir}/build-inc-prj.xml"/>
<property file="${root.dir}/build.properties"/>
<property file="${project.dir}/build.properties"/>
<property name="sql.dir" location="sql"/>
<property name="sql.dir" location="init/sql"/>
<property name="sql.delimiter" value=";"/>
<path id="run-cp">
@ -17,22 +17,12 @@
<target name="run-hsqldb">
<mkdir dir="${project.dir}/data"/>
<java classpathref="run-cp" fork="true" spawn="true"
classname="org.hsqldb.Server" dir="${project.dir}/data">
<arg line="-database.0 file:${db.name} -dbname.0 ${db.name}"/>
</java>
<exec dir="${project.dir}/data" executable="cmd.exe">
<arg line="/c start ${project.dir}/db/run-hsqldb.bat ${db.name}"/>
</exec>
</target>
<target name="stop-hsqldb">
<sql classpathref="run-cp"
driver="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:hsql://localhost/${db.name}"
userid="${db.user}" password="${db.password}" onerror="continue">
shutdown
</sql>
</target>
<target name="run-hsqlman" depends="run-hsqldb">
<target name="run-hsqlman">
<java classpathref="run-cp" fork="true" spawn="true"
classname="org.hsqldb.util.DatabaseManagerSwing" dir="${project.dir}/data">
<arg line="--url jdbc:hsqldb:hsql://localhost/${db.name}"/>

2
db/run-hsqldb.bat Normal file
View File

@ -0,0 +1,2 @@
java -cp ..\..\lib\server\hsqldb-1.8.0.9.jar org.hsqldb.Server -database.0 file:%1 -dbname.0 %1
exit

View File

@ -23,6 +23,7 @@
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72"/>
<property name="openjpa.jdbc.DBDictionary" value="com.haulmont.cuba.core.sys.persistence.CubaHSQLDictionary(SimulateLocking=true)"/>
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>
<property name="openjpa.DetachState" value="loaded(DetachedStateField=true, DetachedStateManager=true)"/>
<property name="openjpa.jdbc.MappingDefaults"
value="FieldStrategies='java.util.UUID=com.haulmont.cuba.core.sys.persistence.UuidStringValueHandler'"/>
</properties>

View File

@ -11,8 +11,12 @@
package com.haulmont.cuba.core.app;
import com.haulmont.cuba.core.*;
import com.haulmont.cuba.core.global.BasicInvocationContext;
import com.haulmont.cuba.core.global.BasicServiceRemote;
import com.haulmont.cuba.core.entity.Config;
import com.haulmont.cuba.core.sys.ConfigWorker;
import com.haulmont.cuba.security.entity.Profile;
import com.haulmont.cuba.security.entity.User;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
@ -155,4 +159,34 @@ public class ConfigStorage extends ManagementBean implements ConfigStorageMBean
return ExceptionUtils.getStackTrace(e);
}
}
public String test() {
// Transaction tx = Locator.createTransaction();
try {
login();
BasicServiceRemote service = Locator.lookupRemote(BasicService.JNDI_NAME);
// BasicService service = Locator.lookupLocal(BasicService.JNDI_NAME);
BasicInvocationContext ctx = new BasicInvocationContext()
.setEntityClass(User.class).setId(UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
User user = service.load(ctx);
ctx = new BasicInvocationContext().setEntityClass(Profile.class);
ctx.setQueryString("select p from sec$Profile p where p.user = :user").addParameter("user", user);
List<Profile> profiles = service.loadList(ctx);
boolean b = false;
if (!profiles.isEmpty()) {
b = profiles.get(0).isDefaultProfile();
}
// tx.commit();
return "Done: " + b;
} catch (Exception e) {
return ExceptionUtils.getStackTrace(e);
} finally {
// tx.end();
logout();
}
}
}

View File

@ -28,5 +28,7 @@ public interface ConfigStorageMBean
String removeProperty(String name);
String loadSystemProperties();
String loadSystemProperties();
String test();
}

View File

@ -25,13 +25,13 @@ public class BaseUuidEntity implements BaseEntity<UUID>
@Id
@Column(name = "ID")
@Persistent
private UUID id;
protected UUID id;
@Column(name = "CREATE_TS")
private Date createTs;
protected Date createTs;
@Column(name = "CREATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
private String createdBy;
protected String createdBy;
public BaseUuidEntity() {
id = UuidProvider.createUuid();

View File

@ -24,19 +24,19 @@ public class StandardEntity
{
@Version
@Column(name = "VERSION")
private Integer version;
protected Integer version;
@Column(name = "UPDATE_TS")
private Date updateTs;
protected Date updateTs;
@Column(name = "UPDATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
private String updatedBy;
protected String updatedBy;
@Column(name = "DELETE_TS")
private Date deleteTs;
protected Date deleteTs;
@Column(name = "DELETED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
private String deletedBy;
protected String deletedBy;
public Integer getVersion() {
return version;

View File

@ -130,11 +130,11 @@ public class ManagedPersistenceProvider extends PersistenceProvider
new Synchronization()
{
public void beforeCompletion() {
log.trace("Closing EntityManager for transaction " + tx);
em.close();
}
public void afterCompletion(int i) {
log.trace("Closing EntityManager for transaction " + tx);
em.close();
emMap.remove(tx);
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 22.01.2009 9:12:24
*
* $Id$
*/
package com.haulmont.cuba.core;
import com.haulmont.cuba.security.entity.User;
import java.util.UUID;
import java.util.List;
public class QueryTest extends CubaTestCase
{
public void test() {
Transaction tx = Locator.createTransaction();
try {
EntityManager em = PersistenceProvider.getEntityManager();
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Query query = em.createQuery("select p from sec$Profile p where p.user = :user");
query.setParameter("user", user);
List list = query.getResultList();
assertFalse(list.isEmpty());
tx.commit();
} finally {
tx.end();
}
}
}

View File

@ -27,15 +27,21 @@ public class LoginWindow extends Window implements ApplicationContext.Transactio
{
private Connection connection;
private TextField loginField;
private TextField passwdField;
protected TextField loginField;
protected TextField passwdField;
public LoginWindow(App app, Connection connection) {
super("CUBA Login");
this.connection = connection;
app.getContext().addTransactionListener(this);
loginField = new TextField();
passwdField = new TextField();
initUI();
}
protected void initUI() {
OrderedLayout layout = new FormLayout();
layout.setSpacing(true);
layout.setMargin(true);
@ -43,11 +49,11 @@ public class LoginWindow extends Window implements ApplicationContext.Transactio
Label label = new Label("Welcome to CUBA!");
layout.addComponent(label);
loginField = new TextField("Login Name");
loginField.setCaption("Login Name");
layout.addComponent(loginField);
loginField.focus();
passwdField = new TextField("Password");
passwdField.setCaption("Password");
passwdField.setSecret(true);
layout.addComponent(passwdField);
@ -59,7 +65,7 @@ public class LoginWindow extends Window implements ApplicationContext.Transactio
setLayout(layout);
}
private void initFields() {
protected void initFields() {
if (ActiveDirectoryHelper.useActiveDirectory()) {
loginField.setValue(null);
passwdField.setValue("");
@ -94,7 +100,7 @@ public class LoginWindow extends Window implements ApplicationContext.Transactio
public void transactionEnd(Application application, Object transactionData) {
}
protected class SubmitListener implements Button.ClickListener
public class SubmitListener implements Button.ClickListener
{
public void buttonClick(Button.ClickEvent event) {
String login = (String) loginField.getValue();