Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced OrientDB with ArcadeDB (latest version) #745

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
build/
.gradle
.gradletasknamecache
.DS_Store
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jade4jVersion = 1.3.2
jsoupVersion = 1.14.3
jgitVersion = 6.0.0.202111291000-r
logbackVersion = 1.2.10
orientDbVersion = 3.0.41
arcadeDbVersion = 22.1.2
pebbleVersion = 3.1.5
slf4jVersion = 1.7.32
snakeYamlVersion = 1.30
Expand Down
2 changes: 1 addition & 1 deletion jbake-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
implementation("com.googlecode.json-simple:json-simple:$jsonSimpleVersion") {
exclude group: "junit", module: "junit"
}
implementation "com.orientechnologies:orientdb-core:$orientDbVersion"
implementation "com.arcadedb:arcadedb-engine:$arcadeDbVersion"
api "org.asciidoctor:asciidoctorj:$asciidoctorjVersion", optional
api "org.codehaus.groovy:groovy:$groovyVersion", optional
api "org.codehaus.groovy:groovy-templates:$groovyVersion", optional
Expand Down
152 changes: 55 additions & 97 deletions jbake-core/src/main/java/org/jbake/app/ContentStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
*/
package org.jbake.app;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import org.jbake.launcher.SystemExit;
import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.MutableDocument;
import com.arcadedb.engine.Bucket;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.Type;
import org.jbake.model.DocumentModel;
import org.jbake.model.DocumentTypes;
import org.jbake.model.ModelAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.io.*;
import java.util.*;

/**
* @author jdlee
Expand Down Expand Up @@ -73,33 +66,29 @@ public class ContentStore {
private final String type;
private final String name;

private ODatabaseSession db;
private Database db;

private long start = -1;
private long limit = -1;
private OrientDB orient;
private long start = -1;
private long limit = -1;
private DatabaseFactory factory;

public ContentStore(final String type, String name) {
this.type = type;
this.name = name;
}

// USE A 4X BIGGER PAGE THAN THE DEFAULT
GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE.setValue(Bucket.DEF_PAGE_SIZE * 4);
}

public void startup() {
startupIfEnginesAreMissing();

if (type.equalsIgnoreCase(ODatabaseType.PLOCAL.name())) {
orient = new OrientDB(type + ":" + name, OrientDBConfig.defaultConfig());
} else {
orient = new OrientDB(type + ":", OrientDBConfig.defaultConfig());
}
factory = new DatabaseFactory(name);

orient.createIfNotExists(name, ODatabaseType.valueOf(type.toUpperCase()));

db = orient.open(name, "admin", "admin");

activateOnCurrentThread();
if( !factory.exists() )
db = factory.create();
else
db = factory.open();

db.setAutoTransaction(true);
updateSchema();
}

Expand All @@ -125,65 +114,37 @@ public void resetPagination() {
}

public final void updateSchema() {
com.arcadedb.schema.Schema schema = db.getSchema();

OSchema schema = db.getMetadata().getSchema();

if (!schema.existsClass(Schema.DOCUMENTS)) {
if (!schema.existsType(Schema.DOCUMENTS)) {
createDocType(schema);
}
if (!schema.existsClass(Schema.SIGNATURES)) {
if (!schema.existsType(Schema.SIGNATURES)) {
createSignatureType(schema);
}
}

public void close() {
if (db != null) {
activateOnCurrentThread();
db.close();
}

if (orient != null) {
orient.close();
if (factory != null) {
factory.close();
}
DBUtil.closeDataStore();
}

public void shutdown() {

// Orient.instance().shutdown();
}

private void startupIfEnginesAreMissing() {
// Using a jdk which doesn't bundle a javascript engine
// throws a NoClassDefFoundError while logging the warning
// see https://github.com/orientechnologies/orientdb/issues/5855
OLogManager.instance().setWarnEnabled(false);

// If an instance of Orient was previously shutdown all engines are removed.
// We need to startup Orient again.
if (Orient.instance().getEngines().isEmpty()) {
Orient.instance().startup();
}
OLogManager.instance().setWarnEnabled(true);
close();
}

public void drop() {
activateOnCurrentThread();
// db.drop();

orient.drop(name);
}

private void activateOnCurrentThread() {
if (db != null) {
db.activateOnCurrentThread();
} else {
System.out.println("db is null on activate");
}
if( db != null)
db.drop();
}

public long getDocumentCount(String docType) {
activateOnCurrentThread();
String statement = String.format(STATEMENT_GET_DOCUMENT_COUNT_BY_TYPE, docType);
return (long) query(statement).get(0).get("count");
}
Expand Down Expand Up @@ -291,20 +252,17 @@ private void insertTemplatesSignature(String currentTemplatesSignature) {
}

private DocumentList<DocumentModel> query(String sql) {
activateOnCurrentThread();
OResultSet results = db.query(sql);
ResultSet results = db.query("sql", sql);
return DocumentList.wrap(results);
}

private DocumentList<DocumentModel> query(String sql, Object... args) {
activateOnCurrentThread();
OResultSet results = db.command(sql, args);
ResultSet results = db.command("sql", sql, args);
return DocumentList.wrap(results);
}

private void executeCommand(String query, Object... args) {
activateOnCurrentThread();
db.command(query, args);
db.command("sql", query, args);
}

public Set<String> getTags() {
Expand All @@ -330,29 +288,29 @@ public Set<String> getAllTags() {
return result;
}

private void createDocType(final OSchema schema) {
private void createDocType(final com.arcadedb.schema.Schema schema) {
logger.debug("Create document class");

OClass page = schema.createClass(Schema.DOCUMENTS);
page.createProperty(ModelAttributes.SHA1, OType.STRING).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "sha1Index", OClass.INDEX_TYPE.NOTUNIQUE, ModelAttributes.SHA1);
page.createProperty(ModelAttributes.SOURCE_URI, OType.STRING).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "sourceUriIndex", OClass.INDEX_TYPE.UNIQUE, ModelAttributes.SOURCE_URI);
page.createProperty(ModelAttributes.CACHED, OType.BOOLEAN).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "cachedIndex", OClass.INDEX_TYPE.NOTUNIQUE, ModelAttributes.CACHED);
page.createProperty(ModelAttributes.RENDERED, OType.BOOLEAN).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "renderedIndex", OClass.INDEX_TYPE.NOTUNIQUE, ModelAttributes.RENDERED);
page.createProperty(ModelAttributes.STATUS, OType.STRING).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "statusIndex", OClass.INDEX_TYPE.NOTUNIQUE, ModelAttributes.STATUS);
page.createProperty(ModelAttributes.TYPE, OType.STRING).setNotNull(true);
page.createIndex(Schema.DOCUMENTS + "typeIndex", OClass.INDEX_TYPE.NOTUNIQUE, ModelAttributes.TYPE);
DocumentType page = schema.createDocumentType(Schema.DOCUMENTS);
page.createProperty(ModelAttributes.SHA1, Type.STRING);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE,false, ModelAttributes.SHA1);
page.createProperty(ModelAttributes.SOURCE_URI, Type.STRING);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, true, ModelAttributes.SOURCE_URI);
page.createProperty(ModelAttributes.CACHED, Type.BOOLEAN);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, false, ModelAttributes.CACHED);
page.createProperty(ModelAttributes.RENDERED, Type.BOOLEAN);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, false, ModelAttributes.RENDERED);
page.createProperty(ModelAttributes.STATUS, Type.STRING);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, false, ModelAttributes.STATUS);
page.createProperty(ModelAttributes.TYPE, Type.STRING);
page.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, false, ModelAttributes.TYPE);

}

private void createSignatureType(OSchema schema) {
OClass signatures = schema.createClass(Schema.SIGNATURES);
signatures.createProperty(ModelAttributes.SHA1, OType.STRING).setNotNull(true);
signatures.createIndex("sha1Idx", OClass.INDEX_TYPE.UNIQUE, ModelAttributes.SHA1);
private void createSignatureType(com.arcadedb.schema.Schema schema) {
DocumentType signatures = schema.createDocumentType(Schema.SIGNATURES);
signatures.createProperty(ModelAttributes.SHA1, Type.STRING);
signatures.createTypeIndex(com.arcadedb.schema.Schema.INDEX_TYPE.LSM_TREE, true, ModelAttributes.SHA1);
}

public void updateAndClearCacheIfNeeded(boolean needed, File templateFolder) {
Expand Down Expand Up @@ -404,11 +362,11 @@ private void deleteAllDocumentTypes() {
}

public boolean isActive() {
return db.isActiveOnCurrentThread();
return true;
}

public void addDocument(DocumentModel document) {
ODocument doc = new ODocument(Schema.DOCUMENTS);
public void addDocument(final DocumentModel document) {
final MutableDocument doc = db.newDocument(Schema.DOCUMENTS);
doc.fromMap(document);
doc.save();
}
Expand Down
12 changes: 4 additions & 8 deletions jbake-core/src/main/java/org/jbake/app/Crawler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jbake.app;

import com.orientechnologies.orient.core.record.impl.ODocument;
import org.apache.commons.configuration2.CompositeConfiguration;
import org.apache.commons.io.FilenameUtils;
import org.jbake.app.configuration.JBakeConfiguration;
Expand All @@ -13,13 +12,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.io.*;
import java.net.*;
import java.nio.charset.*;
import java.util.*;

/**
* Crawls a file system looking for content.
Expand Down
12 changes: 6 additions & 6 deletions jbake-core/src/main/java/org/jbake/app/DBUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jbake.app;

import com.orientechnologies.orient.core.db.record.OTrackedList;
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.arcadedb.query.sql.executor.Result;
import org.jbake.app.configuration.JBakeConfiguration;
import org.jbake.model.DocumentModel;

import java.util.*;

public class DBUtil {
private static ContentStore contentStore;

Expand Down Expand Up @@ -34,7 +34,7 @@ public static void closeDataStore() {
contentStore = null;
}

public static DocumentModel documentToModel(OResult doc) {
public static DocumentModel documentToModel(Result doc) {
DocumentModel result = new DocumentModel();

for (String key : doc.getPropertyNames()) {
Expand All @@ -53,8 +53,8 @@ public static DocumentModel documentToModel(OResult doc) {
public static String[] toStringArray(Object entry) {
if (entry instanceof String[]) {
return (String[]) entry;
} else if (entry instanceof OTrackedList) {
OTrackedList<String> list = (OTrackedList<String>) entry;
} else if (entry instanceof List) {
List<String> list = (List<String>) entry;
return list.toArray(new String[list.size()]);
}
return new String[0];
Expand Down
10 changes: 5 additions & 5 deletions jbake-core/src/main/java/org/jbake/app/DocumentList.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jbake.app;

import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultSet;
import org.jbake.model.DocumentModel;

import java.util.LinkedList;
import java.util.*;

/**
* Wraps an OrientDB document iterator into a model usable by
Expand All @@ -14,10 +14,10 @@
*/
public class DocumentList<T> extends LinkedList<T> {

public static DocumentList<DocumentModel> wrap(OResultSet docs) {
public static DocumentList<DocumentModel> wrap(ResultSet docs) {
DocumentList<DocumentModel> list = new DocumentList<>();
while (docs.hasNext()) {
OResult next = docs.next();
Result next = docs.next();
list.add(DBUtil.documentToModel(next));
}
docs.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jbake.template;


import de.neuland.jade4j.Jade4J;
import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.filter.CDATAFilter;
Expand All @@ -11,18 +10,14 @@
import de.neuland.jade4j.template.JadeTemplate;
import de.neuland.jade4j.template.TemplateLoader;
import org.apache.commons.configuration2.CompositeConfiguration;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jbake.app.ContentStore;
import org.jbake.app.configuration.JBakeConfiguration;
import org.jbake.template.model.TemplateModel;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.io.*;
import java.text.*;
import java.util.*;

/**
* Renders pages using the <a href="http://jade.org/">Jade</a> template language.
Expand Down Expand Up @@ -105,7 +100,7 @@ public String format(Date date, String pattern) {
}

public String escape(String s) {
return StringEscapeUtils.escapeHtml(s);
return StringEscapeUtils.escapeHtml4(s);
}
}
}