Permalink
Browse files

TempDir attribute in PCTCreateDatabase (#331)

Issue #326, and added #66
  • Loading branch information...
gquerret committed Dec 14, 2018
1 parent 335b2dd commit be3f853c3d1667f1d80a4aa1d717c38cd2e7365e
@@ -2,6 +2,7 @@ PCTRun=com.phenix.pct.PCTRun
PCTDynRun=com.phenix.pct.PCTDynamicRun
PCTCompile=com.phenix.pct.CompilationWrapper
PCTCompileExt=com.phenix.pct.CompilationWrapper
PCTCreateDatabase=com.phenix.pct.PCTCreateBase
PCTCreateBase=com.phenix.pct.PCTCreateBase
PCTLoadSchema=com.phenix.pct.PCTLoadSchema
PCTLoadUsers=com.phenix.pct.PCTLoadUsers
@@ -44,6 +44,7 @@
private File sourceDb = null;
private File destDir = null;
private File structFile = null;
private File tempDir = null;
private int blockSize = DEFAULT_BLOCK_SIZE;
private boolean noInit = false;
private String schema = null;
@@ -64,6 +65,9 @@
private boolean newInstance = false;
private String numsep = null;
private String numdec = null;
private String cpStream = null;
private String cpColl = null;
private String cpCase = null;

/**
* Structure file (.st)
@@ -128,6 +132,13 @@ public void setDestDir(File destDir) {
this.destDir = destDir;
}

/**
* Temp directory (-T attribute)
*/
public void setTempDir(File tempDir) {
this.tempDir = tempDir;
}

/**
* Load schema after creating database. Multiple schemas can be loaded : seperate them with
* commas e.g. dump1.df,dump2.df,dump3.df
@@ -265,6 +276,27 @@ public void setCpInternal(String cpInternal) {
this.cpInternal = cpInternal;
}

/**
* Stream code page (-cpstream attribute)
*/
public void setCpStream(String cpStream) {
this.cpStream = cpStream;
}

/**
* Collation table (-cpcoll attribute)
*/
public void setCpColl(String cpColl) {
this.cpColl = cpColl;
}

/**
* Case table (-cpcase attribute)
*/
public void setCpCase(String cpCase) {
this.cpCase = cpCase;
}

/**
* Enable new instance of the database
*
@@ -449,25 +481,8 @@ public void execute() {
// Bug #1245992 : use Project#resolveFile(String)
File f = getProject().resolveFile(sc);
if (f.isFile() && f.canRead()) {
PCTLoadSchema pls = new PCTLoadSchema();
pls.bindToOwner(this);
PCTLoadSchema pls = createLoadSchemaTask();
pls.setSrcFile(f);
pls.setDlcHome(getDlcHome());
pls.setDlcBin(getDlcBin());
pls.addPropath(propath);
pls.setIncludedPL(getIncludedPL());
pls.setFailOnError(failOnError);
pls.setNumDec(numdec);
pls.setNumSep(numsep);
for (Variable var : getEnvironmentVariables()) {
pls.addEnv(var);
}

PCTConnection pc = new PCTConnection();
pc.setDbName(dbName);
pc.setDbDir(destDir);
pc.setSingleUser(true);
pls.addDBConnection(pc);
pls.execute();
} else {
throw new BuildException(MessageFormat.format(
@@ -477,26 +492,10 @@ public void execute() {
}

if (!schemaResColl.isEmpty()) {
PCTLoadSchema pls = new PCTLoadSchema();
pls.bindToOwner(this);
pls.setDlcHome(getDlcHome());
pls.setDlcBin(getDlcBin());
pls.addPropath(propath);
pls.setIncludedPL(getIncludedPL());
pls.setFailOnError(failOnError);
pls.setNumDec(numdec);
pls.setNumSep(numsep);
for (Variable var : getEnvironmentVariables()) {
pls.addEnv(var);
}
PCTLoadSchema pls = createLoadSchemaTask();
for (ResourceCollection fs : schemaResColl) {
pls.add(fs);
}
PCTConnection pc = new PCTConnection();
pc.setDbName(dbName);
pc.setDbDir(destDir);
pc.setSingleUser(true);
pls.addDBConnection(pc);
pls.execute();
}

@@ -516,6 +515,11 @@ public void execute() {
run.setIncludedPL(getIncludedPL());
run.setProcedure(holder.getProcedure());
run.setParameters(holder.getParameters());
run.setTempDir(tempDir);
run.setCpInternal(cpInternal);
run.setCpStream(cpStream);
run.setCpColl(cpColl);
run.setCpCase(cpCase);

PCTConnection pc = new PCTConnection();
pc.setDbName(dbName);
@@ -525,20 +529,43 @@ public void execute() {
run.execute();

if (holder.getSchemaFile() != null) {
PCTLoadSchema pls = new PCTLoadSchema();
pls.bindToOwner(this);
PCTLoadSchema pls = createLoadSchemaTask();
pls.setSrcFile(holder.getSchemaFile());
pls.setDlcHome(getDlcHome());
pls.setDlcBin(getDlcBin());
pls.addPropath(propath);
pls.addDBConnection(pc);
pls.execute();

}
}
}
}

private PCTLoadSchema createLoadSchemaTask() {
PCTLoadSchema task = new PCTLoadSchema();
task.bindToOwner(this);
task.setDlcHome(getDlcHome());
task.setDlcBin(getDlcBin());
task.addPropath(propath);
task.setIncludedPL(getIncludedPL());
task.setFailOnError(failOnError);
task.setNumDec(numdec);
task.setNumSep(numsep);
task.setTempDir(tempDir);
task.setCpInternal(cpInternal);
task.setCpStream(cpStream);
task.setCpColl(cpColl);
task.setCpCase(cpCase);

for (Variable var : getEnvironmentVariables()) {
task.addEnv(var);
}

PCTConnection pc = new PCTConnection();
pc.setDbName(dbName);
pc.setDbDir(destDir);
pc.setSingleUser(true);
task.addDBConnection(pc);

return task;
}

/**
* Creates the _dbutil procopy emptyX command line
*
@@ -204,4 +204,17 @@ public void test17() {
File f4 = new File("PCTCreateBase/test17/build2/test.r");
assertTrue(f4.exists());
}

@Test(groups= {"unix", "v10"})
public void test18() {
configureProject("PCTCreateBase/test18/build.xml");
executeTarget("init");
expectBuildException("db1", "Temp dir not writable");
executeTarget("db2");
executeTarget("test");
File f = new File("PCTCreateBase/test18/build/test.r");
assertTrue(f.exists());
}


}
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<project name="PCTCreateDatabase-test18">
<taskdef resource="PCT.properties" />

<target name="init">
<mkdir dir="db1" />
<mkdir dir="db2" />
<mkdir dir="build" />
<mkdir dir="tmp" />
<chmod dir="." perm="555" />
</target>

<target name="db1">
<PCTCreateDatabase dbName="test" destDir="db1" dlcHome="${DLC}" schemaFile="schema.df" />
</target>

<target name="db2">
<PCTCreateDatabase dbName="test" destDir="db2" dlcHome="${DLC}" schemaFile="schema.df" tempDir="tmp" />
</target>

<target name="test">
<PCTCompile destDir="build" dlcHome="${DLC}" tempDir="tmp">
<fileset dir="src">
<include name="test.p" />
</fileset>
<PCTConnection dbName="test" dbDir="db2" singleUser="true" />
</PCTCompile>
</target>

</project>
@@ -0,0 +1,19 @@
UPDATE DATABASE "?"

ADD TABLE "Tab1"
LABEL ""
DESCRIPTION ""
DUMP-NAME "Tab1"

ADD FIELD "Fld1" OF "tab1" AS integer
FORMAT "9"
INITIAL "0"
LABEL "Fld1"
COLUMN-LABEL "Fld1"
ORDER 10

ADD INDEX "Tab1-PK" ON "tab1"
UNIQUE
PRIMARY
DESCRIPTION "Primary key"
INDEX-FIELD "Fld1" ASCENDING
@@ -0,0 +1,2 @@
CREATE tab1.
ASSIGN tab1.fld1 = 1.

0 comments on commit be3f853

Please sign in to comment.