Skip to content

Commit

Permalink
Improved ConfigEntities
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Feb 6, 2015
1 parent 96233e1 commit 6eccd2e
Show file tree
Hide file tree
Showing 34 changed files with 1,254 additions and 28 deletions.
42 changes: 41 additions & 1 deletion pom.xml
Expand Up @@ -92,6 +92,19 @@
</plugin>-->
</plugins>
</build>

<!-- Make sure that the Log4J API and Log4J Core versionw stay in sync-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

Expand All @@ -108,7 +121,7 @@
<version>4.10</version>
<scope>test</scope>
</dependency>

<!-- <version>2.1</version>-->
<!-- LICENSE INFORMATION
Groovy:2.2.2
Apache 2 License
Expand All @@ -121,6 +134,33 @@
<groupId>org.codehaus.groovy</groupId>
<version>2.2.2</version>
</dependency>

<!-- The logger "Log4j2" was selected because of license terms (SLF4J (MIT), Logback(LGPL)) -->
<!-- LICENSE INFORMATION
Log4j2:2.1
Apache 2 License
http://logging.apache.org/log4j/2.x/license.html
2015-01-05
permin
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<!-- LICENSE INFORMATION
Log4j2:2.1
Apache 2 License
http://logging.apache.org/log4j/2.x/license.html
2015-01-05
permin
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

</dependencies>


Expand Down
17 changes: 17 additions & 0 deletions requrements/project_model.txt
@@ -1,3 +1,20 @@
====

Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); You may not
use this file except in compliance with the License. You may obtain a copy of
the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
====

Requirement Specification
Project Model
0.0.1
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/speedment/codegen/TestConfigModel.java
Expand Up @@ -40,6 +40,13 @@ public static void main(String[] args) {

final Table table = Table.newInstance();

pm.addNewProject().setName("olle")
.addNewDbms()
.addNewSchema()
.addNewTable()
.addNewColumn()
.setName("id");

pm.add(Project.newInstance()
.setName("myProject")
.add(Dbms.newInstance()
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/speedment/orm/config/model/Column.java
Expand Up @@ -16,13 +16,20 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.annotations.Api;
import com.speedment.orm.config.model.impl.ColumnImpl;
import com.speedment.orm.config.model.parameters.ColumnCompressionTypeable;
import com.speedment.orm.config.model.parameters.FieldStorageTypeable;

/**
*
* @author pemi
*/
public interface Column extends ConfigEntity<Column, Table, ConfigEntity<?, Column, ?>> {
@Api(version = 0)
public interface Column extends
ConfigEntity<Column, Table, ConfigEntity<?, Column, ?>>,
FieldStorageTypeable<Column>,
ColumnCompressionTypeable<Column> {

public static Column newInstance() {
return new ColumnImpl();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/speedment/orm/config/model/ConfigEntity.java
Expand Up @@ -16,6 +16,7 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.annotations.Api;
import com.speedment.orm.config.ConfigParameter;
import com.speedment.util.Trees;
import java.util.Optional;
Expand All @@ -32,8 +33,13 @@
* @param <C> The type of the child class.
*/
//public abstract interface ConfigEntity<T extends ConfigEntity<T, P, C>, P extends ConfigEntity<P, ?, T>, C extends ConfigEntity<?, ?, ?>> extends Comparable<T> {
@Api(version = 0)
public abstract interface ConfigEntity<T extends ConfigEntity<T, P, C>, P extends ConfigEntity<?, ?, ?>, C extends ConfigEntity<?, ?, ?>> extends Comparable<T> {

boolean isEnabled();

T setEnabled(boolean enabled);

String getName();

T setName(CharSequence name);
Expand Down Expand Up @@ -85,6 +91,12 @@ default String getRelativeName(ConfigEntity<?, ?, ?> from) {
return Trees.walkOptional(this, PARENT_TRAVERSER, Trees.WalkingOrder.BACKWARD).map(NAME_MAPPER).collect(Collectors.joining("."));
}

default <E extends ConfigEntity> Optional<E> getParent(final Class<E> clazz) {
return (Optional<E>) Trees.walkOptional((ConfigEntity) this, PARENT_TRAVERSER, Trees.WalkingOrder.FORWARD)
.filter(e -> clazz.isAssignableFrom(e.getClass()))
.findFirst();
}

/**
* Returns a value if the ConfigEntity by definition is not existing. For
* example, a Project does not have an overlying Dbms.
Expand Down
@@ -0,0 +1,51 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.orm.config.model;

/**
* Copyright (c), Speedment AB
* @author pemi
*/
public class ConfigEntityConstant {

public static final String XMLTAG_IDXCOL = "INDEX_COLUMN";
public static final String XMLTAG_PMGR = "PROJECT_MANAGER";
public static final String XMLTAG_PROJ = "PROJECT";
public static final String XMLTAG_DBMS = "DBMS";
public static final String XMLTAG_SCH = "SCHEMA";
public static final String XMLTAG_TBL = "TABLE";
public static final String XMLTAG_COL = "COLUMN";
public static final String XMLTAG_IDX = "INDEX";
public static final String XMLTAG_FGK = "FK";
public static final String XMLTAG_FKCOL = "FK_COLUMN";
public static final String XMLTAG_PKCOL = "PK_COLUMN";
public static final String XMLATR_NAME = "NAME";
public static final String XMLATR_POS = "POSITION";
public static final String XMLATR_DFLT = "DEFAULT";
public static final String XMLATR_NULL = "NULL";
public static final String XMLATR_DEC = "DECIMALS";
public static final String XMLATR_SIZE = "SIZE";
public static final String XMLATR_TYPE = "TYPE";
public static final String XMLATR_PRI = "PRIMARY";
public static final String XMLATR_PKCOL = "PKCOLUMN";
public static final String XMLATR_PKTBL = "PKTABLE";
public static final String XMLATR_CATALOG = "CATALOG_NAME";
public static final String XMLATR_SCHEMA = "SCHEMA_NAME";
public static final String XMLATR_ASC = "ASCDESC";
public static final String XMLATR_UNI = "UNIQUE";

}
@@ -0,0 +1,48 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.orm.config.model;

import com.speedment.orm.annotations.Api;
import com.speedment.orm.platform.Component;
import com.speedment.orm.platform.SpeedmentPlatform;

/**
*
* @author pemi
*/
@Api(version = 0)
public interface ConfigEntityFactory extends Component {

static ConfigEntityFactory getInstance() {
return SpeedmentPlatform.getInstance().get(ConfigEntityFactory.class);
}

ProjectManager newProjectManager();

Project newProject();

Dbms newDbms();

Schema newSchema();

Table newTable();

Column newColumn();

Index newIndex();

}
41 changes: 39 additions & 2 deletions src/main/java/com/speedment/orm/config/model/Dbms.java
Expand Up @@ -16,16 +16,53 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.config.model.impl.DbmsImpl;
import com.speedment.orm.annotations.Api;
import com.speedment.orm.config.model.parameters.DbmsType;

/**
*
* @author pemi
*/
@Api(version = 0)
public interface Dbms extends ConfigEntity<Dbms, Project, Schema> {

public static Dbms newInstance() {
return new DbmsImpl();
return ConfigEntityFactory.getInstance().newDbms();
}

default Schema addNewSchema() {
final Schema e = Schema.newInstance();
add(e);
return e;
}

DbmsType getType();

Dbms setType(DbmsType dbmsType);

/**
*
* @param dbmsTypeName
* @return the DbmsType
* @throws IllegalArgumentException if a DbmsType for the given dbmsTypeName
* could not be found
*/
Dbms setType(CharSequence dbmsTypeName);

CharSequence getIpAddress();

Dbms setIpAddress(CharSequence ipAddress);

int getPort();

Dbms setPort(int port);

CharSequence getUsername();

Dbms setUsername(CharSequence name);

CharSequence getPassword();

Dbms setPassword(CharSequence password);

}
2 changes: 2 additions & 0 deletions src/main/java/com/speedment/orm/config/model/Index.java
Expand Up @@ -16,12 +16,14 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.annotations.Api;
import com.speedment.orm.config.model.impl.IndexImpl;

/**
*
* @author pemi
*/
@Api(version = 0)
public interface Index extends ConfigEntity<Index, Table, ConfigEntity<?, Index, ?>> {

public static Index newInstance() {
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/speedment/orm/config/model/Project.java
Expand Up @@ -16,15 +16,31 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.config.model.impl.ProjectImpl;
import com.speedment.orm.annotations.Api;

/**
*
* @author pemi
*/
@Api(version = 0)
public interface Project extends ConfigEntity<Project, ProjectManager, Dbms> {

public static Project newInstance() {
return new ProjectImpl();
return ConfigEntityFactory.getInstance().newProject();
}

default Dbms addNewDbms() {
final Dbms e = Dbms.newInstance();
add(e);
return e;
}

CharSequence getPacketName();

Project getPacketName(CharSequence packetName);

CharSequence getPacketLocation();

Project setPacketLocation(CharSequence packetLocation);

}
Expand Up @@ -16,12 +16,19 @@
*/
package com.speedment.orm.config.model;

import com.speedment.orm.annotations.Api;
import com.speedment.orm.platform.Component;

/**
*
* @author pemi
*/
@Api(version = 0)
public interface ProjectManager extends ConfigEntity<ProjectManager, ConfigEntity<?, ?, ProjectManager>, Project>, Component {

default Project addNewProject() {
final Project e = Project.newInstance();
add(e);
return e;
}
}

0 comments on commit 6eccd2e

Please sign in to comment.