diff --git a/pom.xml b/pom.xml index 29d04c3..415a019 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ 4.3 - 3.1.3-SNAPSHOT + 3.2.5 2.7.3 @@ -107,18 +107,18 @@ 4.5.1 - 1.0.3 - 1.0.3 + 1.0.9 + 1.0.9 1.6.4 1.6.4 - 2.3 + 2.4 1.9.2 - 9.1-901.jdbc4 - 5.1.20 - 1.3.167 - 10.8.2.2 + 9.1-901-1.jdbc4 + 5.1.22 + 1.3.170 + 10.9.1.0 3.1.0.CR1 @@ -148,7 +148,7 @@ 2.2.1-b04 1.6.3 3.0.0.CR2 - 1.5.1-SNAPSHOT + 1.5.1 9.1.0.8 diff --git a/todo.txt b/todo.txt index aaa9bdd..c51961a 100644 --- a/todo.txt +++ b/todo.txt @@ -8,21 +8,8 @@ - demo menu - demo wiki -- hotdeploy - null list option mongo query -- sql conn limit - mongo backend limit - -Build layout: -lib/ -demo/ -deploy/ -config/ -workdir/ -logs/ - -- remote ejb3 - - encodeing select model - lcoale select model - x4o template diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java index d710dca..f293bc3 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java @@ -102,7 +102,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { i++; } if (isPageable() && state.getPageSize()>0) { - q.setFirstResult(state.getPageIndex()); + q.setFirstResult(state.getPageIndex()*state.getPageSize()); q.setMaxResults(state.getPageSize()); } List data = q.list(); diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java index 384c853..23ec150 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java @@ -102,7 +102,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend i++; } if (isPageable() && state.getPageSize()>0) { - q.setFirstResult(state.getPageIndex()); + q.setFirstResult(state.getPageIndex()*state.getPageSize()); q.setMaxResults(state.getPageSize()); } if (emTransaction) { diff --git a/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld index 674e65b..7acd82e 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld +++ b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld @@ -7,7 +7,7 @@ xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd" providerName="vasc.forwardfire.net" name="Vasc Backend JPA" - id="mod-vasc-backend-jpa" + id="vasc-backend-jpa" > Provides VASC JPA backend support. result = new ArrayList(50); try { - LDAPSearchConstraints cons = new LDAPSearchConstraints(); cons.setBatchSize( 0 ); - cons.setTimeLimit( 10000 ) ; - cons.setReferralFollowing(true); + cons.setTimeLimit(getTimeLimit() ) ; + cons.setReferralFollowing(isReferralFollowing()); connection.setConstraints(cons); int searchScope = LDAPConnection.SCOPE_ONE; String searchBase = baseDN; - //System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter); LDAPSearchResults searchResults = connection.search( - searchBase, // object to read - searchScope, // scope - read single object - ldapFilter, // search filter - null, // return all attributes - false); // return attrs and values + searchBase, // object to read + searchScope, // scope - read single object + getLdapFilter(), // search filter + null, // return all attributes + false); // return attrs and values while (searchResults.hasMore()) { LDAPEntry entry = searchResults.next(); @@ -114,7 +111,6 @@ public class LdapVascBackend extends AbstractVascBackend { Iterator i = attributeSet.iterator(); while (i.hasNext()) { LDAPAttribute attr = i.next(); - //System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue()); String[] s = attr.getStringValueArray(); if (s.length==1) { map.put(attr.getName(), attr.getStringValue()); @@ -149,14 +145,12 @@ public class LdapVascBackend extends AbstractVascBackend { String keyValue = (String)map.get(keyAttribute); LDAPSearchConstraints cons = new LDAPSearchConstraints(); cons.setBatchSize( 0 ); - cons.setTimeLimit( 10000 ) ; - cons.setReferralFollowing(true); + cons.setTimeLimit(getTimeLimit() ) ; + cons.setReferralFollowing(isReferralFollowing()); connection.setConstraints(cons); - int searchScope = LDAPConnection.SCOPE_ONE; String searchBase = baseDN; - String filter = "(&("+keyAttribute+"="+keyValue+"))"; - System.out.println("ldap filter: "+filter); + String filter = "(&"+ldapFilter+"("+keyAttribute+"="+keyValue+"))"; LDAPSearchResults searchResults = connection.search( searchBase, // object to read searchScope, // scope - read single object @@ -210,8 +204,9 @@ public class LdapVascBackend extends AbstractVascBackend { } LDAPModification[] m = new LDAPModification[mods.size()]; - mods.toArray(m); + m = mods.toArray(m); connection.modify(entry.getDN(), m); + return object; } catch (Exception e) { throw new VascException(e); @@ -270,7 +265,7 @@ public class LdapVascBackend extends AbstractVascBackend { String keyValue = (String)map.get(keyAttribute); int searchScope = LDAPConnection.SCOPE_ONE; String searchBase = baseDN; - String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))"; + String filter = "(&"+ldapFilter+"("+keyAttribute+"="+keyValue+"))"; LDAPSearchResults searchResults = connection.search( searchBase, // object to read searchScope, // scope - read single object @@ -362,4 +357,32 @@ public class LdapVascBackend extends AbstractVascBackend { public void setCreateObjectClass(String createObjectClass) { this.createObjectClass = createObjectClass; } + + /** + * @return the timeLimit + */ + public int getTimeLimit() { + return timeLimit; + } + + /** + * @param timeLimit the timeLimit to set + */ + public void setTimeLimit(int timeLimit) { + this.timeLimit = timeLimit; + } + + /** + * @return the referralFollowing + */ + public boolean isReferralFollowing() { + return referralFollowing; + } + + /** + * @param referralFollowing the referralFollowing to set + */ + public void setReferralFollowing(boolean referralFollowing) { + this.referralFollowing = referralFollowing; + } } \ No newline at end of file diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java index ee27275..becdbf6 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java @@ -26,7 +26,6 @@ import java.net.UnknownHostException; import org.eobjects.metamodel.DataContext; import org.eobjects.metamodel.mongodb.MongoDbDataContext; -import org.eobjects.metamodel.mongodb.MongoDbDataContextBean; import com.mongodb.DB; import com.mongodb.Mongo; @@ -51,13 +50,16 @@ public class MetaModelDataContextMongodb implements MetaModelDataContextProvider protected Mongo mongo = null; public DataContext getDataContext() { - MongoDbDataContextBean dataContext = new MongoDbDataContextBean(getMongodbConnection()); - dataContext.setRegisterMBean(true); - dataContext.start(); + //MongoDbDataContextBean dataContext = new MongoDbDataContextBean(getMongodbConnection()); + ///dataContext.setRegisterMBean(true); + //dataContext.start(); + //MongoDbDataContextSchemaDetector detector = new MongoDbDataContextSchemaDetector(); //detector.setDataCheckSize(10); //detector.setSearchReference(true); //DataContext dataContext = detector.new MongoDbDataContextExtended(getMongodbConnection(),detector); + + DataContext dataContext = new MongoDbDataContext(getMongodbConnection()); return dataContext; } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelSchemaAutoEntry.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelSchemaAutoEntry.java index aaed3cc..5cc39ce 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelSchemaAutoEntry.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelSchemaAutoEntry.java @@ -23,7 +23,9 @@ package net.forwardfire.vasc.backend.metamodel; import java.util.ArrayList; -import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,6 +69,8 @@ public class MetaModelSchemaAutoEntry { private String tableExclude = null; private String entryPrefix = null; private String vascGroupId = null; + private String veLinkPostfix = "_velink"; + private String veListPostfix = "_velist"; private Map resultEntries = null; private Map resultEntryGroups = null; @@ -160,11 +164,9 @@ public class MetaModelSchemaAutoEntry { if (tableName.equals(rs.getForeignTable().getName())==false) { logger.finer("Creating Link entry for: "+rs.getForeignColumns()[0].getName()+" of table: "+rs.getForeignTable().getName()); createLinkEntry(rs,ve,metaTable); - //createLinkEntry(rs,ve,metaTable,id+"_"+rs.getForeignTable().getName()+"_"+rs.getForeignColumns()[0].getName()+"_link"); } else { logger.finer("Creating List entry for: "+rs.getPrimaryColumns()[0].getName()+" of table: "+rs.getPrimaryTable().getName()); createListEntry(rs,ve,metaTable); - //createListEntry(rs,ve,metaTable,id+"_"+rs.getPrimaryTable().getName()+"_"+rs.getPrimaryColumns()[0].getName()+"_list"); } } @@ -173,7 +175,7 @@ public class MetaModelSchemaAutoEntry { } private void createLinkEntry(Relationship rs2,VascEntryLocal ve,Table metaTable) { - String id = getEntryPrefix()+"_"+metaTable.getName()+"_link"; + String id = getEntryPrefix()+"_"+rs2.getForeignTable().getName()+getVeLinkPostfix(); MetaModelVascBackend backendLink = new MetaModelVascBackend(); backendLink.setId(id+"_backend"); backendLink.setDataContextProvider(getDataContextProvider()); @@ -195,26 +197,25 @@ public class MetaModelSchemaAutoEntry { veLink.setBackendId(id+"_backend"); veLink.setPrimaryKeyFieldId(backendLink.getTableId()); veLink.setVascGroupId(getVascGroupId()); - veLink.setAccessType(VascEntryAccessType.ENTRY_LIST); + veLink.setAccessType(VascEntryAccessType.ENTRY_LINK); createFields(veLink,cols); + if (resultBackends.containsKey(backendLink.getId())==false) { + resultBackends.put(backendLink.getId(),backendLink); + resultEntries.put(veLink.getId(),veLink); + } + for (Relationship rs:rs2.getForeignTable().getRelationships()) { logger.finer("Found relation FT: "+rs.getForeignTable().getName()+" PT: "+rs.getPrimaryTable().getName()); if (rs2.getForeignTable().getName().equals(rs.getForeignTable().getName())==false) { //logger.info("Creating Link entry for: "+rs.getForeignColumns()[0].getName()+" of table: "+rs.getForeignTable().getName()); - //createLinkEntry(rs,ve,rs2.getForeignTable(),id+"_"+rs.getForeignTable().getName()+"_"+rs.getForeignColumns()[0].getName()+"_link"); + //createLinkEntry(rs,veLink,rs2.getForeignTable()); } else { logger.fine("Creating List entry for: "+rs.getPrimaryColumns()[0].getName()+" of table: "+rs.getPrimaryTable().getName()); createListEntry(rs,veLink,rs2.getForeignTable()); - //createListEntry(rs,veLink,rs2.getForeignTable(),id+"_"+rs.getPrimaryTable().getName()+"_"+rs.getPrimaryColumns()[0].getName()+"_list"); } } - if (resultBackends.containsKey(backendLink.getId())==false) { - resultBackends.put(backendLink.getId(),backendLink); - resultEntries.put(veLink.getId(),veLink); - } - DefaultVascEntryLink vle = new DefaultVascEntryLink(); vle.setId(id+"Link"); vle.setVascEntryLinkType(VascEntryLinkType.DEFAULT_TYPE); @@ -225,7 +226,7 @@ public class MetaModelSchemaAutoEntry { } private void createListEntry(Relationship rs,VascEntry ve,Table metaTable) { - String id = getEntryPrefix()+"_"+metaTable.getName()+"_list"; + String id = getEntryPrefix()+"_"+rs.getPrimaryTable().getName()+getVeListPostfix(); MetaModelVascBackend backendList = new MetaModelVascBackend(); backendList.setId(id+"_backend"); backendList.setDataContextProvider(getDataContextProvider()); @@ -263,27 +264,34 @@ public class MetaModelSchemaAutoEntry { VascSelectItemModelEntry itemModel = new VascSelectItemModelEntry(); itemModel.setEntryId(veList.getId()); - itemModel.setDisplayFieldId(veList.getDisplayNameFieldId()); + if (veList.getDisplayNameFieldId()==null) { + itemModel.setDisplayFieldId(veList.getPrimaryKeyFieldId()); // display can be null see createFields(), in vasc display is not null but defaulted on primary id. + } else { + itemModel.setDisplayFieldId(veList.getDisplayNameFieldId()); + } + vef.getVascEntryFieldType().setDataObject(itemModel); } private void createFields(VascEntryLocal ve,Column[] cols) { for (Column c:cols) { + String name = c.getName().toLowerCase(); DefaultVascEntryField vef = new DefaultVascEntryField(); vef.setId(c.getName()); vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeByClass(c.getType().getJavaEquivalentClass())); if (vef.getId().equals(ve.getPrimaryKeyFieldId())) { vef.setEditReadOnly(true); - // vef.setCreate(false); mmm + vef.setCreate(false); } if (vef.getVascEntryFieldType()==null || "TextField".equals(vef.getVascEntryFieldType().getId())) { - if (c.getName().toLowerCase().contains("desc") || c.getName().toLowerCase().contains("text")) { + if (name.contains("desc") || name.contains("text") || name.contains("comment") || name.contains("memo") ) { vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextAreaField")); } - if (c.getName().toLowerCase().contains("active")) { + if (name.contains("active")) { + vef.setDefaultValue("true"); vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField")); } /* todo if (c.getName().toLowerCase().contains("email")) { @@ -293,25 +301,55 @@ public class MetaModelSchemaAutoEntry { vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("URLField")); } */ } + + if (vef.getVascEntryFieldType()!=null && vef.getVascEntryFieldType().getAutoDetectClass()==Date.class) { + vef.setDefaultValue("now()"); + if (name.contains("create") || name.contains("modified")) { + vef.setEdit(false); + vef.setCreate(false); + } + if (name.contains("update")) { + vef.setCreate(false); + } + } + ve.addVascEntryField(vef); if (ve.getDisplayNameFieldId()==null && c.getName().equals(ve.getPrimaryKeyFieldId())==false && c.getType().getJavaEquivalentClass()==String.class) { ve.setDisplayNameFieldId(c.getName()); } } + // Disable lists when id contains; + for (VascEntryField vef:ve.getVascEntryFields()) { + String id = vef.getId().toLowerCase(); + if (ve.getDisplayNameFieldId()!=null && ve.getDisplayNameFieldId().equals(vef.getId())) { + continue; + } + if (ve.getPrimaryKeyFieldId()!=null && ve.getPrimaryKeyFieldId().equals(vef.getId())) { + continue; + } + if (vef.getList()!=null && vef.getList()==false) { + continue; + } + if ( id.contains("email") | + id.contains("phone") | + id.contains("data") | + id.contains("value") | + id.contains("create") | + id.contains("update") | + id.contains("delete") | + id.contains("classname") | + id.contains("description") + ) { + vef.setList(false); + } + } + // Some auto detection on fields so default imported list view looks oke on 8++ columns. - if (ve.getVascEntryFields().size()>8) { + if (ve.getVascEntryFields().size()>10) { List vefListIds = new ArrayList(20); + int max = 0; for (VascEntryField vef:ve.getVascEntryFields()) { - String id = vef.getId().toLowerCase(); - if ( id.contains("create") | - id.contains("update") | - id.contains("delete") | - id.contains("classname") | - id.contains("description") - ) { - vef.setList(false); - } if (ve.getDisplayNameFieldId()!=null && ve.getDisplayNameFieldId().equals(vef.getId())) { continue; } @@ -322,14 +360,15 @@ public class MetaModelSchemaAutoEntry { continue; } vefListIds.add(vef.getId()); - } - if (vefListIds.size()<8) { - List vefListFalseIds = vefListIds.subList(8-1, vefListIds.size()); - for (String key:vefListFalseIds) { - VascEntryField vef = ve.getVascEntryFieldById(key); - vef.setList(false); + max++; + if (max>8) { + break; } } + for (String key:vefListIds) { + VascEntryField vef = ve.getVascEntryFieldById(key); + vef.setList(false); + } } } @@ -406,22 +445,43 @@ public class MetaModelSchemaAutoEntry { /** * @return the resultEntries */ - public Collection getResultEntries() { - return resultEntries.values(); + public List getResultEntries() { + List result = new ArrayList(resultEntries.values()); + Collections.sort(result, new Comparator() { + @Override + public int compare(VascEntryLocal o1, VascEntryLocal o2) { + return o1.getId().compareTo(o2.getId()); + } + }); + return result; } /** * @return the resultEntryGroups */ - public Collection getResultEntryGroups() { - return resultEntryGroups.values(); + public List getResultEntryGroups() { + List result = new ArrayList(resultEntryGroups.values()); + Collections.sort(result, new Comparator() { + @Override + public int compare(VascEntryGroupLocal o1, VascEntryGroupLocal o2) { + return o1.getId().compareTo(o2.getId()); + } + }); + return result; } /** * @return the resultBackends */ - public Collection getResultBackends() { - return resultBackends.values(); + public List getResultBackends() { + List result = new ArrayList(resultBackends.values()); + Collections.sort(result, new Comparator() { + @Override + public int compare(MetaModelVascBackend o1, MetaModelVascBackend o2) { + return o1.getId().compareTo(o2.getId()); + } + }); + return result; } /** @@ -437,4 +497,32 @@ public class MetaModelSchemaAutoEntry { public void removeTable(String table) { tables.remove(table); } + + /** + * @return the veLinkPostfix + */ + public String getVeLinkPostfix() { + return veLinkPostfix; + } + + /** + * @param veLinkPostfix the veLinkPostfix to set + */ + public void setVeLinkPostfix(String veLinkPostfix) { + this.veLinkPostfix = veLinkPostfix; + } + + /** + * @return the veListPostfix + */ + public String getVeListPostfix() { + return veListPostfix; + } + + /** + * @param veListPostfix the veListPostfix to set + */ + public void setVeListPostfix(String veListPostfix) { + this.veListPostfix = veListPostfix; + } } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java index 7c4f61d..27a5c12 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java @@ -32,10 +32,13 @@ import org.eobjects.metamodel.DataContext; import org.eobjects.metamodel.UpdateableDataContext; import org.eobjects.metamodel.data.DataSet; import org.eobjects.metamodel.data.Row; +import org.eobjects.metamodel.jdbc.JdbcDataContext; +import org.eobjects.metamodel.query.OrderByItem.Direction; import org.eobjects.metamodel.query.Query; import org.eobjects.metamodel.query.SelectItem; import org.eobjects.metamodel.query.builder.SatisfiedQueryBuilder; import org.eobjects.metamodel.query.builder.SatisfiedWhereBuilder; +import org.eobjects.metamodel.schema.Column; import org.eobjects.metamodel.schema.Schema; import org.eobjects.metamodel.schema.Table; @@ -131,6 +134,14 @@ public class MetaModelVascBackend extends AbstractVascBackend { return true; } + /** + * @see net.forwardfire.vasc.backend.AbstractVascBackend#isSortable() + */ + @Override + public boolean isSortable() { + return true; + } + /** * @see net.forwardfire.vasc.backend.AbstractVascBackend#fetchTotalExecuteSize(net.forwardfire.vasc.backend.VascBackendState) */ @@ -208,8 +219,23 @@ public class MetaModelVascBackend extends AbstractVascBackend { throw new VascException("Could not get meta table for: '"+table+"'."); } Query q = createFilterQuery(state,t,false); + if (isSortable() && state.getSortField() != null) { + Column orderColumn = t.getColumnByName(state.getSortField()); + if (state.isSortAscending()) { + q.orderBy(orderColumn,Direction.ASC); + } else { + q.orderBy(orderColumn,Direction.DESC); + } + } if (isPageable() && state.getPageSize()>0) { - q.setFirstRow(state.getPageIndex()+1); // +1 for mm ? + if (state.getPageIndex()>0) { + q.setFirstRow((state.getPageIndex()*state.getPageSize())+1); // MM is 1 based ?? + + // workaround for bug in MM in jdbc/pg mode which is zero based. + if (dataContext instanceof JdbcDataContext) { + q.setFirstRow((state.getPageIndex()*state.getPageSize())+0); // MM is 1 based but sql is 0 based + } + } q.setMaxRows(state.getPageSize()); } if (crudDataContext!=null) { @@ -227,7 +253,7 @@ public class MetaModelVascBackend extends AbstractVascBackend { SelectItem[] cols = row.getSelectItems(); List keys = new ArrayList(1); keys.add(cols[0].getColumn().getName()); - UpdateableRowMapImpl rowMM = new UpdateableRowMapImpl(dataContext.getDefaultSchema().getTableByName(table),keys); + UpdateableRowMapImpl rowMM = new UpdateableRowMapImpl(dataContext.getDefaultSchema().getTableByName(table),keys,cols); for (SelectItem col:cols) { Object value = row.getValue(col); rowMM.setValue(col, value); diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MongoDbDataContextSchemaDetector.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MongoDbDataContextSchemaDetector.java index dff0b31..223eead 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MongoDbDataContextSchemaDetector.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MongoDbDataContextSchemaDetector.java @@ -46,7 +46,7 @@ public class MongoDbDataContextSchemaDetector /* implements MetaModelSchemaDetec private int dataCheckSize = 100; private boolean searchReference = true; - public MongoDbDataContextSchemaDetector() { + private MongoDbDataContextSchemaDetector() { } public class MongoDbDataContextExtended extends QueryPostprocessDataContext /* MongoDbDataContext */ { @@ -153,8 +153,10 @@ public class MongoDbDataContextSchemaDetector /* implements MetaModelSchemaDetec private boolean _closed; private volatile DBObject _dbObject; - public MongoDbDataSet(DBCursor cursor, Column[] columns, - boolean queryPostProcessed) { + public MongoDbDataSet(DBCursor cursor, Column[] columns,boolean queryPostProcessed) { + + super(columns); // create header + _cursor = cursor; _selectItems = new SelectItem[columns.length]; for (int i = 0; i < columns.length; i++) { @@ -211,7 +213,7 @@ public class MongoDbDataContextSchemaDetector /* implements MetaModelSchemaDetec Object value = _dbObject.get(key); values[i] = toValue(_selectItems[i].getColumn(), value); } - return new DefaultRow(_selectItems, values); + return new DefaultRow(getHeader(), values); } private Object toValue(Column column, Object value) { @@ -440,6 +442,7 @@ public class MongoDbDataContextSchemaDetector /* implements MetaModelSchemaDetec // Override to make public class PublicTable extends MutableTable { + private static final long serialVersionUID = 1L; public PublicTable(String name,TableType type) { super(name,type); } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractCrudDataContext.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractCrudDataContext.java index b23f7e4..9396060 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractCrudDataContext.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractCrudDataContext.java @@ -2,7 +2,6 @@ package net.forwardfire.vasc.backend.metamodel.crud; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import org.eobjects.metamodel.DataContext; @@ -45,15 +44,15 @@ abstract public class AbstractCrudDataContext implements CrudDataContext { public void persist(final UpdateableRow row) { UpdateableDataContext dataContext = abstractProviderUpdateableDataContext(); dataContext.executeUpdate(new UpdateScript() { - public void run(UpdateCallback backendImpl) { - RowInsertionBuilder query = backendImpl.insertInto(row.getTable()); - for (int i=0;i primaryKeyColumns = new ArrayList(30); Collections.addAll(primaryKeyColumns, row.getPrimaryKeys()); - for (String column:primaryKeyColumns) { - Object value = row.getValue(column); - queryWhereBuilderUpdate(qWhere,column,value,first); - first = false; - } - List columns = new ArrayList(30); + for (String column:primaryKeyColumns) { + Object value = row.getValue(column); + queryWhereBuilderUpdate(qWhere,column,value,first); + first = false; + } + List columns = new ArrayList(30); Collections.addAll(columns, row.getTable().getColumnNames()); columns.removeAll(primaryKeyColumns); for (String column:columns) { - Object value = row.getValue(column); - ((RowUpdationBuilder)qWhere).value(column, value); - } + Object value = row.getValue(column); + ((RowUpdationBuilder)qWhere).value(column, value); + } if (first==false) { ((RowUpdationBuilder)qWhere).execute(); } else { @@ -92,18 +91,18 @@ abstract public class AbstractCrudDataContext implements CrudDataContext { Object qWhere = dataContext.query().from(row.getTable()).select(row.getTable().getColumns()); boolean first = true; - for (String column:row.getPrimaryKeys()) { - Object value = row.getValue(column); - queryWhereBuilder(qWhere,column,value,first); - first = false; - } - Query mergeSelectQuery = ((SatisfiedQueryBuilder)qWhere).toQuery(); - DataSet ds = dataContext.executeQuery(mergeSelectQuery); - if (ds.next()==false) { - ds.close(); - throw new IllegalStateException("Could not fetch row after merging."); - } - UpdateableRow rowResult = wrapOrCreateToUpdateableRow(ds.getRow(),row.getTable()); + for (String column:row.getPrimaryKeys()) { + Object value = row.getValue(column); + queryWhereBuilder(qWhere,column,value,first); + first = false; + } + Query mergeSelectQuery = ((SatisfiedQueryBuilder)qWhere).toQuery(); + DataSet ds = dataContext.executeQuery(mergeSelectQuery); + if (ds.next()==false) { + ds.close(); + throw new IllegalStateException("Could not fetch row after merging."); + } + UpdateableRow rowResult = wrapOrCreateToUpdateableRow(ds.getRow(),row.getTable()); ds.close(); return rowResult; } @@ -111,131 +110,71 @@ abstract public class AbstractCrudDataContext implements CrudDataContext { public void delete(final UpdateableRow row) { UpdateableDataContext dataContext = abstractProviderUpdateableDataContext(); dataContext.executeUpdate(new UpdateScript() { - public void run(UpdateCallback backendImpl) { - Object qWhere = backendImpl.deleteFrom(row.getTable()); - boolean first = true; - for (String column:row.getPrimaryKeys()) { - Object value = row.getValue(column); - queryWhereBuilderDelete(qWhere,column,value,first); - first = false; - } - if (first==false) { - ((RowDeletionBuilder)qWhere).execute(); - } else { - ///logger.warning no where clause - } - } + public void run(UpdateCallback backendImpl) { + Object qWhere = backendImpl.deleteFrom(row.getTable()); + boolean first = true; + for (String column:row.getPrimaryKeys()) { + Object value = row.getValue(column); + queryWhereBuilderDelete(qWhere,column,value,first); + first = false; + } + if (first==false) { + ((RowDeletionBuilder)qWhere).execute(); + } else { + ///logger.warning no where clause + } + } }); } // TODO: redo these queryWhereBuilder methods to cleaner code protected Object queryWhereBuilder(Object qWhere,String key,Object value,boolean first) { - if (value instanceof Number) { - if (first) { - qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).equals((Number)value); - } else { - qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).equals((Number)value); - } - } else if (value instanceof Date) { + if (value==null) { if (first) { - qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).equals((Date)value); + qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).isNull(); } else { - qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).equals((Date)value); - } - } else if (value instanceof Boolean) { - if (first) { - qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).equals((Boolean)value); - } else { - qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).equals((Boolean)value); + qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).isNull(); } } else { - if (value==null) { - if (first) { - qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).isNull(); - } else { - qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).isNull(); - } + if (first) { + qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).isEquals(value); } else { - if (first) { - qWhere = ((SatisfiedQueryBuilder)qWhere).where(key).equals(value.toString()); - } else { - qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).equals(value.toString()); - } + qWhere = ((SatisfiedWhereBuilder)qWhere).and(key).isEquals(value); } } return qWhere; } protected Object queryWhereBuilderUpdate(Object qWhere,String key,Object value,boolean first) { - if (value instanceof Number) { - if (first) { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Number)value); - } else { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Number)value); - } - } else if (value instanceof Date) { + if (value==null) { if (first) { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Date)value); + qWhere = ((RowUpdationBuilder)qWhere).where(key).isNull(); } else { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Date)value); - } - } else if (value instanceof Boolean) { - if (first) { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Boolean)value); - } else { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals((Boolean)value); + qWhere = ((RowUpdationBuilder)qWhere).where(key).isNull(); } } else { - if (value==null) { - if (first) { - qWhere = ((RowUpdationBuilder)qWhere).where(key).isNull(); - } else { - qWhere = ((RowUpdationBuilder)qWhere).where(key).isNull(); - } + if (first) { + qWhere = ((RowUpdationBuilder)qWhere).where(key).isEquals(value); } else { - if (first) { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals(value.toString()); - } else { - qWhere = ((RowUpdationBuilder)qWhere).where(key).equals(value.toString()); - } + qWhere = ((RowUpdationBuilder)qWhere).where(key).isEquals(value); } } return qWhere; } protected Object queryWhereBuilderDelete(Object qWhere,String key,Object value,boolean first) { - if (value instanceof Number) { - if (first) { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Number)value); - } else { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Number)value); - } - } else if (value instanceof Date) { + if (value==null) { if (first) { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Date)value); + qWhere = ((RowDeletionBuilder)qWhere).where(key).isNull(); } else { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Date)value); - } - } else if (value instanceof Boolean) { - if (first) { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Boolean)value); - } else { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals((Boolean)value); + qWhere = ((RowDeletionBuilder)qWhere).where(key).isNull(); } } else { - if (value==null) { - if (first) { - qWhere = ((RowDeletionBuilder)qWhere).where(key).isNull(); - } else { - qWhere = ((RowDeletionBuilder)qWhere).where(key).isNull(); - } + if (first) { + qWhere = ((RowDeletionBuilder)qWhere).where(key).isEquals(value); } else { - if (first) { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals(value.toString()); - } else { - qWhere = ((RowDeletionBuilder)qWhere).where(key).equals(value.toString()); - } + qWhere = ((RowDeletionBuilder)qWhere).where(key).isEquals(value); } } return qWhere; diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractUpdateableRow.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractUpdateableRow.java index 131deeb..bc355e3 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractUpdateableRow.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/AbstractUpdateableRow.java @@ -22,7 +22,8 @@ abstract public class AbstractUpdateableRow extends AbstractRow implements Updat } public int indexOf(String columnName) { if (columnName==null) { - return UpdateableRow.INDEX_NOT_FOUND; + throw new NullPointerException("Can't search for null column name."); + //return UpdateableRow.INDEX_NOT_FOUND; } int index = 0; for (SelectItem si:getIndexedSelectItemList()) { @@ -31,7 +32,8 @@ abstract public class AbstractUpdateableRow extends AbstractRow implements Updat } index++; } - return UpdateableRow.INDEX_NOT_FOUND; + throw new IndexOutOfBoundsException("Can't find key of column: "+columnName); + ////return UpdateableRow.INDEX_NOT_FOUND; } public void setValue(Row row) { @@ -66,7 +68,7 @@ abstract public class AbstractUpdateableRow extends AbstractRow implements Updat if (selectItem.getSubQuerySelectItem() != null) { value = getValue(selectItem.getSubQuerySelectItem()); - style = getStyle(selectItem.getSubQuerySelectItem()); + style = getStyle(selectItem.getSubQuerySelectItem()); } if (value == null) { value = getValue(selectItem); diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/CrudDataContextImpl.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/CrudDataContextImpl.java index 09f428f..c66d947 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/CrudDataContextImpl.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/CrudDataContextImpl.java @@ -11,6 +11,7 @@ import org.eobjects.metamodel.UpdateScript; import org.eobjects.metamodel.UpdateableDataContext; import org.eobjects.metamodel.data.DataSet; import org.eobjects.metamodel.data.Row; +import org.eobjects.metamodel.query.CompiledQuery; import org.eobjects.metamodel.query.Query; import org.eobjects.metamodel.query.builder.InitFromBuilder; import org.eobjects.metamodel.query.builder.InitFromBuilderImpl; @@ -81,7 +82,7 @@ public class CrudDataContextImpl extends AbstractCrudDataContext implements Abst if (row==null) { result.addSelectItems(table.getColumns()); // create new when row is null } else { - result.addSelectItems(row.getSelectItems()); + result.addSelectItems(row.getSelectItems()); result.setValue(row); // copy all values to impl } return result; @@ -205,4 +206,12 @@ public class CrudDataContextImpl extends AbstractCrudDataContext implements Abst public DataSet executeQuery(String queryString) throws MetaModelException { return dataContextDelegate.executeQuery(queryString); } + + public CompiledQuery compileQuery(Query q) throws MetaModelException { + return dataContextDelegate.compileQuery(q); + } + + public DataSet executeQuery(CompiledQuery cq, Object... args) { + return dataContextDelegate.executeQuery(cq, args); + } } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/UpdateableRowMapImpl.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/UpdateableRowMapImpl.java index 569e4a0..84920b4 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/UpdateableRowMapImpl.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/crud/UpdateableRowMapImpl.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eobjects.metamodel.data.DataSetHeader; import org.eobjects.metamodel.data.Row; import org.eobjects.metamodel.query.SelectItem; import org.eobjects.metamodel.schema.Table; @@ -47,6 +48,9 @@ public class UpdateableRowMapImpl extends AbstractUpdateableRow { } public void setValue(int index, Object value) throws IndexOutOfBoundsException { + if (index == UpdateableRow.INDEX_NOT_FOUND) { + throw new IndexOutOfBoundsException("Can't save value without key index: "+UpdateableRow.INDEX_NOT_FOUND+" value:"+value); + } dataMap.put(index, value); } @@ -57,4 +61,8 @@ public class UpdateableRowMapImpl extends AbstractUpdateableRow { public Row getSubSelection(SelectItem[] selectItems) { return getSubSelectionFromImpl(new UpdateableRowMapImpl(table,primaryKeys,selectItems),selectItems); } + + public Row getSubSelection(DataSetHeader header) { + return getSubSelection(header.getSelectItems()); + } } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/JndiReadOnlyDataContext.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/JndiReadOnlyDataContext.java index 464aacb..afdcace 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/JndiReadOnlyDataContext.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/JndiReadOnlyDataContext.java @@ -3,6 +3,7 @@ package net.forwardfire.vasc.backend.metamodel.jndi; import org.eobjects.metamodel.DataContext; import org.eobjects.metamodel.MetaModelException; import org.eobjects.metamodel.data.DataSet; +import org.eobjects.metamodel.query.CompiledQuery; import org.eobjects.metamodel.query.Query; import org.eobjects.metamodel.query.builder.InitFromBuilder; import org.eobjects.metamodel.schema.Column; @@ -53,4 +54,12 @@ public class JndiReadOnlyDataContext /* extends DataContextProxy */ implements D public DataSet executeQuery(String queryString) throws MetaModelException { return proxyDataContext.executeQuery(queryString); } + @Override + public CompiledQuery compileQuery(Query q) throws MetaModelException { + return proxyDataContext.compileQuery(q); + } + @Override + public DataSet executeQuery(CompiledQuery cq, Object... args) { + return proxyDataContext.executeQuery(cq, args); + } } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/loader/JndiMongodbDataContextLoader.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/loader/JndiMongodbDataContextLoader.java index 6279def..9532d47 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/loader/JndiMongodbDataContextLoader.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/jndi/loader/JndiMongodbDataContextLoader.java @@ -7,7 +7,6 @@ import javax.naming.NamingException; import org.eobjects.metamodel.DataContext; import org.eobjects.metamodel.mongodb.MongoDbDataContext; -import org.eobjects.metamodel.mongodb.MongoDbDataContextBean; import com.mongodb.DB; import com.mongodb.Mongo; @@ -31,27 +30,38 @@ public class JndiMongodbDataContextLoader implements JndiDataContextLoader { } public DataContext loadDataContext(JndiDataContextLoaderConfig config) { - MongoDbDataContextBean result = null; + //MongoDbDataContextBean result = null; + DB mongoDb = null; if (useJndiResource) { config.checkBackendUrl(); - result = new MongoDbDataContextBean(getMongodbJdni(config.getJndiObjectName(),config.getBackendUrl())); + //result = new MongoDbDataContextBean(,)); + mongoDb = getMongodbJdni(config.getJndiObjectName(),config.getBackendUrl()); + } else { int mongoPort = 27017; if (config.getBackendPort()!=null && config.getBackendPort().isEmpty()==false) { mongoPort = new Integer(config.getBackendPort()); } - result = new MongoDbDataContextBean(getMongodbConnection( + mongoDb = getMongodbConnection( config.getJndiObjectName(), config.getBackendHost(), mongoPort, config.getBackendDatabase(), config.getBackendUsername(), config.getBackendPassword() - )); + ); } - result.setRegisterMBean(true); // TODO: make flag - result.start(); - return result; + //MongoDbDataContextSchemaDetector detector = new MongoDbDataContextSchemaDetector(); + //detector.setDataCheckSize(10); + //detector.setSearchReference(true); + //DataContext dataContext = detector.new MongoDbDataContextExtended(mongoDb,detector); + + DataContext dataContext = new MongoDbDataContext(mongoDb); + return dataContext; + + //result.setRegisterMBean(true); // TODO: make flag + //result.start(); + //return result; } protected DB getMongodbJdni(String objectName,String jndiName) { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendDataSelector.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendDataSelector.java index 59d0910..0c52d83 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendDataSelector.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendDataSelector.java @@ -45,9 +45,23 @@ public interface VascFrontendDataSelector extends VascFrontendEntry { public boolean isFieldEditReadOnly(VascEntryField field); public boolean isFieldList(VascEntryField field); - public List getFieldsList(); + public enum EntrySelectType { + VIEW, + LINK + } - public List getFieldsCreate(); + public enum EntryFieldSelectType { + CREATE, + LIST, + EDIT, + + ALL, + + EXPORT, + GRAPH, + SUM, + SORT + } - public List getFieldsEdit(); + public List getFields(EntryFieldSelectType type); } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendActions.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendActions.java index f6308ad..852301d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendActions.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendActions.java @@ -155,6 +155,8 @@ public class DefaultVascFrontendActions implements VascFrontendActions { // save object on backend if (persist) { entry.getVascFrontendController().getVascEntryState().getVascBackend().persist(object); + result = object; // TODO: fix persist + entry.getVascFrontendController().getVascEntryState().setTotalBackendRecords(1+entry.getVascFrontendController().getVascEntryState().getTotalBackendRecords()); } else { result = entry.getVascFrontendController().getVascEntryState().getVascBackend().merge(object); } @@ -185,6 +187,7 @@ public class DefaultVascFrontendActions implements VascFrontendActions { removeObjectFromDataList(object); entry.getVascFrontendController().getVascEntryState().setEntryDataObject(null); + entry.getVascFrontendController().getVascEntryState().setTotalBackendRecords(entry.getVascFrontendController().getVascEntryState().getTotalBackendRecords()-1); entry.getVascFrontendController().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_DELETE, object); } catch (VascException ve) { throw new VascFrontendException(ve); @@ -195,6 +198,8 @@ public class DefaultVascFrontendActions implements VascFrontendActions { * @see net.forwardfire.vasc.frontend.VascFrontendHelper#refreshData(net.forwardfire.vasc.core.VascEntry) */ public void refreshData() throws VascFrontendException { + + // Fire pre read event entry.getVascFrontendController().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_READ, null); entry.getVascFrontendController().getVascEntryState().setEntryDataObject(null); VascBackendState backendState = entry.getVascFrontendController().getVascEntryState().getVascBackendState(); @@ -213,21 +218,21 @@ public class DefaultVascFrontendActions implements VascFrontendActions { } } - // Update total every time first + // Always update total records Long total = entry.getVascFrontendController().getVascEntryState().getVascBackend().fetchTotalExecuteSize(backendState); entry.getVascFrontendController().getVascEntryState().setTotalBackendRecords(total); + // check if we need to change the current page if table size if changed in between + int pages = new Long(total/backendState.getPageSize()).intValue(); + if (backendState.getPageIndex() > pages) { + backendState.setPageIndex(pages); + } + try { // Execute to get data. entry.getVascFrontendController().getVascEntryState().setEntryDataList(entry.getVascFrontendController().getVascEntryState().getVascBackend().execute(backendState)); - // check if we need to change the current page - int pages = new Long(total/backendState.getPageSize()).intValue(); - if (backendState.getPageIndex() > pages) { - backendState.setPageIndex(pages); - entry.getVascFrontendController().getVascEntryState().setEntryDataList(entry.getVascFrontendController().getVascEntryState().getVascBackend().execute(backendState)); - } - + // Fire event post read entry.getVascFrontendController().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_READ, null); } catch (VascException ve) { throw new VascFrontendException(ve); @@ -251,12 +256,10 @@ public class DefaultVascFrontendActions implements VascFrontendActions { public void searchAction(String searchString) throws VascFrontendException { entry.getVascFrontendController().getVascEntryState().getVascBackendState().setSearchString(searchString); - entry.getVascFrontendController().getVascEntryState().getVascBackendState().setSortField(null); entry.getVascFrontendController().getVascEntryState().getVascBackendState().setPageIndex(0); entry.getVascFrontendController().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.SEARCH, searchString); - - refreshData(); + refreshData(); entry.getVascFrontendController().getVascFrontend().renderView(); } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendDataSelector.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendDataSelector.java index 86fe94f..bb83b4e 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendDataSelector.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/frontend/DefaultVascFrontendDataSelector.java @@ -23,13 +23,15 @@ package net.forwardfire.vasc.impl.frontend; import java.util.ArrayList; -import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.actions.VascAction; import net.forwardfire.vasc.frontend.VascFrontendDataSelector; +import net.forwardfire.vasc.frontend.VascFrontendDataSelector.EntryFieldSelectType; /** @@ -38,7 +40,7 @@ import net.forwardfire.vasc.frontend.VascFrontendDataSelector; * @author Willem Cazander * @version 1.0 Jun 1, 2012 */ -public class DefaultVascFrontendDataSelector implements VascFrontendDataSelector { +public class DefaultVascFrontendDataSelector implements VascFrontendDataSelector { private VascEntry entry = null; @@ -126,30 +128,48 @@ public class DefaultVascFrontendDataSelector implements VascFrontendDataSelector */ - private List filter() { + + public List getFields(final EntryFieldSelectType type) { List result = new ArrayList(50); - for (VascEntryField vef:entry.getVascEntryFields()) { - + for (VascEntryField field:entry.getVascEntryFields()) { + + if (EntryFieldSelectType.CREATE.equals(type)) { + + if (field.getCreate()!=null && field.getCreate()==false) { + continue; + } + + } else if (EntryFieldSelectType.EDIT.equals(type)) { + + if (field.getEdit()!=null && field.getEdit()==false) { + continue; + } + + } else if (EntryFieldSelectType.LIST.equals(type)) { + + if (field.getList()!=null && field.getList()==false) { + continue; + } + } + result.add(field); } + Collections.sort(result,new Comparator() { + @Override + public int compare(VascEntryField o1, VascEntryField o2) { + + if (EntryFieldSelectType.CREATE.equals(type)) { + return o1.getOrderCreate().compareTo(o2.getOrderCreate()); + } else if (EntryFieldSelectType.EDIT.equals(type)) { + return o1.getOrderEdit().compareTo(o2.getOrderEdit()); + } else { + // List is default + return o1.getOrderList().compareTo(o2.getOrderList()); + } + } + }); return result; } - public List getFieldsList() { - List result = new ArrayList(50); - result.addAll(entry.getVascEntryFields()); - return result; - } - - public List getFieldsCreate() { - List result = new ArrayList(50); - result.addAll(entry.getVascEntryFields()); - return result; - } - - public List getFieldsEdit() { - List result = new ArrayList(50); - result.addAll(entry.getVascEntryFields()); - return result; - } + } \ No newline at end of file diff --git a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld index 7335096..538777a 100644 --- a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld +++ b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld @@ -7,7 +7,7 @@ xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd" providerName="vasc.forwardfire.net" name="Vasc Config Language" - id="mod-vasc-lang" + id="vasc-lang" > @@ -22,6 +22,7 @@ + + + @@ -115,6 +118,7 @@ + diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-build/src/main/directory/conf/vasc.d/tech-admin.xml b/vasc-demo/vasc-demo-server/vasc-demo-server-build/src/main/directory/conf/vasc.d/tech-admin.xml index fb4fe1b..f2e4403 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-build/src/main/directory/conf/vasc.d/tech-admin.xml +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-build/src/main/directory/conf/vasc.d/tech-admin.xml @@ -57,27 +57,36 @@ - - + + + + + + + + + + + - + diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/ServerGuiApplication.java b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/ServerGuiApplication.java index 1b16850..0c682b9 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/ServerGuiApplication.java +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/ServerGuiApplication.java @@ -24,6 +24,7 @@ package net.forwardfire.vasc.demo.server.ui; import java.awt.AWTException; import java.awt.Color; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.MenuItem; @@ -35,7 +36,9 @@ import java.awt.event.ActionListener; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; import java.util.EventObject; +import java.util.List; import java.util.Properties; import java.util.logging.Logger; @@ -74,7 +77,8 @@ public class ServerGuiApplication extends SingleFrameApplication { mainView.setComponent(statusPanel); mainView.getFrame().setMinimumSize(new Dimension(640,480)); mainView.getFrame().setMaximumSize(new Dimension(800,600)); - + mainView.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + show(mainView); startSystemTray(); @@ -124,7 +128,11 @@ public class ServerGuiApplication extends SingleFrameApplication { } public void startupDone() { - statusPanel.startupDone(); + try { + statusPanel.startupDone(); + } finally { + getMainFrame().setCursor(Cursor.getDefaultCursor()); + } } /** @@ -231,6 +239,39 @@ public class ServerGuiApplication extends SingleFrameApplication { } catch (IOException e) { } } + + // Invert focus painters + List keys = new ArrayList(UIManager.getLookAndFeelDefaults().keySet()); + for (Object keyObj:keys) { + if ((keyObj instanceof String)==false) { + continue; + } + String key = (String)keyObj; + + if (key.endsWith("[Focused].backgroundPainter")==false & key.endsWith("[Focused].iconPainter")==false) { + continue; + } + String preKey = key.substring(0,key.indexOf("[")); + String postKey = "backgroundPainter"; + if (key.contains("iconPainter")) { + postKey = "iconPainter"; + } + + logger.finer("Flipping painters of key: "+preKey); + + Object focusPainter = UIManager.getLookAndFeelDefaults().get(preKey+"[Focused]."+postKey); + Object mouseOverPainter = UIManager.getLookAndFeelDefaults().get(preKey+"[MouseOver]."+postKey); + UIManager.getLookAndFeelDefaults().put(preKey+"[Focused]."+postKey,mouseOverPainter); + UIManager.getLookAndFeelDefaults().put(preKey+"[MouseOver]."+postKey,focusPainter); + + if (key.contains("iconPainter")) { + Object focusPainterSelected = UIManager.getLookAndFeelDefaults().get(preKey+"[Focused+Selected]."+postKey); + Object mouseOverPainterSelected = UIManager.getLookAndFeelDefaults().get(preKey+"[MouseOver+Selected]."+postKey); + UIManager.getLookAndFeelDefaults().put(preKey+"[Focused+Selected]."+postKey,mouseOverPainterSelected); + UIManager.getLookAndFeelDefaults().put(preKey+"[MouseOver+Selected]."+postKey,focusPainterSelected); + } + } + return colorName; } } diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadDialog.java b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadDialog.java index 363342b..87e7043 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadDialog.java +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadDialog.java @@ -23,6 +23,7 @@ package net.forwardfire.vasc.demo.server.ui.load; import java.awt.BorderLayout; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; @@ -194,17 +195,22 @@ public class JLoadDialog extends JDialog implements ActionListener { if (currentStep <= 0) { return; } - currentStep--; - centerPanel.removeAll(); - LoadStep step = steps.get(currentStep); - centerPanel.add(step.getPanel()); - topLabel.setText(step.getStepTitle()); - step.setupStep(model); - SwingUtilities.updateComponentTreeUI(centerPanel); - if (currentStep==0) { - prev.setEnabled(false); + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try { + currentStep--; + centerPanel.removeAll(); + LoadStep step = steps.get(currentStep); + centerPanel.add(step.getPanel()); + topLabel.setText(step.getStepTitle()); + step.setupStep(model); + SwingUtilities.updateComponentTreeUI(centerPanel); + if (currentStep==0) { + prev.setEnabled(false); + } + next.setText("Next"); + } finally { + setCursor(Cursor.getDefaultCursor()); } - next.setText("Next"); } public void gotoStepNext() { @@ -221,21 +227,26 @@ public class JLoadDialog extends JDialog implements ActionListener { if (currentStep > steps.size()-1) { return; } - LoadStep step = steps.get(currentStep); - boolean result = step.performStep(model); - if (result==false) { - return; + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try { + LoadStep step = steps.get(currentStep); + boolean result = step.performStep(model); + if (result==false) { + return; + } + currentStep++; + centerPanel.removeAll(); + step = steps.get(currentStep); + centerPanel.add(step.getPanel()); + topLabel.setText(step.getStepTitle()); + step.setupStep(model); + SwingUtilities.updateComponentTreeUI(centerPanel); + if (currentStep==steps.size()-1) { + next.setText("Finish"); + } + prev.setEnabled(true); + } finally { + setCursor(Cursor.getDefaultCursor()); } - currentStep++; - centerPanel.removeAll(); - step = steps.get(currentStep); - centerPanel.add(step.getPanel()); - topLabel.setText(step.getStepTitle()); - step.setupStep(model); - SwingUtilities.updateComponentTreeUI(centerPanel); - if (currentStep==steps.size()-1) { - next.setText("Finish"); - } - prev.setEnabled(true); } } diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadStepWriteFile.java b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadStepWriteFile.java index 93c54bb..6527d31 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadStepWriteFile.java +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/JLoadStepWriteFile.java @@ -62,7 +62,7 @@ public class JLoadStepWriteFile extends JPanel implements LoadStep,ActionListene } public String getStepTitle() { - return "Select Tables"; + return "Write xml to file."; } public JPanel getPanel() { diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/LoadVascXmlWriter.java b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/LoadVascXmlWriter.java index 5f8c031..0e80e39 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/LoadVascXmlWriter.java +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/java/net/forwardfire/vasc/demo/server/ui/load/LoadVascXmlWriter.java @@ -223,6 +223,19 @@ public class LoadVascXmlWriter { if (f.getEditReadOnly()!=null) { atts.addAttribute ("", "editReadOnly", "", "", ""+f.getEditReadOnly()); } + if (f.getDefaultValue()!=null) { + atts.addAttribute ("", "defaultValue", "", "", ""+f.getDefaultValue()); + } + if (f.getList()!=null) { + atts.addAttribute ("", "list", "", "", ""+f.getList()); + } + if (f.getEdit()!=null) { + atts.addAttribute ("", "edit", "", "", ""+f.getEdit()); + } + if (f.getCreate()!=null) { + atts.addAttribute ("", "create", "", "", ""+f.getCreate()); + } + //atts.addAttribute ("", "vascGroupId", "", "", model.groupId); xmlWriter.startElement (URI_VASC_LANG, "field", "", atts); diff --git a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/resources/net/forwardfire/vasc/demo/server/ui/resources/laf-colors.properties b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/resources/net/forwardfire/vasc/demo/server/ui/resources/laf-colors.properties index 78b4673..dc4a3c2 100644 --- a/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/resources/net/forwardfire/vasc/demo/server/ui/resources/laf-colors.properties +++ b/vasc-demo/vasc-demo-server/vasc-demo-server-core/src/main/resources/net/forwardfire/vasc/demo/server/ui/resources/laf-colors.properties @@ -1,12 +1,18 @@ + # -# Default dark red color thema for pulsefire +# yellow-purple color schema from pulsefire. # -text=#DF0A0A -info=#370A00 -control=#0A1428 -nimbusBase=#00050A -nimbusFocus=#0A6428 -nimbusOrange=#00960A -nimbusBorder=#34415E -nimbusDisabledText=#850F0F -nimbusLightBackground=#050A28 +text=#FF9900 +info=#9F3B00 +control=#5B084C +nimbusBase=#3A0053 +nimbusDisabledText=#3A0053 +nimbusFocus=#FF6600 +nimbusLightBackground=#47184D +nimbusSelectedText=#47184D +nimbusBlueGrey=#661C7D +nimbusGreen=#D2C122 +nimbusBorder=#A018D8 +nimbusSelectionBackground=#BF6204 +ComboBox.background=#380030 +TabbedPane.background=#380030 diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoSwingClient.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoSwingClient.java index e2bcad2..0cf8bcf 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoSwingClient.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoSwingClient.java @@ -22,6 +22,10 @@ package net.forwardfire.vasc.demo.client.swing; +import java.awt.Color; +import java.awt.Font; +import java.io.IOException; +import java.io.InputStream; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -36,6 +40,7 @@ import javax.naming.InitialContext; import javax.security.auth.login.LoginContext; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.UIManager; import net.forwardfire.vasc.demo.tech.ejb3.menu.VascMenuController; import net.forwardfire.vasc.demo.tech.ejb3.user.ClientUserController; @@ -70,6 +75,7 @@ public class VascDemoSwingClient extends SingleFrameApplication { protected void startup() { logger = Logger.getLogger(VascDemoSwingClient.class.getName()); + installColorsLaF(); doLogin(); VascServiceManager vc = null; @@ -187,14 +193,81 @@ public class VascDemoSwingClient extends SingleFrameApplication { return false; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Server error: "+e.getMessage()); - e.printStackTrace(); + //e.printStackTrace(); return false; } } + private String installColorsLaF() { + UIManager.put("TabbedPane.font", Font.decode("SansSerif-BOLD-12")); + UIManager.put("TitledBorder.font", Font.decode("SansSerif-BOLD-16")); + UIManager.put("FireDial.font", Font.decode("SansSerif-9")); + + String colorName = "laf-colors"; + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl==null) { + cl = this.getClass().getClassLoader(); + } + InputStream in = cl.getResourceAsStream("net/forwardfire/vasc/demo/client/swing/resources/"+colorName+".properties"); + if (in==null) { + logger.warning("Color schema not found: "+colorName); + return "unknown"; + } + try { + Properties p = new Properties(); + p.load(in); + for (Object key:p.keySet()) { + String value = p.getProperty(key.toString()); + Color colorValue = Color.decode(value); + UIManager.put(key,colorValue); + } + } catch (IOException e) { + logger.warning("Could not load color schema: "+colorName+" error: "+e.getMessage()); + } finally { + try { + in.close(); + } catch (IOException e) { + } + } + + // Invert focus painters + List keys = new ArrayList(UIManager.getLookAndFeelDefaults().keySet()); + for (Object keyObj:keys) { + if ((keyObj instanceof String)==false) { + continue; + } + String key = (String)keyObj; + + if (key.endsWith("[Focused].backgroundPainter")==false & key.endsWith("[Focused].iconPainter")==false) { + continue; + } + String preKey = key.substring(0,key.indexOf("[")); + String postKey = "backgroundPainter"; + if (key.contains("iconPainter")) { + postKey = "iconPainter"; + } + + logger.finer("Flipping painters of key: "+preKey); + + Object focusPainter = UIManager.getLookAndFeelDefaults().get(preKey+"[Focused]."+postKey); + Object mouseOverPainter = UIManager.getLookAndFeelDefaults().get(preKey+"[MouseOver]."+postKey); + UIManager.getLookAndFeelDefaults().put(preKey+"[Focused]."+postKey,mouseOverPainter); + UIManager.getLookAndFeelDefaults().put(preKey+"[MouseOver]."+postKey,focusPainter); + + if (key.contains("iconPainter")) { + Object focusPainterSelected = UIManager.getLookAndFeelDefaults().get(preKey+"[Focused+Selected]."+postKey); + Object mouseOverPainterSelected = UIManager.getLookAndFeelDefaults().get(preKey+"[MouseOver+Selected]."+postKey); + UIManager.getLookAndFeelDefaults().put(preKey+"[Focused+Selected]."+postKey,mouseOverPainterSelected); + UIManager.getLookAndFeelDefaults().put(preKey+"[MouseOver+Selected]."+postKey,focusPainterSelected); + } + } + + return colorName; + } + public String i18n(Object obj,String key,Object...params) { - if(obj==null) { throw new NullPointerException("Can't get key of null obj"); } - if (key==null) { throw new NullPointerException("key may not be null"); } + if(obj==null) { throw new NullPointerException("Can't get key of null obj"); } + if (key==null) { throw new NullPointerException("key may not be null"); } if(obj instanceof Class) { key=((Class)obj).getName()+"."+key; } else { @@ -203,23 +276,16 @@ public class VascDemoSwingClient extends SingleFrameApplication { return i18n(key,params); } - /** - * Some simple hardcoded i18n function here - * - * @param key - * @param params - * @return - */ - public String i18n(String key,Object...params) { - try { - String text = ResourceBundle.getBundle(RootApplicationBundle.class.getName()).getString(key); - if (params != null) { - MessageFormat mf = new MessageFormat(text); - text = mf.format(params, new StringBuffer(), null).toString(); - } - return text; - } catch(MissingResourceException e){ - return key; - } - } + public String i18n(String key,Object...params) { + try { + String text = ResourceBundle.getBundle(RootApplicationBundle.class.getName()).getString(key); + if (params != null) { + MessageFormat mf = new MessageFormat(text); + text = mf.format(params, new StringBuffer(), null).toString(); + } + return text; + } catch(MissingResourceException e){ + return key; + } + } } diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoUserLoginDialog.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoUserLoginDialog.java index 4688e7f..e6ed9e6 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoUserLoginDialog.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/java/net/forwardfire/vasc/demo/client/swing/VascDemoUserLoginDialog.java @@ -23,7 +23,6 @@ package net.forwardfire.vasc.demo.client.swing; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; @@ -43,6 +42,7 @@ import java.util.TimerTask; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -51,47 +51,19 @@ import javax.swing.JPasswordField; import javax.swing.JTextField; /** - * Zwaar gehacke jaas login dialog - * added features: - * - name remebering - * - focus on name field - * - alway on top - * - logo stuff - * - message field - * - *

- * Uses a Swing dialog window to query the user for answers to authentication - * questions. This can be used by a JAAS application to instantiate a - * CallbackHandler + * VascDemoUserLoginDialog used be be true jaas auth module but now only dialog. * - * @see javax.security.auth.callback + * @author Willem Cazander + * @version 1.0 Nov 10, 2012 */ public class VascDemoUserLoginDialog { - private Component parentComponent; private static final int JPasswordFieldLen = 8; private int loginTry = 0; private String connectUrl = null; private String username = null; private String password = null; - /** - * Creates a callback dialog with the default parent window. - */ - public VascDemoUserLoginDialog() { - } - - /** - * Creates a callback dialog and specify the parent window. - * - * @param parentComponent - * the parent window -- specify null for the - * default parent - */ - public VascDemoUserLoginDialog(Component parentComponent) { - this.parentComponent = parentComponent; - } - /** * An interface for recording actions to carry out if the user clicks OK for * the dialog. @@ -105,10 +77,9 @@ public class VascDemoUserLoginDialog { */ public void handle() { this.loginTry++; - /* Collect messages to display in the dialog */ final JPanel loginDesign = new JPanel(); loginDesign.setLayout(new BoxLayout(loginDesign, BoxLayout.PAGE_AXIS)); - //final Image logoImage = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/resources/images/logos/logo.png")); + final Image logoImage = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/net/forwardfire/vasc/demo/client/swing/resources/logo.png")); final JPanel logoPanel = new JPanel() { private static final long serialVersionUID = 10l; protected void paintComponent(Graphics g) { @@ -119,20 +90,14 @@ public class VascDemoUserLoginDialog { // Paint the default look of the panel. super.paintComponent(g2d); - - int offsetX = 0; // for windows systems - boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") != -1; - if (isWindows) { - offsetX += 25; - } g2d.setColor(Color.BLACK); g2d.fillRect(0,0,getWidth(),getHeight()); g2d.setColor(new Color(238,212,1)); - - //int w = (getWidth()/2)-(logoImage.getWidth(null)/2); - //int h = (getHeight()/2)-(logoImage.getHeight(null)/2); - //g2d.drawImage(logoImage, w, h, this); + + int w = (getWidth()/2)-(logoImage.getWidth(null)/2); + int h = (getHeight()/2)-(logoImage.getHeight(null)/2); + g2d.drawImage(logoImage, w, h, this); } }; logoPanel.setPreferredSize(new Dimension(200, 170)); @@ -146,13 +111,11 @@ public class VascDemoUserLoginDialog { loginDesign.add(namePanel); loginDesign.add(Box.createVerticalStrut(5)); + final List okActions = new ArrayList(2); final GridLayout messagesLayout = new GridLayout(3,2); final JPanel messages = new JPanel(); messages.setLayout(messagesLayout); - /* Collection actions to perform if the user clicks OK */ - final List okActions = new ArrayList(2); - // Add server field JLabel serverName = new JLabel("Server:"); final JTextField serverField = new JTextField(getConnectUrl()); @@ -225,6 +188,7 @@ public class VascDemoUserLoginDialog { /// JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) JOptionPane jop = new JOptionPane(loginDesign, JOptionPane.PLAIN_MESSAGE,JOptionPane.OK_CANCEL_OPTION,null,options,name); + JComponent parentComponent = null; JDialog dialog = jop.createDialog(parentComponent,"Vasc Demo Login"); // We alway request focus after the windows gets focus diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/VascDemoSwingClient.properties b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/VascDemoSwingClient.properties index 003c074..28e1472 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/VascDemoSwingClient.properties +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/VascDemoSwingClient.properties @@ -29,4 +29,5 @@ Application.homepage = http://vasc.forwardfire.org/ Application.vendorId = vasc Application.id = vascdemotech Application.lookAndFeel = com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -#Application.icon = images/icon.png +Application.icon = icon.png + diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/icon.png b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/icon.png new file mode 100644 index 0000000..3acf3fc Binary files /dev/null and b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/icon.png differ diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/laf-colors.properties b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/laf-colors.properties new file mode 100644 index 0000000..dc4a3c2 --- /dev/null +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/laf-colors.properties @@ -0,0 +1,18 @@ + +# +# yellow-purple color schema from pulsefire. +# +text=#FF9900 +info=#9F3B00 +control=#5B084C +nimbusBase=#3A0053 +nimbusDisabledText=#3A0053 +nimbusFocus=#FF6600 +nimbusLightBackground=#47184D +nimbusSelectedText=#47184D +nimbusBlueGrey=#661C7D +nimbusGreen=#D2C122 +nimbusBorder=#A018D8 +nimbusSelectionBackground=#BF6204 +ComboBox.background=#380030 +TabbedPane.background=#380030 diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/logo.png b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/logo.png new file mode 100644 index 0000000..7ca6181 Binary files /dev/null and b/vasc-demo/vasc-demo-tech/vasc-demo-tech-client-swing/src/main/resources/net/forwardfire/vasc/demo/client/swing/resources/logo.png differ diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/java/net/forwardfire/vasc/demo/tech/web/beans/I18nController.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/java/net/forwardfire/vasc/demo/tech/web/beans/I18nController.java new file mode 100644 index 0000000..77f4386 --- /dev/null +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/java/net/forwardfire/vasc/demo/tech/web/beans/I18nController.java @@ -0,0 +1,106 @@ +/* + * Copyright 2009-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.demo.tech.web.beans; + +import java.util.Collection; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +import javax.faces.context.FacesContext; + +/** + * I18nController wraps to root application bundle to skip jsf cache. + * + * @author Willem Cazander + * @version 1.0 Jan 7, 2013 + */ +public class I18nController implements Map { + + public ResourceBundle getBundle() { + Locale locale = null; + FacesContext context = FacesContext.getCurrentInstance(); + locale = context.getApplication().getDefaultLocale(); + ResourceBundle bundle = ResourceBundle.getBundle("net.forwardfire.vasc.lib.i18n.bundle.RootApplicationBundle", locale); + return bundle; + } + + @Override + public void clear() { + } + + @Override + public boolean containsKey(Object key) { + return getBundle().containsKey((String)key); + } + + @Override + public boolean containsValue(Object value) { + return false; + } + + @Override + public Set> entrySet() { + return null; + } + + @Override + public String get(Object key) { + return getBundle().getString((String)key); + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public Set keySet() { + return getBundle().keySet(); + } + + @Override + public String put(String key, String value) { + return value; + } + + @Override + public void putAll(Map arg0) { + } + + @Override + public String remove(Object key) { + return (String)key; + } + + @Override + public int size() { + return getBundle().keySet().size(); + } + + @Override + public Collection values() { + return null; + } +} \ No newline at end of file diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/webapp/WEB-INF/faces-config.xml b/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/webapp/WEB-INF/faces-config.xml index 5c870f8..c61a596 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/webapp/WEB-INF/faces-config.xml +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-web/src/main/webapp/WEB-INF/faces-config.xml @@ -7,10 +7,12 @@ > + en @@ -20,6 +22,13 @@ + + I18n map bean as workaround for jsf caching. + i18n + net.forwardfire.vasc.demo.tech.web.beans.I18nController + application + + Fixes the context path for root vs non-root deployments. contextPathController diff --git a/vasc-export/vasc-export-jr4o/src/main/java/net/forwardfire/vasc/export/jr4o/JRDynamicDataSourceVascEntry.java b/vasc-export/vasc-export-jr4o/src/main/java/net/forwardfire/vasc/export/jr4o/JRDynamicDataSourceVascEntry.java index b12be28..f996c7e 100644 --- a/vasc-export/vasc-export-jr4o/src/main/java/net/forwardfire/vasc/export/jr4o/JRDynamicDataSourceVascEntry.java +++ b/vasc-export/vasc-export-jr4o/src/main/java/net/forwardfire/vasc/export/jr4o/JRDynamicDataSourceVascEntry.java @@ -30,6 +30,7 @@ import java.util.Map; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.frontend.VascFrontendDataSelector.EntryFieldSelectType; import net.forwardfire.vasc.lib.jr4o.data.AbstractJRDynamicDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; @@ -46,6 +47,7 @@ public class JRDynamicDataSourceVascEntry extends AbstractJRDynamicDataSource { private VascEntry vascEntry = null; + private List fields = null; private long total = -1; private int index = -1; private static final String PREFIX_COLUMN = "COLUMN_"; @@ -61,6 +63,8 @@ public class JRDynamicDataSourceVascEntry extends AbstractJRDynamicDataSource { this.vascEntry = vascEntry; total = vascEntry.getVascFrontendController().getVascEntryState().getTotalBackendRecords(); + fields = vascEntry.getVascFrontendController().getVascFrontendDataSelector().getFields(EntryFieldSelectType.EXPORT); + // hackje until calc index to page and row. try { data = new ArrayList>(1000); @@ -70,7 +74,7 @@ public class JRDynamicDataSourceVascEntry extends AbstractJRDynamicDataSource { vascEntry.getVascFrontendController().getVascFrontendActions().refreshData(); for (Object o:vascEntry.getVascFrontendController().getVascEntryState().getEntryDataList()) { List row = new ArrayList(30); - for (VascEntryField c:vascEntry.getVascEntryFields()) { + for (VascEntryField c:fields) { row.add(c.getVascEntryFieldValue().getDisplayValue(c, o)); } data.add(row); @@ -90,10 +94,8 @@ public class JRDynamicDataSourceVascEntry extends AbstractJRDynamicDataSource { return data.get(index).get(Integer.parseInt(fieldName.substring(7))); } if (fieldName.startsWith(PREFIX_HEADER)) { - return "todo"; // TODO: fixme - //List fields = vascEntry.getVascEntryFields(); - //VascEntryField field = fields.get(Integer.parseInt(fieldName.substring(7))); - //return vascEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(field.getName()); + VascEntryField field = fields.get(Integer.parseInt(fieldName.substring(7))); + return vascEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(field.getName()); } throw new JRException("Unknown column name : " + fieldName); } diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntryEventListener.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntryEventListener.java index 826c08c..d2617d9 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntryEventListener.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntryEventListener.java @@ -51,7 +51,11 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener * @see net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes() */ public VascFrontendEventType[] getEventTypes() { - VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + VascFrontendEventType[] result = { + VascEntryFrontendEventListener.VascFrontendEventType.POST_READ, + VascEntryFrontendEventListener.VascFrontendEventType.POST_DELETE, + VascEntryFrontendEventListener.VascFrontendEventType.POST_UPDATE + }; return result; } diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntrySupportBean.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntrySupportBean.java index 2cc4d61..d63a118 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntrySupportBean.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascEntrySupportBean.java @@ -87,8 +87,6 @@ public class JSFVascEntrySupportBean implements Serializable { private Boolean backendMoveable = null; private Boolean backendSearchable = null; private Boolean backendPageable = null; - private Boolean sortOrder = null; - private String sortField = null; private VascEntryExport selectedExporter = null; private String selectedExporterAction = "null"; private String selectedDirectPage = "null"; @@ -441,8 +439,6 @@ public class JSFVascEntrySupportBean implements Serializable { VascEntry entry = comp.getVascEntry(); VascEntryField field = entry.getVascEntryFieldById(fieldIdString); entry.getVascFrontendController().getVascFrontendActions().sortAction(field); - sortOrder = entry.getVascFrontendController().getVascEntryState().getVascBackendState().isSortAscending(); - sortField = field.getId(); } public boolean getRenderBackAction() { @@ -855,20 +851,6 @@ public class JSFVascEntrySupportBean implements Serializable { return tablePagesDataModel; } - /** - * @return the sortOrder - */ - public Boolean getSortOrder() { - return sortOrder; - } - - /** - * @return the sortField - */ - public String getSortField() { - return sortField; - } - /** * @return the selectedExporter */ diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascFrontendRenderer.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascFrontendRenderer.java index f1fe2b1..87cdb44 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascFrontendRenderer.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascFrontendRenderer.java @@ -38,8 +38,6 @@ import net.forwardfire.vasc.frontend.web.jsf.ui.JSFList; import net.forwardfire.vasc.frontend.web.jsf.ui.JSFText; import net.forwardfire.vasc.frontend.web.jsf.ui.JSFTextArea; - - /** * Given the jsf vasc renderer its own class * @@ -56,8 +54,6 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser logger = Logger.getLogger(JSFVascFrontendRenderer.class.getName()); } - // Frontend Stuff - /** * @see net.forwardfire.vasc.frontend.VascFrontend#getFrontendType() */ @@ -65,10 +61,9 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser return "jsf"; } - protected void addUiComponents() { VascFrontendController vfd = getVascEntry().getVascFrontendController(); - + // required UI components vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_LABEL,JSFLabel.class.getName()); vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_TEXT, JSFText.class.getName()); @@ -82,7 +77,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser //vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_COLOR , JSFColorChooser.class.getName()); } - + /** * @see net.forwardfire.vasc.frontend.VascFrontend#renderDelete(java.lang.Object) */ @@ -92,7 +87,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); comp.setRenderFacetState("deleteView"); } - + /** * @see net.forwardfire.vasc.frontend.VascFrontend#renderEdit(java.lang.Object) */ @@ -114,7 +109,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser comp.getSupportBean().setSelected(selBean); } - + /** * @see net.forwardfire.vasc.frontend.VascFrontend#renderExport(net.forwardfire.vasc.core.entry.VascEntryExport) */ @@ -125,7 +120,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser comp.setRenderFacetState("exportView"); comp.getSupportBean().setSelectedExporter(exporter); } - + /** * @see net.forwardfire.vasc.frontend.VascFrontend#renderView() */ @@ -134,10 +129,5 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); comp.setRenderFacetState("listView"); - - //if (comp.getSupportBean().getSelected()!=null) { - // comp.getSupportBean().getSelected().setRealValue(false); - // comp.getSupportBean().setSelected(null); - //} } -} \ No newline at end of file +} diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponent.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponent.java index f5662ed..83d2624 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponent.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponent.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.logging.Logger; import javax.el.ValueExpression; @@ -57,63 +56,62 @@ import net.forwardfire.vasc.frontend.web.jsf.ui.JSFListModel; */ public class JSFVascUIComponent extends UIComponentBase { - public static final String FAMILY = "vasc.jsf.component.family"; - public static final String ENTRY_SUPPORT_VAR_KEY = "entrySupportVar"; - public static final String TABLE_RECORD_VAR_KEY = "tableRecordVar"; - public static final String INJECT_EDIT_FIELDS_ID = "injectEditFieldsId"; - public static final String INJECT_TABLE_OPTIONS_ID = "injectTableOptionsId"; - public static final String INJECT_TABLE_COLUMNS_ID = "injectTableColumnsId"; - public static final String DISABLE_LINK_COLUMNS = "disableLinkColumns"; - public static final String INJECT_TABLE_OPTIONS_ON_CHANGE = "injectTableOptionOnChange"; - - private JSFVascFrontendRenderer renderer = null; - private JSFVascEntrySupportBean supportBean = null; - private String renderFacetState = null; - private VascEntryLink link = null; - private VascEntryState linkState = null; - private VascEntryState state = null; - private Object stateEditId = null; - private Logger logger = null; - private Boolean initClear = null; - private String injectTableOptionOnChange = null; - - public JSFVascUIComponent() { - logger = Logger.getLogger(JSFVascUIComponent.class.getName()); - } - - public String getFamily() { - return FAMILY; - } + public static final String FAMILY = "vasc.jsf.component.family"; + public static final String ENTRY_SUPPORT_VAR_KEY = "entrySupportVar"; + public static final String TABLE_RECORD_VAR_KEY = "tableRecordVar"; + public static final String INJECT_EDIT_FIELDS_ID = "injectEditFieldsId"; + public static final String INJECT_TABLE_OPTIONS_ID = "injectTableOptionsId"; + public static final String INJECT_TABLE_COLUMNS_ID = "injectTableColumnsId"; + public static final String DISABLE_LINK_COLUMNS = "disableLinkColumns"; + public static final String INJECT_TABLE_OPTIONS_ON_CHANGE = "injectTableOptionOnChange"; + + private JSFVascFrontendRenderer renderer = null; + private JSFVascEntrySupportBean supportBean = null; + private String renderFacetState = null; + private VascEntryLink link = null; + private VascEntryState linkState = null; + private VascEntryState state = null; + private Object stateEditId = null; + private Logger logger = null; + private Boolean initClear = null; + private String injectTableOptionOnChange = null; + + public JSFVascUIComponent() { + logger = Logger.getLogger(JSFVascUIComponent.class.getName()); + } + + public String getFamily() { + return FAMILY; + } + + @Override + public Object saveState(FacesContext facesContext) { + logger.fine("Save State"); + Object values[] = new Object[5]; + values[0] = super.saveState(facesContext); + values[1] = renderer; + values[2] = supportBean; + values[3] = renderFacetState; + values[4] = this.getAttributes().get(INJECT_TABLE_OPTIONS_ON_CHANGE); + return values; + } - @Override - public Object saveState(FacesContext facesContext) { - logger.fine("Save State"); - Object values[] = new Object[5]; - values[0] = super.saveState(facesContext); - values[1] = renderer; - values[2] = supportBean; - values[3] = renderFacetState; - values[4] = this.getAttributes().get(INJECT_TABLE_OPTIONS_ON_CHANGE); - return values; + @Override + public void restoreState(FacesContext facesContext, Object state) { + logger.fine("Resotre State"); + Object values[] = (Object[])state; + super.restoreState(facesContext, values[0]); + renderer = (JSFVascFrontendRenderer) values[1]; + supportBean = (JSFVascEntrySupportBean) values[2]; + renderFacetState = (String) values[3]; + injectTableOptionOnChange = (String) values[4]; - } - - @Override - public void restoreState(FacesContext facesContext, Object state) { - logger.fine("Resotre State"); - Object values[] = (Object[])state; - super.restoreState(facesContext, values[0]); - renderer = (JSFVascFrontendRenderer) values[1]; - supportBean = (JSFVascEntrySupportBean) values[2]; - renderFacetState = (String) values[3]; - injectTableOptionOnChange = (String) values[4]; - - // TODO: check if we can move this some day... + // TODO: check if we can move this some day... String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+"}", Object.class); ve2.setValue(FacesContext.getCurrentInstance().getELContext(), getSupportBean()); - } - + } + static public JSFVascUIComponent findVascParent(UIComponent comp) { if (comp==null) { return null; @@ -146,7 +144,7 @@ public class JSFVascUIComponent extends UIComponentBase { } return null; } - + /** * Finds component with the given id */ @@ -229,7 +227,7 @@ public class JSFVascUIComponent extends UIComponentBase { // edit action copyed try { - VascEntry entry = supportBean.getVascEntry(); + VascEntry entry = supportBean.getVascEntry(); entry.getVascFrontendController().getVascEntryState().setEditCreate(false); entry.getVascFrontendController().fireVascFrontendEvent(entry, VascFrontendEventType.SELECT, rowObject); entry.getVascFrontendController().getVascEntryState().setEntryDataObject(rowObject); @@ -263,46 +261,44 @@ public class JSFVascUIComponent extends UIComponentBase { super.encodeBegin(context); } - public UIComponent getCurrentView() { - UIComponent result = getFacet(renderFacetState); - if (result==null) { - throw new IllegalArgumentException("Could not get facet: "+renderFacetState); - } - return result; - } - - public JSFVascEntrySupportBean getSupportBean() { - return supportBean; - } - - public void setRenderFacetState(String renderFacetState) { - this.renderFacetState=renderFacetState; - } - - public String getRenderFacetState() { - return renderFacetState; - } - + public UIComponent getCurrentView() { + UIComponent result = getFacet(renderFacetState); + if (result==null) { + throw new IllegalArgumentException("Could not get facet: "+renderFacetState); + } + return result; + } + + public JSFVascEntrySupportBean getSupportBean() { + return supportBean; + } + + public void setRenderFacetState(String renderFacetState) { + this.renderFacetState=renderFacetState; + } + + public String getRenderFacetState() { + return renderFacetState; + } + /** * @return the injectTableOptionOnChange */ public String getInjectTableOptionOnChange() { return injectTableOptionOnChange; } - + /** * @param injectTableOptionOnChange the injectTableOptionOnChange to set */ public void setInjectTableOptionOnChange(String injectTableOptionOnChange) { this.injectTableOptionOnChange = injectTableOptionOnChange; } - + public VascEntry createClonedVascEntry() { - - VascController vascController = (VascController)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(VascRequestFacesFilter.REQ_VASC_CONTOLLER); String entryId = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(VascRequestFacesFilter.REQ_VASC_ENTRY_ID); - + if (link!=null) { entryId = link.getVascEntryId(); } @@ -314,8 +310,6 @@ public class JSFVascUIComponent extends UIComponentBase { if (entry==null) { throw new NullPointerException("Could not get '"+entryId+"' from : "+vascController); } - - try { vascController.getVascEntryConfigController().configVascFrontendController(vascController, entry); } catch (Exception e1) { @@ -410,4 +404,4 @@ public class JSFVascUIComponent extends UIComponentBase { } } } -} \ No newline at end of file +} diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponentRenderer.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponentRenderer.java index e6e7804..0339f04 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponentRenderer.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/JSFVascUIComponentRenderer.java @@ -419,14 +419,14 @@ public class JSFVascUIComponentRenderer extends Renderer { orderUp.setId(viewRoot.createUniqueId()); orderUp.setEscape(false); orderUp.setValue("↑"); // ↑ - ValueExpression ren2 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==true and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class); + ValueExpression ren2 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".vascEntry.vascFrontendController.vascEntryState.vascBackendState.sortAscending==true and "+entrySupportVar+".vascEntry.vascFrontendController.vascEntryState.vascBackendState.sortField=='"+c.getId()+"'}", Boolean.class); orderUp.setValueExpression("rendered", ren2); HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); orderDown.setId(viewRoot.createUniqueId()); orderDown.setEscape(false); orderDown.setValue("↓"); // ↓ - ValueExpression ren3 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==false and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class); + ValueExpression ren3 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".vascEntry.vascFrontendController.vascEntryState.vascBackendState.sortAscending==false and "+entrySupportVar+".vascEntry.vascFrontendController.vascEntryState.vascBackendState.sortField=='"+c.getId()+"'}", Boolean.class); orderDown.setValueExpression("rendered", ren3); link.getChildren().add(out2); diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascDataBackendBean.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascDataBackendBean.java index fc15bb5..23712c9 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascDataBackendBean.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascDataBackendBean.java @@ -29,6 +29,7 @@ import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.frontend.VascFrontendDataSelector.EntryFieldSelectType; @@ -63,7 +64,7 @@ public class VascDataBackendBean implements Serializable { if (index>entry.getVascEntryFields().size()) { throw new IllegalArgumentException("Index is bigger then total field size: "+index); } - return entry.getVascFrontendController().getVascFrontendDataSelector().getFieldsList().get(index); + return entry.getVascFrontendController().getVascFrontendDataSelector().getFields(EntryFieldSelectType.ALL).get(index); } static public int getIndexId(VascEntryField field) { diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascRequestFacesFilter.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascRequestFacesFilter.java index 9ec938c..6154477 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascRequestFacesFilter.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontend/web/jsf/VascRequestFacesFilter.java @@ -94,20 +94,19 @@ public class VascRequestFacesFilter implements Filter { className = className.substring(atIndex+1); } try { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = className.getClass().getClassLoader(); - } - Class clazz = cl.loadClass(className); - if (classArgument==null) { - vascControllerProvider = (VascControllerProvider)clazz.newInstance(); - } else { - vascControllerProvider = (VascControllerProvider)clazz.getConstructor(String.class).newInstance(classArgument); - } + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = className.getClass().getClassLoader(); + } + Class clazz = cl.loadClass(className); + if (classArgument==null) { + vascControllerProvider = (VascControllerProvider)clazz.newInstance(); + } else { + vascControllerProvider = (VascControllerProvider)clazz.getConstructor(String.class).newInstance(classArgument); + } } catch (Exception e) { throw new ServletException("Could not create VascControllerProvider: "+e.getMessage(),e); } - } /** diff --git a/vasc-test/vasc-test-i18n/src/main/java/net/forwardfire/vasc/test/i18n/VascBundleCheckEntryKeys.java b/vasc-test/vasc-test-i18n/src/main/java/net/forwardfire/vasc/test/i18n/VascBundleCheckEntryKeys.java index 05ed4db..874ba7d 100644 --- a/vasc-test/vasc-test-i18n/src/main/java/net/forwardfire/vasc/test/i18n/VascBundleCheckEntryKeys.java +++ b/vasc-test/vasc-test-i18n/src/main/java/net/forwardfire/vasc/test/i18n/VascBundleCheckEntryKeys.java @@ -56,16 +56,25 @@ public class VascBundleCheckEntryKeys { } public Map collectVascKeys(VascEntry ve) { + String value = ve.getId(); + if (ve.getVascGroupId()!=null) { + if (value.toLowerCase().startsWith(ve.getVascGroupId().toLowerCase())) { + value = value.substring(ve.getVascGroupId().length()); + if (Character.isLetterOrDigit(value.charAt(0))==false) { + value = value.substring(1); + } + } + } Map keys = new HashMap(300); - keys.put(ve.getName(), ve.getId()); + keys.put(ve.getName(), value); keys.put(ve.getImage(), ve.getId()); - keys.put(ve.getListDescription(), ve.getId()); + keys.put(ve.getListDescription(), "View list of "+value); keys.put(ve.getListImage(), imagePrefix+ve.getId()+imagePostfix); - keys.put(ve.getEditDescription(), ve.getId()); + keys.put(ve.getEditDescription(), "Edit your "+value); keys.put(ve.getEditImage(), imagePrefix+ve.getId()+imagePostfix); - keys.put(ve.getDeleteDescription(), ve.getId()); + keys.put(ve.getDeleteDescription(), "Delete this "+value); keys.put(ve.getDeleteImage(), imagePrefix+ve.getId()+imagePostfix); - keys.put(ve.getCreateDescription(), ve.getId()); + keys.put(ve.getCreateDescription(), "Create new "+value); keys.put(ve.getCreateImage(), imagePrefix+ve.getId()+imagePostfix); for (VascEntryField vef:ve.getVascEntryFields()) { keys.put(vef.getName(), vef.getId()); diff --git a/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld index 1655f1d..725a6cb 100644 --- a/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld +++ b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld @@ -6,7 +6,7 @@ xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd" providerName="vasc.forwardfire.net" name="Vasc EJB3 Xpql query loading" - id="mod-vasc-xpql-ejb3" + id="vasc-xpql-ejb3" > queries = new HashMap(100); @PostConstruct @@ -73,117 +73,114 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa long s = System.currentTimeMillis(); Map keys = loadKeys(); - for (String key:keys.keySet()) { - String value = keys.get(key); - if (key.startsWith("load")) { - loadResource(value); - } - if ("persistenceUnit".equals(key)) { - logger.fine("getting EntityManager: "+value); - entityManager = (EntityManager)new InitialContext().lookup(value); - } - } + for (String key:keys.keySet()) { + String value = keys.get(key); + if (key.startsWith("load")) { + loadResource(value); + } + if ("persistenceUnit".equals(key)) { + logger.fine("getting EntityManager: "+value); + entityManager = (EntityManager)new InitialContext().lookup(value); + } + } long t = System.currentTimeMillis()-s; logger.info("Total loaded xpql queries: "+queries.size()+" in "+t+" ms."); } catch (Exception e) { throw new RuntimeException("Error while load xpql resources error: "+e.getMessage(),e); } } - - /** - * Loads xtes-xpql-ejb3.xml from meta-inf and gives the keys - */ - protected Map loadKeys() throws IOException { - - Properties properties = new Properties(); - - logger.fine("Getting urls"); - Enumeration e = Thread.currentThread().getContextClassLoader().getResources("META-INF/xtes-xpql-ejb3.xml"); - while(e.hasMoreElements()) { - URL u = e.nextElement(); - logger.finer("Loading reletive namespaces of: "+u+" for: META-INF/xtes-xpql-ejb3.xml"); - InputStream in = u.openStream(); - try { - properties.loadFromXML(in); - } finally { - if (in!=null) { - in.close(); - } - } - } - - - e = Thread.currentThread().getContextClassLoader().getResources("/META-INF/xtes-xpql-ejb3.xml"); - while(e.hasMoreElements()) { - URL u = e.nextElement(); - logger.finer("Loading root namespaces of: "+u+" for: /META-INF/xtes-xpql-ejb3.xml"); - InputStream in = u.openStream(); - try { - properties.loadFromXML(in); - } finally { - if (in!=null) { - in.close(); - } - } - } - logger.fine("done loading"); - - Map result = new HashMap(20); - for (Object key:properties.keySet()) { - if (key instanceof String) { - String key2 = (String) key; - String value = properties.getProperty(key2); - result.put(key2, value); - } - } - return result; - } + /** + * Loads xtes-xpql-ejb3.xml from meta-inf and gives the keys + */ + protected Map loadKeys() throws IOException { + + Properties properties = new Properties(); + logger.fine("Getting urls"); + Enumeration e = Thread.currentThread().getContextClassLoader().getResources("META-INF/xtes-xpql-ejb3.xml"); + while(e.hasMoreElements()) { + URL u = e.nextElement(); + logger.finer("Loading reletive namespaces of: "+u+" for: META-INF/xtes-xpql-ejb3.xml"); + InputStream in = u.openStream(); + try { + properties.loadFromXML(in); + } finally { + if (in!=null) { + in.close(); + } + } + } + + e = Thread.currentThread().getContextClassLoader().getResources("/META-INF/xtes-xpql-ejb3.xml"); + while(e.hasMoreElements()) { + URL u = e.nextElement(); + logger.finer("Loading root namespaces of: "+u+" for: /META-INF/xtes-xpql-ejb3.xml"); + InputStream in = u.openStream(); + try { + properties.loadFromXML(in); + } finally { + if (in!=null) { + in.close(); + } + } + } + logger.fine("done loading"); + + Map result = new HashMap(20); + for (Object key:properties.keySet()) { + if (key instanceof String) { + String key2 = (String) key; + String value = properties.getProperty(key2); + result.put(key2, value); + } + } + return result; + } - private void loadResource(String resource) { - XPQLParser parser = new XPQLParser(); - logger.fine("Try loading: "+resource); - try { + private void loadResource(String resource) { + XPQLParser parser = new XPQLParser(); + logger.fine("Try loading: "+resource); + try { parser.parseResource(resource); } catch (Exception e) { throw new RuntimeException("Could not load xpql resource: "+resource+" error: "+e.getMessage(),e); } - QueryStore store = parser.getQueryStore(); - - for (String key:store.getQueryNames()) { - Query q = store.getQuery(key); - + QueryStore store = parser.getQueryStore(); + + for (String key:store.getQueryNames()) { + Query q = store.getQuery(key); + queries.put(q.getName(),q); - String out = "\n\n=========== SQL: "+q.getName()+"\n"; - //out +=q.toSQL(q); - out +="=========== XML: "+q.getName()+"\n"; - out +=q.toXML(q); - //out +="=========== Edit: "+q.getName()+"\n"; - //out +=q.toEdit(q); - out +="=========== Prepard: "+q.getName()+"\n"; - out +=q.toPreparedSQL(q)+"\n"; - logger.finer("FOUND Query: "+out); - } - } + String out = "\n\n=========== SQL: "+q.getName()+"\n"; + //out +=q.toSQL(q); + out +="=========== XML: "+q.getName()+"\n"; + out +=q.toXML(q); + //out +="=========== Edit: "+q.getName()+"\n"; + //out +=q.toEdit(q); + out +="=========== Prepard: "+q.getName()+"\n"; + out +=q.toPreparedSQL(q)+"\n"; + logger.finer("FOUND Query: "+out); + } + } - public Query getQuery(String name) { - Query q = queries.get(name); - return q; - } - - @SuppressWarnings("unchecked") + public Query getQuery(String name) { + Query q = queries.get(name); + return q; + } + + @SuppressWarnings("unchecked") public List execute(Query query) { - String sql = query.toPreparedSQL(query); - logger.finer("Executing: "+query.getName()+" sql: "+sql); - javax.persistence.Query q2 = null; - if (Query.QueryType.hql==query.getType()) { - q2 = entityManager.createQuery(sql); - } - if (Query.QueryType.sql==query.getType()) { - q2 = entityManager.createNativeQuery(sql); - } - + String sql = query.toPreparedSQL(query); + logger.finer("Executing: "+query.getName()+" sql: "+sql); + javax.persistence.Query q2 = null; + if (Query.QueryType.hql==query.getType()) { + q2 = entityManager.createQuery(sql); + } + if (Query.QueryType.sql==query.getType()) { + q2 = entityManager.createNativeQuery(sql); + } + // TODO: move this hack to xtest xpql if (query.getProperty("limit")!=null) { int max = new Integer(query.getPropertyString("limit")); @@ -193,9 +190,8 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa int offset = new Integer(query.getPropertyString("offset")); q2.setFirstResult(offset); } - - - List options = query.getOrderQueryParameterValues(); + + List options = query.getOrderQueryParameterValues(); int i=1; for ( QueryParameterValue value : options ) { Object para = value.getValue(); @@ -208,20 +204,19 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa } return q2.getResultList(); } - - @SuppressWarnings("unchecked") + + @SuppressWarnings("unchecked") public Object executeObject(Query query) { - String sql = query.toPreparedSQL(query); - logger.finer("Executing: "+query.getName()+" sql: "+sql); - javax.persistence.Query q2 = null; - if (Query.QueryType.hql==query.getType()) { - q2 = entityManager.createQuery(sql); - } - if (Query.QueryType.sql==query.getType()) { - q2 = entityManager.createNativeQuery(sql); - } - - + String sql = query.toPreparedSQL(query); + logger.finer("Executing: "+query.getName()+" sql: "+sql); + javax.persistence.Query q2 = null; + if (Query.QueryType.hql==query.getType()) { + q2 = entityManager.createQuery(sql); + } + if (Query.QueryType.sql==query.getType()) { + q2 = entityManager.createNativeQuery(sql); + } + // TODO: move this hack to xtest xpql if (query.getProperty("limit")!=null) { int max = new Integer(query.getPropertyString("limit")); @@ -231,8 +226,8 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa int offset = new Integer(query.getPropertyString("offset")); q2.setFirstResult(offset); } - - List options = query.getOrderQueryParameterValues(); + + List options = query.getOrderQueryParameterValues(); int i=1; for ( QueryParameterValue value : options ) { Object para = value.getValue(); @@ -255,9 +250,9 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa } } return result; - } catch (Exception se) { - throw new RuntimeException("Transaction error: "+se.getMessage(),se); - } + } catch (Exception se) { + throw new RuntimeException("Transaction error: "+se.getMessage(),se); + } } public List execute(String name,Map parameters) { @@ -283,59 +278,59 @@ public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryMa } public Integer executeUpdate(Query query) { - String sql = query.toPreparedSQL(query); - logger.fine("Executing: "+query.getName()+" sql: "+sql); - try { - javax.persistence.Query q2 = null; - if (Query.QueryType.hql==query.getType()) { - q2 = entityManager.createQuery(sql); - List options = query.getOrderQueryParameterValues(); - int i=1; - for ( QueryParameterValue value : options ) { - Object para = value.getValue(); - if(para==null) { - para = value.getDefaultValue(); - } - logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName()); - q2.setParameter(i,para); - i++; - } - utx.begin(); - Integer result = q2.executeUpdate(); - utx.commit(); - return result; - } - - if (Query.QueryType.sql==query.getType()) { - q2 = entityManager.createNativeQuery(sql); - List options = query.getOrderQueryParameterValues(); - int i=1; - for ( QueryParameterValue value : options ) { - Object para = value.getValue(); - if(para==null) { - para = value.getDefaultValue(); - } - logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName()); - q2.setParameter(i,para); - i++; - } - utx.begin(); - Integer result = q2.executeUpdate(); + String sql = query.toPreparedSQL(query); + logger.fine("Executing: "+query.getName()+" sql: "+sql); + try { + javax.persistence.Query q2 = null; + if (Query.QueryType.hql==query.getType()) { + q2 = entityManager.createQuery(sql); + List options = query.getOrderQueryParameterValues(); + int i=1; + for ( QueryParameterValue value : options ) { + Object para = value.getValue(); + if(para==null) { + para = value.getDefaultValue(); + } + logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName()); + q2.setParameter(i,para); + i++; + } + utx.begin(); + Integer result = q2.executeUpdate(); utx.commit(); - return result; - } - } catch (Exception se) { - throw new RuntimeException("Transaction error: "+se.getMessage(),se); - } - throw new IllegalStateException("unknow query type"); + return result; + } + + if (Query.QueryType.sql==query.getType()) { + q2 = entityManager.createNativeQuery(sql); + List options = query.getOrderQueryParameterValues(); + int i=1; + for ( QueryParameterValue value : options ) { + Object para = value.getValue(); + if(para==null) { + para = value.getDefaultValue(); + } + logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName()); + q2.setParameter(i,para); + i++; + } + utx.begin(); + Integer result = q2.executeUpdate(); + utx.commit(); + return result; + } + } catch (Exception se) { + throw new RuntimeException("Transaction error: "+se.getMessage(),se); + } + throw new IllegalStateException("unknow query type"); } public Integer executeUpdate(String name,Map parameters) { Query query = getQuery(name); for (String key:parameters.keySet()) { - Object value = parameters.get(key); - query.setQueryParameter(key, value); - } + Object value = parameters.get(key); + query.setQueryParameter(key, value); + } return executeUpdate(query); } } diff --git a/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld index 0f11ea6..43752f3 100644 --- a/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld +++ b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld @@ -6,7 +6,7 @@ xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd" providerName="vasc.forwardfire.net" name="Xpql query loading" - id="mod-vasc-xpql" + id="vasc-xpql" >