Skip to content

Commit

Permalink
Moves the models related to databases to the database plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Apr 11, 2021
1 parent 0b82d9b commit 5634b6e
Show file tree
Hide file tree
Showing 43 changed files with 104 additions and 94 deletions.
7 changes: 3 additions & 4 deletions irit.gaml.extensions.database/META-INF/MANIFEST.MF
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Additions of Database Tools to GAML
Bundle-Name: Databases
Bundle-SymbolicName: irit.gaml.extensions.database;singleton:=true
Bundle-Version: 1.8.1.qualifier
Require-Bundle: msi.gama.ext,
Expand All @@ -15,6 +15,5 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-Activator: msi.gama.database.Activator
Automatic-Module-Name: irit.gaml.extensions.database
Bundle-ClassPath: lib/olap4j 1.2.0/jars/olap4j-1.2.0.jar,
lib/olap4j 1.2.0/jars/olap4j-xmla-1.2.0.jar,
.
Bundle-ClassPath: ., lib/olap4j 1.2.0/jars/olap4j-1.2.0.jar,
lib/olap4j 1.2.0/jars/olap4j-xmla-1.2.0.jar
3 changes: 2 additions & 1 deletion irit.gaml.extensions.database/build.properties
Expand Up @@ -5,4 +5,5 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/olap4j 1.2.0/jars/olap4j-1.2.0.jar,\
lib/olap4j 1.2.0/jars/olap4j-xmla-1.2.0.jar
lib/olap4j 1.2.0/jars/olap4j-xmla-1.2.0.jar,\
models/
34 changes: 34 additions & 0 deletions irit.gaml.extensions.database/models/Databases/.project
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>databases</name>
<comment>database plugin</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>msi.gama.application.gamaNature</nature>
<nature>msi.gama.application.pluginNature</nature>
</natures>
</projectDescription>
Expand Up @@ -11,7 +11,7 @@ global {
map<string, string> MySQL <- ['host'::'localhost', 'dbtype'::'MySQL', 'database'::'', 'port'::'8889', 'user'::'root', 'passwd'::'root'];
map<string, string> ORACLE <- ['host'::'localhost', 'dbtype'::'Oracle', 'database'::'', 'port'::'1433', 'user'::'sa', 'passwd'::'tmt'];
map<string, string> POSTGRES <- ['host'::'localhost', 'dbtype'::'Postgres', 'database'::'postgres', 'port'::'5432', 'user'::'postgres', 'passwd'::''];
map<string, string> SQLITE <- ['dbtype'::'sqlite', 'database'::'../../includes/meteo.db'];
map<string, string> SQLITE <- ['dbtype'::'sqlite', 'database'::'../includes/meteo.db'];
init {
write "This model will work only if the corresponding database is installed and the database management server launched." color: #red;

Expand Down
Expand Up @@ -11,7 +11,7 @@
* Note: this model could be used with any DBMS just by changing the PARAMS variable.
*
*
* NOTE: YOU SHOULD HAVE ALREADY CREATED YOUR DATABASE (meteo_DB here) AND IMPORTED THE FILE (../../includes/meteo_DB_dump.sql)
* NOTE: YOU SHOULD HAVE ALREADY CREATED YOUR DATABASE (meteo_DB here) AND IMPORTED THE FILE (../includes/meteo_DB_dump.sql)
* IN ORDER THAT THE MODEL CAN RUN PROPERLY.
* Tags: database
*/
Expand All @@ -24,7 +24,7 @@ global {
FROM meteo_table GROUP BY `idPointgrille`";
init {
write "This model will work only if the MySQL database server is installed." color: #red;
write "In addition, the database \"meteo_db\" should have be created and the data imported inside. The SQL queries are available in the file ../../includes/meteo_DB_dump.sql.";
write "In addition, the database \"meteo_db\" should have be created and the data imported inside. The SQL queries are available in the file ../includes/meteo_DB_dump.sql.";
write "";

create DB_accessor;
Expand Down
Expand Up @@ -31,7 +31,7 @@
* - Drop table
*
*
* NOTE: YOU SHOULD HAVE ALREADY CREATED YOUR DATABASE (testDB here) AND IMPORTED THE FILE (../../includes/meteo_DB_dump.sql)
* NOTE: YOU SHOULD HAVE ALREADY CREATED YOUR DATABASE (testDB here) AND IMPORTED THE FILE (../includes/meteo_DB_dump.sql)
* IN ORDER THAT THE MODEL CAN RUN PROPERLY.
* Tags: database
*/
Expand Down
Expand Up @@ -20,7 +20,7 @@
model SQLite_selectNUpdate

global {
map<string, string> PARAMS <- ['dbtype'::'sqlite', 'database'::'../../includes/emptyFile.db'];
map<string, string> PARAMS <- ['dbtype'::'sqlite', 'database'::'../includes/emptyFile.db'];
init {
write "This model will work only if the corresponding database is installed" color: #red;

Expand Down
Expand Up @@ -7,19 +7,19 @@
model DB2agentSQLite

global {
// file buildingsShp <- file('../../includes/building.shp');
// file boundsShp <- file('../../includes/bounds.shp');
// file buildingsShp <- file('../includes/building.shp');
// file boundsShp <- file('../includes/bounds.shp');
// geometry shape <- envelope(boundsShp);


map<string,string> BOUNDS <- ["dbtype"::"sqlite",
'database'::'../../includes/spatialite.db',
'database'::'../includes/spatialite.db',
//'srid'::'32648',
"select"::"SELECT AsBinary(geom) as geom FROM bounds;"
];
map<string,string> PARAMS <- ["dbtype"::"sqlite",
//'srid'::'32648',
'database'::'../../includes/spatialite.db'
'database'::'../includes/spatialite.db'
];

string QUERY <- "SELECT name, type, AsBinary(geom) as geom FROM buildings ;";
Expand Down
Expand Up @@ -16,13 +16,13 @@ model Sqlite_QGis
global {
map BOUNDS <- [//'srid'::'4326', // optinal
"dbtype"::"sqlite",
"database"::"../../includes/building.sqlite"
"database"::"../includes/building.sqlite"
,"select":: "select geom from building;"

];
map PARAMS <- [//'srid'::'4326', // optinal
"dbtype"::"sqlite",
"database"::"../../includes/building.sqlite"];
"database"::"../includes/building.sqlite"];
string QUERY <- "SELECT geom FROM building ;";
geometry shape <- envelope(BOUNDS);

Expand Down
Expand Up @@ -8,8 +8,8 @@
model agent2DB_MSSQL

global {
file buildingsShp <- file('../../includes/building.shp');
file boundsShp <- file('../../includes/bounds.shp');
file buildingsShp <- file('../includes/building.shp');
file boundsShp <- file('../includes/bounds.shp');
geometry shape <- envelope(boundsShp);
map<string,string> PARAMS <- [//'srid'::'4326', // optinal
'host'::'localhost','dbtype'::'sqlserver','database'::'GAMAMSSQL',
Expand Down
Expand Up @@ -15,8 +15,8 @@
model agent2DB_MySQL

global {
file buildingsShp <- file('../../includes/building.shp');
file boundsShp <- file('../../includes/bounds.shp');
file buildingsShp <- file('../includes/building.shp');
file boundsShp <- file('../includes/bounds.shp');
geometry shape <- envelope(boundsShp);

map<string,string> PARAMS <- ['srid'::'4326',
Expand Down
Expand Up @@ -14,8 +14,8 @@
model agent2DB_MySQL

global {
file buildingsShp <- file('../../includes/building.shp');
file boundsShp <- file('../../includes/bounds.shp');
file buildingsShp <- file('../includes/building.shp');
file boundsShp <- file('../includes/bounds.shp');
geometry shape <- envelope(boundsShp);

map<string,string> PARAMS <- [//'srid'::'4326', // optional
Expand Down
Expand Up @@ -14,7 +14,7 @@
model agent2DB_POSTGIS

global {
file buildingsShp <- file('../../includes/building.shp') ;
file buildingsShp <- file('../includes/building.shp') ;
geometry shape <- envelope(buildingsShp);

map<string,string> PARAMS <- ['srid'::'4326', // optinal postgis
Expand Down
Expand Up @@ -14,7 +14,7 @@
model agent2DB_POSTGIS

global {
file districtShp <- file('../../includes/district.shp') ;
file districtShp <- file('../includes/district.shp') ;
geometry shape <- envelope(districtShp);

map<string,string> PARAMS <- ['srid'::'32846', // 32648 represents for the WGS 84 - Zone 48 Northern.
Expand Down
Expand Up @@ -13,14 +13,14 @@
model agent2DB_SQLite

global {
file buildingsShp <- file('../../includes/building.shp');
file boundsShp <- file('../../includes/bounds.shp');
file buildingsShp <- file('../includes/building.shp');
file boundsShp <- file('../includes/bounds.shp');
geometry shape <- envelope(boundsShp);

map<string,string> PARAMS <- [
'dbtype'::'sqlite',
//'srid'::'4326', // optinal
'database'::'../../includes/spatialite.db'
'database'::'../includes/spatialite.db'

];

Expand Down
Expand Up @@ -8,7 +8,7 @@
model SQLite_selectNUpdate

global {
map PARAMS <- ['dbtype'::'sqlite','database'::'../../includes/spatialite.db'];
map PARAMS <- ['dbtype'::'sqlite','database'::'../includes/spatialite.db'];

init {
write "This model will work only if the corresponding database is installed" color: #red;
Expand Down
Expand Up @@ -141,27 +141,33 @@ public void openModelPassedAsArgument(final String modelPath) {
private IFile findAndLoadIFile(final String filePath) {
// GAMA.getGui().debug("WorkspaceModelsManager.findAndLoadIFile " + filePath);
// No error in case of an empty argument
if ( isBlank(filePath) ) { return null; }
if ( isBlank(filePath) )
return null;
final IPath path = new Path(filePath);

// 1st case: the path can be identified as a file residing in the workspace
IFile result = findInWorkspace(path);
if ( result != null ) { return result; }
if ( result != null )
return result;
// 2nd case: the path is outside the workspace
result = findOutsideWorkspace(path);
if ( result != null ) { return result; }
if ( result != null )
return result;
// DEBUG.OUT(
// "File " + filePath + " cannot be located. Please check its name and location. Arguments provided were : " +
// Arrays.toString(CommandLineArgs.getApplicationArgs()));
return null;
}

private boolean isBlank(final String cs) {
if ( cs == null ) { return true; }
if ( cs.isEmpty() ) { return true; }
if ( cs == null )
return true;
if ( cs.isEmpty() )
return true;
final int sz = cs.length();
for ( int i = 0; i < sz; i++ ) {
if ( !Character.isWhitespace(cs.charAt(i)) ) { return false; }
if ( !Character.isWhitespace(cs.charAt(i)) )
return false;
}
return true;
}
Expand All @@ -181,15 +187,17 @@ private IFile findInWorkspace(final IPath originalPath) {
} catch (final Exception e) {
return null;
}
if ( !file.exists() ) { return null; }
if ( !file.exists() )
return null;
return file;
}

private IFile findOutsideWorkspace(final IPath originalPath) {
// GAMA.getGui().debug("WorkspaceModelsManager.findOutsideWorkspace " + originalPath);
final File modelFile = new File(originalPath.toOSString());
// TODO If the file does not exist we return null (might be a good idea to check other locations)
if ( !modelFile.exists() ) { return null; }
if ( !modelFile.exists() )
return null;

// We try to find a folder containing the model file which can be considered as a project
File projectFileBean = new File(modelFile.getPath());
Expand Down Expand Up @@ -308,18 +316,14 @@ public IFolder createUnclassifiedModelsProject(final IPath location) throws Core
if ( result == MessageDialog.CANCEL ) {
project = createOrUpdateProject(UNCLASSIFIED_MODELS);
modelFolder = project.getFolder(new Path("models"));
if ( !modelFolder.exists() ) {
modelFolder.create(true, true, null);
}
if ( !modelFolder.exists() ) { modelFolder.create(true, true, null); }
} else {
final IContainer container =
(IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) dialog.getResult()[0]);
if ( container instanceof IProject ) {
project = (IProject) container;
modelFolder = project.getFolder(new Path("models"));
if ( !modelFolder.exists() ) {
modelFolder.create(true, true, null);
}
if ( !modelFolder.exists() ) { modelFolder.create(true, true, null); }
} else {
modelFolder = (IFolder) container;
}
Expand All @@ -337,11 +341,11 @@ IFile createUnclassifiedModelsProjectAndAdd(final IPath location) {
if ( iFile.exists() ) {
if ( iFile.isLinked() ) {
final IPath path = iFile.getLocation();
if ( path.equals(location) ) {
if ( path.equals(location) )
// First case, this is a linked resource to the same location. In that case, we simply return
// its name.
return iFile;
} else {
else {
// Second case, this resource is a link to another location. We create a filename that is
// guaranteed not to exist and change iFile accordingly.
iFile = createUniqueFileFrom(iFile, modelFolder);
Expand Down Expand Up @@ -454,18 +458,18 @@ private static void linkModelsToWorkspace(final Bundle bundle, final String path
findProjects(modelsRep, foundProjects);
importBuiltInProjects(bundle, core, tests, foundProjects);

if ( core ) {
stampWorkspaceFromModels();
}
if ( core ) { stampWorkspaceFromModels(); }

}

private static final FilenameFilter isDotFile = (dir, name) -> name.equals(".project");

private static void findProjects(final File folder, final Map<File, IPath> found) {
if ( folder == null ) { return; }
if ( folder == null )
return;
final File[] dotFile = folder.listFiles(isDotFile);
if ( dotFile == null ) { return; } // not a directory
if ( dotFile == null )
return;
if ( dotFile.length == 0 ) { // no .project file
final File[] files = folder.listFiles();
if ( files != null ) {
Expand Down Expand Up @@ -535,7 +539,8 @@ protected void execute(final IProgressMonitor monitor) throws CoreException {
final IProjectDescription desc = ws.newProjectDescription(name);
project.create(desc, m.split(1000));
}
if ( monitor.isCanceled() ) { throw new OperationCanceledException(); }
if ( monitor.isCanceled() )
throw new OperationCanceledException();
project.open(IResource.BACKGROUND_REFRESH, m.split(1000));
projectHandle[0] = project;
setValuesProjectDescription(project, false, false, false, null);
Expand Down Expand Up @@ -571,9 +576,7 @@ static public void setValuesProjectDescription(final IProject proj, final boolea
ids.add(TEST_NATURE);
} else if ( inPlugin ) {
ids.add(PLUGIN_NATURE);
} else if ( builtin ) {
ids.add(BUILTIN_NATURE);
}
} else if ( builtin ) { ids.add(BUILTIN_NATURE); }
desc = proj.getDescription();
desc.setNatureIds(ids.toArray(new String[ids.size()]));
// Addition of a special nature to the project.
Expand Down Expand Up @@ -614,16 +617,12 @@ public static void stampWorkspaceFromModels() {
if ( oldStamp != null ) {
final File stampFile =
new File(new Path(root.getLocation().toOSString() + File.separator + oldStamp).toOSString());
if ( stampFile.exists() ) {
stampFile.delete();
}
if ( stampFile.exists() ) { stampFile.delete(); }
}
root.setPersistentProperty(BUILTIN_PROPERTY, stamp);
final File stampFile =
new File(new Path(root.getLocation().toOSString() + File.separator + stamp).toOSString());
if ( !stampFile.exists() ) {
stampFile.createNewFile();
}
if ( !stampFile.exists() ) { stampFile.createNewFile(); }
} catch (final CoreException e) {
e.printStackTrace();
} catch (final IOException e) {
Expand All @@ -639,7 +638,8 @@ public boolean isGamaProject(final File f) throws CoreException {
IPath p = new Path(f.getAbsolutePath());
p = p.append(".project");
final IProjectDescription pd = ResourcesPlugin.getWorkspace().loadProjectDescription(p);
if ( pd.hasNature(this.GAMA_NATURE) ) { return true; }
if ( pd.hasNature(this.GAMA_NATURE) )
return true;
}
}
}
Expand Down

0 comments on commit 5634b6e

Please sign in to comment.