Skip to content

Commit

Permalink
Support for reading DBMS schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Mar 18, 2015
1 parent 7f812a0 commit e5e3b7f
Show file tree
Hide file tree
Showing 16 changed files with 608 additions and 40 deletions.
12 changes: 10 additions & 2 deletions pom.xml
Expand Up @@ -178,20 +178,28 @@
</dependency>



<!-- GNU LICENSE, NOT INCLUDED IN THE PRODUCT! -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>

<!-- LICENSE INFORMATION
OpenHFT, Chronicle Map
Apache 2 License
https://github.com/OpenHFT/Chronicle-Map/blob/master/LICENSE
2015-03-01
permin
-->
<!-- <dependency>
<!-- <dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
<version>2.1.3</version>
</dependency>-->

<!-- <dependency>
<!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.10</version>
Expand Down
39 changes: 36 additions & 3 deletions src/main/java/com/speedment/orm/Test.java
Expand Up @@ -14,9 +14,15 @@
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.speedment.orm;

import com.speedment.orm.config.model.Dbms;
import com.speedment.orm.config.model.aspects.Node;
import com.speedment.orm.db.impl.MySqlDbmsHandler;
import com.speedment.util.Trees;
import java.util.function.Function;
import java.util.stream.Stream;

/**
*
* @author pemi
Expand All @@ -27,7 +33,34 @@ public class Test {
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Dbms dbms = Dbms.newDbms();
dbms.setName("db0");
dbms.setIpAddress("localhost");
dbms.setUsername("root");

final MySqlDbmsHandler handler = new MySqlDbmsHandler(dbms);

handler.schemasPopulated().forEachOrdered(schema -> {

// System.out.println(schema);
//
// List<Table> tables = schema.stream().collect(Collectors.<Table>toList());
//
// for (Table table : tables) {
// final String s = table.toString();
//
// String rn = table.getRelativeName(schema);
//
// System.out.println(" " + s);
// }
Function<Node, Stream<Node>> traverser = n -> n.asParent().map(p -> p.stream()).orElse(Stream.empty()).map(c -> (Node) c);

Trees.traverse(schema,
traverser,
Trees.TraversalOrder.BREADTH_FIRST).forEachOrdered(System.out::println);
// System.out.println(schema.toString());
});

}

}
Expand Up @@ -61,19 +61,19 @@ public String getName() {
@Override
public void setName(String name) {
this.name = Optional.ofNullable(name)
.filter(n -> !n.contains("."))
.orElseThrow(() -> new IllegalArgumentException("A name can't be null or contain '.'"));
.filter(n -> !n.contains("."))
.orElseThrow(() -> new IllegalArgumentException("A name can't be null or contain '.'"));
}

@Override
public String toString() {
return getInterfaceMainClass().getSimpleName()
+ " '" + Optional.of(this)
+ " '" + Optional.of(this)
.filter(e -> e.isChildInterface())
.map(e -> (Child<?>) e)
.flatMap(e -> e.getParent())
.map(e -> getRelativeName(e))
.map(e -> getRelativeName(e) + "." + getName())
.orElse(getName())
+ "'";
+ "'";
}
}
Expand Up @@ -17,24 +17,25 @@
package com.speedment.orm.config.model.parameters;

import java.util.Optional;
import java.util.Set;

/**
*
* @author pemi
*/
public interface DbmsType {

public String getName();
String getName();

public String getDriverManagerName();
String getDriverManagerName();

public int getDefaultPort();
int getDefaultPort();

public String getSchemaTableDelimiter();
String getSchemaTableDelimiter();

public String getDbmsNameMeaning();
String getDbmsNameMeaning();

public boolean isSupported();
boolean isSupported();

// Implementation specifics
String getDriverName();
Expand All @@ -43,8 +44,18 @@ public interface DbmsType {

String getJdbcConnectorName();

public String getFieldEncloserStart(final boolean isWithinQuotes);
default String getFieldEncloserStart() {
return getFieldEncloserStart(false);
}

public String getFieldEncloserEnd(final boolean isWithinQuotes);
default String getFieldEncloserEnd() {
return getFieldEncloserEnd(false);
}

String getFieldEncloserStart(final boolean isWithinQuotes);

String getFieldEncloserEnd(final boolean isWithinQuotes);

Set<String> getSchemaExcludSet();

}
Expand Up @@ -31,7 +31,6 @@ public interface DbmsTypeable {
/**
*
* @param dbmsTypeName
* @return the DbmsType
* @throws IllegalArgumentException if a DbmsType for the given dbmsTypeName
* could not be found
*/
Expand Down
Expand Up @@ -18,8 +18,12 @@

import com.speedment.orm.annotations.Api;
import com.speedment.orm.config.model.ConfigEntity;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

/**
Expand All @@ -39,7 +43,8 @@ public enum StandardDbmsType implements EnumHelper<StandardDbmsType>, DbmsType {
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mysql",
"`",
"`"
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema")))
),
MARIADB(
"MariaDB",
Expand All @@ -51,7 +56,8 @@ public enum StandardDbmsType implements EnumHelper<StandardDbmsType>, DbmsType {
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mariadb",
"`",
"`"
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema")))
);
//
// ORACLE("Oracle", "Oracle JDBC Driver", 1521, ".", "SID"),
Expand All @@ -73,7 +79,8 @@ private StandardDbmsType(
final String defaultConnectionParameters,
final String jdbcConnectorName,
final String fieldEncloserStart,
final String fieldEncloserEnd
final String fieldEncloserEnd,
final Set<String> schemaExcludSet
) {
this.name = name;
this.driverManagerName = driverManagerName;
Expand All @@ -85,6 +92,7 @@ private StandardDbmsType(
this.jdbcConnectorName = jdbcConnectorName;
this.fieldEncloserStart = fieldEncloserStart;
this.fieldEncloserEnd = fieldEncloserEnd;
this.schemaExcludSet = schemaExcludSet;
}
private final String name;
private final String driverManagerName;
Expand All @@ -96,6 +104,7 @@ private StandardDbmsType(
private final String jdbcConnectorName;
private final String fieldEncloserStart;
private final String fieldEncloserEnd;
private final Set<String> schemaExcludSet;

@Override
public String getName() {
Expand Down Expand Up @@ -170,4 +179,10 @@ public static StandardDbmsType defaultFor(final ConfigEntity entity) {
public static Stream<StandardDbmsType> stream() {
return Stream.of(values());
}



public Set<String> getSchemaExcludSet() {
return schemaExcludSet;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/speedment/orm/db/DbmsHandler.java
Expand Up @@ -31,7 +31,7 @@ public interface DbmsHandler {

Dbms getDbms();

Stream<Schema> readMetadata();
Stream<Schema> schemas();

<ENTITY> long readAll(Consumer<ENTITY> consumer);

Expand Down

0 comments on commit e5e3b7f

Please sign in to comment.