Made unittest data backend for frontends and improved swing frontend.
Worked on metamodel backend and some other fixes.
This commit is contained in:
parent
1c308a684a
commit
a25e98f5d5
65 changed files with 2820 additions and 499 deletions
|
|
@ -56,7 +56,11 @@ public class LdapConnectionProviderImpl implements LdapConnectionProvider {
|
|||
}
|
||||
return lc;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
if (bindUser!=null && bindPass!=null) {
|
||||
throw new RuntimeException("Connect as: "+bindUser+" pass: "+bindPass+" message: "+e.getMessage(),e);
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eobjects.metamodel</groupId>
|
||||
<artifactId>MetaModel-core</artifactId>
|
||||
<version>2.1</version>
|
||||
<artifactId>MetaModel-full</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package net.forwardfire.vasc.backend.metamodel;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.eobjects.metamodel.DataContext;
|
||||
import org.eobjects.metamodel.csv.CsvConfiguration;
|
||||
import org.eobjects.metamodel.csv.CsvDataContext;
|
||||
|
||||
public class MetaModelDataContextCsv implements MetaModelDataContextProvider {
|
||||
|
||||
private String file = null;
|
||||
private String resource = null;
|
||||
private String url = null;
|
||||
private CsvConfiguration csvConfiguration = null;
|
||||
|
||||
public DataContext getDataContext() {
|
||||
if (csvConfiguration==null) {
|
||||
csvConfiguration = new CsvConfiguration();
|
||||
}
|
||||
CsvDataContext dataContext;
|
||||
if (file != null) {
|
||||
dataContext = new CsvDataContext(new File(file),csvConfiguration);
|
||||
} else if (url != null) {
|
||||
try {
|
||||
dataContext = new CsvDataContext(new URL(url),csvConfiguration);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Could not parse url: "+e.getMessage(),e);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("No file or url defined.");
|
||||
}
|
||||
return dataContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the file
|
||||
*/
|
||||
public String getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file the file to set
|
||||
*/
|
||||
public void setFile(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resource
|
||||
*/
|
||||
public String getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource the resource to set
|
||||
*/
|
||||
public void setResource(String resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the csvConfiguration
|
||||
*/
|
||||
public CsvConfiguration getCsvConfiguration() {
|
||||
return csvConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param csvConfiguration the csvConfiguration to set
|
||||
*/
|
||||
public void setCsvConfiguration(CsvConfiguration csvConfiguration) {
|
||||
this.csvConfiguration = csvConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package net.forwardfire.vasc.backend.metamodel;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.eobjects.metamodel.DataContext;
|
||||
import org.eobjects.metamodel.mongodb.MongoDbDataContext;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoOptions;
|
||||
import com.mongodb.ServerAddress;
|
||||
|
||||
public class MetaModelDataContextMongodb implements MetaModelDataContextProvider {
|
||||
|
||||
private String hostname = "localhost";
|
||||
private int port = 27017;
|
||||
private String database = null;
|
||||
private String username = null;
|
||||
private String password = null;
|
||||
private boolean readonly = false;
|
||||
|
||||
protected static Mongo mongo = null;
|
||||
protected static DB db = null;
|
||||
|
||||
public DataContext getDataContext() {
|
||||
MongoDbDataContext dataContext = new MongoDbDataContext(getMongodbConnection());
|
||||
return dataContext;
|
||||
}
|
||||
|
||||
public DB getMongodbConnection() {
|
||||
if (db!=null) {
|
||||
return db;
|
||||
}
|
||||
synchronized (this) {
|
||||
ServerAddress server;
|
||||
try {
|
||||
server = new ServerAddress(hostname,port);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
MongoOptions options = new MongoOptions();
|
||||
mongo = new Mongo(server,options);
|
||||
db = mongo.getDB(database);
|
||||
if (username!=null && password!=null) {
|
||||
boolean auth = db.authenticate(username, password.toCharArray());
|
||||
if (auth==false) {
|
||||
throw new RuntimeException("Could not auth to db: "+database+" with username: "+username);
|
||||
}
|
||||
}
|
||||
if (readonly) {
|
||||
db.setReadOnly(true);
|
||||
}
|
||||
//logger.info("Connection to: "+db.getName());
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hostname
|
||||
*/
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hostname the hostname to set
|
||||
*/
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param port the port to set
|
||||
*/
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the database
|
||||
*/
|
||||
public String getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param database the database to set
|
||||
*/
|
||||
public void setDatabase(String database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username the username to set
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param password the password to set
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readonly
|
||||
*/
|
||||
public boolean isReadonly() {
|
||||
return readonly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param readonly the readonly to set
|
||||
*/
|
||||
public void setReadonly(boolean readonly) {
|
||||
this.readonly = readonly;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2007-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.backend.metamodel;
|
||||
|
||||
import org.eobjects.metamodel.DataContext;
|
||||
|
||||
/**
|
||||
* Provides an metamodel datacontext object to the metamodel backend.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 25, 2012
|
||||
*/
|
||||
public interface MetaModelDataContextProvider {
|
||||
|
||||
/**
|
||||
* Returns a DB connection.
|
||||
* @return An DB connection to mongodb
|
||||
*/
|
||||
public DataContext getDataContext();
|
||||
}
|
||||
|
|
@ -23,17 +23,21 @@
|
|||
package net.forwardfire.vasc.backend.metamodel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eobjects.metamodel.DataContext;
|
||||
import org.eobjects.metamodel.UpdateCallback;
|
||||
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.Query;
|
||||
import org.eobjects.metamodel.query.SelectItem;
|
||||
import org.eobjects.metamodel.schema.Schema;
|
||||
import org.eobjects.metamodel.schema.Table;
|
||||
import org.eobjects.metamodel.update.RowUpdationBuilder;
|
||||
|
||||
import net.forwardfire.vasc.backend.AbstractVascBackend;
|
||||
import net.forwardfire.vasc.backend.VascBackendState;
|
||||
|
|
@ -53,13 +57,23 @@ import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
|||
*/
|
||||
public class MetaModelVascBackend extends AbstractVascBackend {
|
||||
|
||||
private DataContext dataContext = null;
|
||||
private MetaModelDataContextProvider dataContextProvider = null;
|
||||
private UpdateableDataContext dataContext = null;
|
||||
private String table = null;
|
||||
private String tableId = null;
|
||||
|
||||
private UpdateableDataContext getUpdateableDataContext() {
|
||||
if (dataContext!=null) {
|
||||
return dataContext;
|
||||
}
|
||||
dataContext = (UpdateableDataContext)dataContextProvider.getDataContext();
|
||||
return dataContext;
|
||||
}
|
||||
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
UpdateableDataContext dataContext = getUpdateableDataContext();
|
||||
Schema schema = dataContext.getDefaultSchema();
|
||||
Table t = schema.getTableByName(table);
|
||||
//dataContext.query().from("").select("").where("").
|
||||
Query q = dataContext.query().from(t).select(t.getColumns()).toQuery();
|
||||
DataSet ds = dataContext.executeQuery(q);
|
||||
List<Object> result = new ArrayList<Object>(50);
|
||||
|
|
@ -78,13 +92,52 @@ public class MetaModelVascBackend extends AbstractVascBackend {
|
|||
}
|
||||
|
||||
public void persist(Object object) throws VascException {
|
||||
UpdateableDataContext dataContext = getUpdateableDataContext();
|
||||
dataContext.executeUpdate(new UpdateScript() {
|
||||
public void run(UpdateCallback backendImpl) {
|
||||
Table table = backendImpl.createTable(null, "some_entries").withColumn("foo").withColumn("bar")
|
||||
.withColumn("baz").withColumn("list").execute();
|
||||
|
||||
backendImpl.insertInto(table).value("foo", 1).value("bar", "hello").execute();
|
||||
backendImpl.insertInto(table).value("foo", 2).value("bar", "world").execute();
|
||||
backendImpl.insertInto(table).value("foo", 3).value("bar", "hi").execute();
|
||||
|
||||
Map<String, Object> nestedObj = new HashMap<String, Object>();
|
||||
nestedObj.put("foo", "bar");
|
||||
nestedObj.put("123", 456);
|
||||
|
||||
backendImpl.insertInto(table).value("foo", 4).value("bar", "there").value("baz", nestedObj)
|
||||
.value("list", Arrays.asList(1, 2, 3)).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object merge(Object object) throws VascException {
|
||||
final Map<String,Object> map = (Map<String,Object>)object;
|
||||
UpdateableDataContext dataContext = getUpdateableDataContext();
|
||||
dataContext.executeUpdate(new UpdateScript() {
|
||||
public void run(UpdateCallback backendImpl) {
|
||||
RowUpdationBuilder query = backendImpl.update(table).where(tableId).equals(""+map.get(tableId));
|
||||
for (String key:map.keySet()) {
|
||||
Object value = map.get(key);
|
||||
query.value(key, value);
|
||||
}
|
||||
query.execute();
|
||||
}
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void delete(Object object) throws VascException {
|
||||
final Map<String,Object> map = (Map<String,Object>)object;
|
||||
UpdateableDataContext dataContext = getUpdateableDataContext();
|
||||
dataContext.executeUpdate(new UpdateScript() {
|
||||
public void run(UpdateCallback backendImpl) {
|
||||
backendImpl.deleteFrom(table).where(tableId).in(""+map.get(tableId)).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
|
|
@ -94,4 +147,46 @@ public class MetaModelVascBackend extends AbstractVascBackend {
|
|||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
return new MapVascEntryRecordCreator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataContextProvider
|
||||
*/
|
||||
public MetaModelDataContextProvider getDataContextProvider() {
|
||||
return dataContextProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataContextProvider the dataContextProvider to set
|
||||
*/
|
||||
public void setDataContextProvider(MetaModelDataContextProvider dataContextProvider) {
|
||||
this.dataContextProvider = dataContextProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the table
|
||||
*/
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param table the table to set
|
||||
*/
|
||||
public void setTable(String table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tableId
|
||||
*/
|
||||
public String getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableId the tableId to set
|
||||
*/
|
||||
public void setTableId(String tableId) {
|
||||
this.tableId = tableId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
|
||||
<eld:elementClass tag="metaModelBackend" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelVascBackend">
|
||||
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
|
||||
</eld:elementClass>
|
||||
<eld:elementClass tag="mongodbDataContext" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextMongodb"/>
|
||||
<eld:elementClass tag="csvDataContext" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextCsv"/>
|
||||
</eld:root>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>
|
||||
Vasc namespace for the metamodel backend
|
||||
</comment>
|
||||
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-metamodel.eld">vasc-backend-metamodel.eld</entry>
|
||||
</properties>
|
||||
Loading…
Add table
Add a link
Reference in a new issue