├── doc
└── readme.txt
├── .gitignore
├── releases
├── open-replicator-1.0.6.jar
├── open-replicator-1.0.7.jar
├── open-replicator-1.0.6-sources.jar
└── open-replicator-1.0.7-sources.jar
├── .settings
├── org.eclipse.m2e.core.prefs
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── .project
├── src
├── test
│ ├── resources
│ │ └── logback.xml
│ └── java
│ │ └── com
│ │ └── google
│ │ └── code
│ │ └── or
│ │ ├── OpenReplicatorTest.java
│ │ └── OpenParserTest.java
└── main
│ └── java
│ └── com
│ └── google
│ └── code
│ └── or
│ ├── binlog
│ ├── StatusVariable.java
│ ├── BinlogEventListener.java
│ ├── BinlogEventFilter.java
│ ├── UserVariable.java
│ ├── BinlogRowEventFilter.java
│ ├── BinlogParserContext.java
│ ├── BinlogEventParser.java
│ ├── impl
│ │ ├── parser
│ │ │ ├── AbstractBinlogEventParser.java
│ │ │ ├── NopEventParser.java
│ │ │ ├── StopEventParser.java
│ │ │ ├── RandEventParser.java
│ │ │ ├── RotateEventParser.java
│ │ │ ├── IntvarEventParser.java
│ │ │ ├── IncidentEventParser.java
│ │ │ ├── FormatDescriptionEventParser.java
│ │ │ ├── XidEventParser.java
│ │ │ ├── GtidEventParser.java
│ │ │ ├── WriteRowsEventParser.java
│ │ │ └── DeleteRowsEventParser.java
│ │ ├── event
│ │ │ ├── AbstractRowEvent.java
│ │ │ ├── AbstractBinlogEventV4.java
│ │ │ ├── StopEvent.java
│ │ │ ├── GtidEvent.java
│ │ │ ├── XidEvent.java
│ │ │ ├── RandEvent.java
│ │ │ ├── RotateEvent.java
│ │ │ ├── IntvarEvent.java
│ │ │ ├── IncidentEvent.java
│ │ │ ├── WriteRowsEvent.java
│ │ │ └── DeleteRowsEvent.java
│ │ ├── variable
│ │ │ ├── user
│ │ │ │ ├── AbstractUserVariable.java
│ │ │ │ ├── UserVariableReal.java
│ │ │ │ ├── UserVariableRow.java
│ │ │ │ ├── UserVariableDecimal.java
│ │ │ │ ├── UserVariableInt.java
│ │ │ │ └── UserVariableString.java
│ │ │ └── status
│ │ │ │ ├── AbstractStatusVariable.java
│ │ │ │ ├── QFlags2Code.java
│ │ │ │ ├── QSQLModeCode.java
│ │ │ │ ├── QMicroseconds.java
│ │ │ │ ├── QMasterDataWrittenCode.java
│ │ │ │ ├── QLcTimeNamesCode.java
│ │ │ │ ├── QTableMapForUpdateCode.java
│ │ │ │ ├── QCatalogCode.java
│ │ │ │ ├── QTimeZoneCode.java
│ │ │ │ ├── QCharsetDatabaseCode.java
│ │ │ │ ├── QCatalogNzCode.java
│ │ │ │ ├── QInvoker.java
│ │ │ │ ├── QAutoIncrement.java
│ │ │ │ ├── QCharsetCode.java
│ │ │ │ └── QUpdatedDBNames.java
│ │ └── filter
│ │ │ └── BinlogRowEventFilterImpl.java
│ ├── BinlogEventV4Header.java
│ ├── BinlogParserListener.java
│ ├── BinlogParser.java
│ └── BinlogEventV4.java
│ ├── common
│ ├── glossary
│ │ ├── Column.java
│ │ ├── Row.java
│ │ ├── column
│ │ │ ├── SetColumn.java
│ │ │ ├── EnumColumn.java
│ │ │ ├── FloatColumn.java
│ │ │ ├── StringColumn.java
│ │ │ ├── DoubleColumn.java
│ │ │ ├── DateColumn.java
│ │ │ ├── TimeColumn.java
│ │ │ ├── Time2Column.java
│ │ │ ├── DatetimeColumn.java
│ │ │ ├── Datetime2Column.java
│ │ │ ├── TimestampColumn.java
│ │ │ ├── Timestamp2Column.java
│ │ │ ├── BlobColumn.java
│ │ │ ├── LongLongColumn.java
│ │ │ ├── YearColumn.java
│ │ │ ├── NullColumn.java
│ │ │ ├── TinyColumn.java
│ │ │ ├── DecimalColumn.java
│ │ │ ├── Int24Column.java
│ │ │ ├── LongColumn.java
│ │ │ ├── ShortColumn.java
│ │ │ └── BitColumn.java
│ │ └── Pair.java
│ └── util
│ │ ├── IOUtils.java
│ │ ├── ClassUtils.java
│ │ └── ToStringBuilder.java
│ ├── io
│ ├── SocketFactory.java
│ ├── ExceedLimitException.java
│ ├── XOutputStream.java
│ ├── util
│ │ └── RamdomAccessFileInputStream.java
│ ├── impl
│ │ └── SocketFactoryImpl.java
│ └── XInputStream.java
│ └── net
│ ├── TransportInputStream.java
│ ├── TransportOutputStream.java
│ ├── Packet.java
│ ├── TransportContext.java
│ ├── impl
│ ├── packet
│ │ ├── command
│ │ │ ├── AbstractCommandPacket.java
│ │ │ ├── ComQuit.java
│ │ │ ├── ComQuery.java
│ │ │ └── ComInitDBPacket.java
│ │ ├── AbstractPacket.java
│ │ ├── RawPacket.java
│ │ └── ResultSetRowPacket.java
│ └── TransportInputStreamImpl.java
│ ├── Transport.java
│ └── TransportException.java
├── .classpath
├── pom.xml
└── README.md
/doc/readme.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 |
--------------------------------------------------------------------------------
/releases/open-replicator-1.0.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whitesock/open-replicator/HEAD/releases/open-replicator-1.0.6.jar
--------------------------------------------------------------------------------
/releases/open-replicator-1.0.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whitesock/open-replicator/HEAD/releases/open-replicator-1.0.7.jar
--------------------------------------------------------------------------------
/releases/open-replicator-1.0.6-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whitesock/open-replicator/HEAD/releases/open-replicator-1.0.6-sources.jar
--------------------------------------------------------------------------------
/releases/open-replicator-1.0.7-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whitesock/open-replicator/HEAD/releases/open-replicator-1.0.7-sources.jar
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | #Thu Dec 22 15:11:26 CST 2011
2 | activeProfiles=
3 | eclipse.preferences.version=1
4 | resolveWorkspaceProjects=true
5 | version=1
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 | encoding//src/test/resources=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Thu Dec 22 15:11:28 CST 2011
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.source=1.5
7 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | open-replicator
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{yy-MM-dd HH:mm:ss.SSS} %-5level[%thread %logger{0}.%M:%L]%marker %msg%n
6 | true
7 | true
8 |
9 |
10 |
11 |
12 |
13 | ${APP_HOME}/log/${APP_NAME}.%d{yyyy-MM-dd}.log
14 |
15 |
16 | %d{yy-MM-dd HH:mm:ss.SSS} %-5level[%thread %logger{0}.%M:%L]%marker %msg%n
17 | true
18 | true
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/StatusVariable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface StatusVariable {
24 |
25 | int getType();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogEventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface BinlogEventListener {
24 |
25 | void onEvents(BinlogEventV4 event);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogEventFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface BinlogEventFilter {
24 |
25 | boolean accepts(BinlogEventV4Header header, BinlogParserContext context);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/UserVariable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | * @see include/mysql_com.h
23 | */
24 | public interface UserVariable {
25 |
26 | int getType();
27 |
28 | Object getValue();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/Column.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary;
18 |
19 | import java.io.Serializable;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public interface Column extends Serializable {
26 |
27 | Object getValue();
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/SocketFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io;
18 |
19 | import java.net.Socket;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public interface SocketFactory {
26 |
27 | Socket create(String host, int port) throws Exception;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/TransportInputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.io.XInputStream;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public interface TransportInputStream extends XInputStream {
28 |
29 | Packet readPacket() throws IOException;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogRowEventFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | import com.google.code.or.binlog.impl.event.TableMapEvent;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public interface BinlogRowEventFilter {
26 |
27 | boolean accepts(BinlogEventV4Header header, BinlogParserContext context, TableMapEvent event);
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/TransportOutputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.io.XOutputStream;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public interface TransportOutputStream extends XOutputStream {
28 |
29 | void writePacket(Packet packet) throws IOException;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/Packet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | import java.io.IOException;
20 | import java.io.Serializable;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public interface Packet extends Serializable {
27 |
28 | int getLength();
29 |
30 | int getSequence();
31 |
32 | byte[] getPacketBody() throws IOException;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogParserContext.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | import com.google.code.or.binlog.impl.event.TableMapEvent;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public interface BinlogParserContext {
26 |
27 | String getBinlogFileName();
28 |
29 | BinlogEventListener getEventListener();
30 |
31 | TableMapEvent getTableMapEvent(long tableId);
32 | }
33 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.io.XInputStream;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public interface BinlogEventParser {
28 |
29 | int getEventType();
30 |
31 | void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context) throws IOException;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/ExceedLimitException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public class ExceedLimitException extends IOException {
26 | //
27 | private static final long serialVersionUID = -5580022370029510002L;
28 |
29 | /**
30 | *
31 | */
32 | public ExceedLimitException() {
33 | }
34 |
35 | public ExceedLimitException(String message) {
36 | super(message);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | open-replicator
6 | open-replicator
7 | 1.0.7
8 | jar
9 |
10 | open-replicator
11 | http://code.google.com/p/open-replicator/
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 | org.slf4j
26 | slf4j-api
27 | 1.7.5
28 |
29 |
30 | ch.qos.logback
31 | logback-core
32 | 1.1.2
33 |
34 |
35 | ch.qos.logback
36 | logback-classic
37 | 1.1.2
38 |
39 |
40 | Open Replicator is a high performance MySQL binlog parser written in Java.
41 |
42 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/TransportContext.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface TransportContext {
24 |
25 | /**
26 | *
27 | */
28 | long getThreadId();
29 |
30 | String getScramble();
31 |
32 | int getProtocolVersion();
33 |
34 | /**
35 | *
36 | */
37 | String getServerHost();
38 |
39 | int getServerPort();
40 |
41 | int getServerStatus();
42 |
43 | int getServerCollation();
44 |
45 | String getServerVersion();
46 |
47 | int getServerCapabilities();
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/AbstractBinlogEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import com.google.code.or.binlog.BinlogEventParser;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public abstract class AbstractBinlogEventParser implements BinlogEventParser {
26 | //
27 | protected final int eventType;
28 |
29 | /**
30 | *
31 | */
32 | public AbstractBinlogEventParser(int eventType) {
33 | this.eventType = eventType;
34 | }
35 |
36 | /**
37 | *
38 | */
39 | public final int getEventType() {
40 | return eventType;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/com/google/code/or/OpenReplicatorTest.java:
--------------------------------------------------------------------------------
1 | package com.google.code.or;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import com.google.code.or.binlog.BinlogEventListener;
11 | import com.google.code.or.binlog.BinlogEventV4;
12 |
13 | public class OpenReplicatorTest {
14 | //
15 | private static final Logger LOGGER = LoggerFactory.getLogger(OpenReplicatorTest.class);
16 |
17 | /**
18 | *
19 | */
20 | public static void main(String args[]) throws Exception {
21 | //
22 | final OpenReplicator or = new OpenReplicator();
23 | or.setUser("nextop");
24 | or.setPassword("nextop");
25 | or.setHost("192.168.1.216");
26 | or.setPort(3306);
27 | or.setServerId(6789);
28 | or.setBinlogPosition(120);
29 | or.setBinlogFileName("mysql-bin.000003");
30 | or.setBinlogEventListener(new BinlogEventListener() {
31 | public void onEvents(BinlogEventV4 event) {
32 | LOGGER.info("{}", event);
33 | }
34 | });
35 | or.start();
36 |
37 | //
38 | LOGGER.info("press 'q' to stop");
39 | final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
40 | for(String line = br.readLine(); line != null; line = br.readLine()) {
41 | if(line.equals("q")) {
42 | or.stop(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
43 | break;
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogEventV4Header.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface BinlogEventV4Header {
24 |
25 | /**
26 | *
27 | */
28 | int getHeaderLength();
29 |
30 | long getPosition();
31 |
32 | /**
33 | *
34 | */
35 | long getTimestamp();
36 |
37 | int getEventType();
38 |
39 | long getServerId();
40 |
41 | long getEventLength();
42 |
43 | long getNextPosition();
44 |
45 | int getFlags();
46 |
47 | /**
48 | *
49 | */
50 | String getBinlogFileName();
51 |
52 | long getTimestampOfReceipt();
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/AbstractRowEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public abstract class AbstractRowEvent extends AbstractBinlogEventV4 {
24 | //
25 | protected long tableId;
26 | protected int reserved;
27 |
28 | /**
29 | *
30 | */
31 | public long getTableId() {
32 | return tableId;
33 | }
34 |
35 | public void setTableId(long tableId) {
36 | this.tableId = tableId;
37 | }
38 |
39 | public int getReserved() {
40 | return reserved;
41 | }
42 |
43 | public void setReserved(int reserved) {
44 | this.reserved = reserved;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/com/google/code/or/OpenParserTest.java:
--------------------------------------------------------------------------------
1 | package com.google.code.or;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import com.google.code.or.binlog.BinlogEventListener;
11 | import com.google.code.or.binlog.BinlogEventV4;
12 | import com.google.code.or.binlog.impl.event.XidEvent;
13 |
14 | public class OpenParserTest {
15 | //
16 | private static final Logger LOGGER = LoggerFactory.getLogger(OpenParserTest.class);
17 |
18 | /**
19 | *
20 | */
21 | public static void main(String args[]) throws Exception {
22 | //
23 | final OpenParser op = new OpenParser();
24 | op.setStartPosition(4);
25 | op.setBinlogFileName("mysql_bin.000031");
26 | op.setBinlogFilePath("C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.5/data");
27 | op.setBinlogEventListener(new BinlogEventListener() {
28 | public void onEvents(BinlogEventV4 event) {
29 | if(event instanceof XidEvent) {
30 | LOGGER.info("{}", event);
31 | }
32 | }
33 | });
34 | op.start();
35 |
36 | //
37 | LOGGER.info("press 'q' to stop");
38 | final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
39 | for(String line = br.readLine(); line != null; line = br.readLine()) {
40 | if(line.equals("q")) {
41 | op.stop(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
42 | break;
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/command/AbstractCommandPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet.command;
18 |
19 | import com.google.code.or.net.impl.packet.AbstractPacket;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public abstract class AbstractCommandPacket extends AbstractPacket {
26 | //
27 | private static final long serialVersionUID = -8046179372409111502L;
28 |
29 | //
30 | protected final int command;
31 |
32 | /**
33 | *
34 | */
35 | public AbstractCommandPacket(int command) {
36 | this.command = command;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public int getCommand() {
43 | return command;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogParserListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public interface BinlogParserListener {
24 |
25 | /**
26 | *
27 | */
28 | void onStart(BinlogParser parser);
29 |
30 | void onStop(BinlogParser parser);
31 |
32 | void onException(BinlogParser parser, Exception eception);
33 |
34 | /**
35 | *
36 | */
37 | class Adapter implements BinlogParserListener {
38 |
39 | public void onStart(BinlogParser parser) {
40 | }
41 |
42 | public void onStop(BinlogParser parser) {
43 | }
44 |
45 | public void onException(BinlogParser parser, Exception exception) {
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/Transport.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | * @see http://forge.mysql.com/wiki/MySQL_Internals
23 | */
24 | public interface Transport {
25 |
26 | /**
27 | *
28 | */
29 | boolean isConnected();
30 |
31 | void disconnect() throws Exception;
32 |
33 | void connect(String host, int port) throws Exception;
34 |
35 | /**
36 | *
37 | */
38 | TransportContext getContext();
39 |
40 | TransportInputStream getInputStream();
41 |
42 | TransportOutputStream getOutputStream();
43 |
44 | /**
45 | *
46 | */
47 | interface Authenticator {
48 |
49 | void login(Transport transport) throws Exception;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/AbstractUserVariable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.binlog.UserVariable;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public abstract class AbstractUserVariable implements UserVariable {
27 | //
28 | protected final int type;
29 |
30 | /**
31 | *
32 | */
33 | public AbstractUserVariable(int type) {
34 | this.type = type;
35 | }
36 |
37 | /**
38 | *
39 | */
40 | @Override
41 | public String toString() {
42 | return new ToStringBuilder(this).toString();
43 | }
44 |
45 | /**
46 | *
47 | */
48 | public int getType() {
49 | return type;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/AbstractPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet;
18 |
19 | import com.google.code.or.net.Packet;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public abstract class AbstractPacket implements Packet {
26 | //
27 | private static final long serialVersionUID = -2762990065527029085L;
28 |
29 | //
30 | protected int length;
31 | protected int sequence;
32 |
33 | /**
34 | *
35 | */
36 | public int getLength() {
37 | return length;
38 | }
39 |
40 | public void setLength(int length) {
41 | this.length = length;
42 | }
43 |
44 | public int getSequence() {
45 | return sequence;
46 | }
47 |
48 | public void setSequence(int sequence) {
49 | this.sequence = sequence;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/AbstractStatusVariable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import com.google.code.or.binlog.StatusVariable;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public abstract class AbstractStatusVariable implements StatusVariable {
27 | //
28 | protected final int type;
29 |
30 | /**
31 | *
32 | */
33 | public AbstractStatusVariable(int type) {
34 | this.type = type;
35 | }
36 |
37 | /**
38 | *
39 | */
40 | @Override
41 | public String toString() {
42 | return new ToStringBuilder(this).toString();
43 | }
44 |
45 | /**
46 | *
47 | */
48 | public int getType() {
49 | return type;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/util/IOUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.util;
18 |
19 | import java.net.Socket;
20 |
21 | import com.google.code.or.io.XInputStream;
22 | import com.google.code.or.io.XOutputStream;
23 |
24 | /**
25 | *
26 | * @author Jingqi Xu
27 | */
28 | public final class IOUtils {
29 |
30 | /**
31 | *
32 | */
33 | public static void closeQuietly(Socket socket) {
34 | try {
35 | socket.close();
36 | } catch(Exception e) {
37 | // NOP
38 | }
39 | }
40 |
41 | public static void closeQuietly(XInputStream is) {
42 | try {
43 | is.close();
44 | } catch(Exception e) {
45 | // NOP
46 | }
47 | }
48 |
49 | public static void closeQuietly(XOutputStream os) {
50 | try {
51 | os.close();
52 | } catch(Exception e) {
53 | // NOP
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/RawPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet;
18 |
19 | import com.google.code.or.common.util.ToStringBuilder;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public class RawPacket extends AbstractPacket {
26 | //
27 | private static final long serialVersionUID = 4109090905397000303L;
28 |
29 | //
30 | private byte packetBody[];
31 |
32 | /**
33 | *
34 | */
35 | @Override
36 | public String toString() {
37 | return new ToStringBuilder(this)
38 | .append("length", length)
39 | .append("sequence", sequence).toString();
40 | }
41 |
42 | /**
43 | *
44 | */
45 | public byte[] getPacketBody() {
46 | return packetBody;
47 | }
48 |
49 | public void setPacketBody(byte[] packetBody) {
50 | this.packetBody = packetBody;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/command/ComQuit.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet.command;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 |
24 | /**
25 | *
26 | * @author Jingqi Xu
27 | */
28 | public class ComQuit extends AbstractCommandPacket {
29 | //
30 | private static final long serialVersionUID = 4569517082177697955L;
31 |
32 | /**
33 | *
34 | */
35 | public ComQuit() {
36 | super(MySQLConstants.COM_QUIT);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return new ToStringBuilder(this).toString();
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public byte[] getPacketBody() throws IOException {
51 | return new byte[0];
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/Row.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary;
18 |
19 | import java.util.List;
20 |
21 | import com.google.code.or.common.util.ToStringBuilder;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public class Row {
28 | //
29 | private List columns;
30 |
31 | /**
32 | *
33 | */
34 | public Row() {
35 | }
36 |
37 | public Row(List columns) {
38 | this.columns = columns;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | @Override
45 | public String toString() {
46 | return new ToStringBuilder(this)
47 | .append("columns", columns).toString();
48 | }
49 |
50 | /**
51 | *
52 | */
53 | public List getColumns() {
54 | return columns;
55 | }
56 |
57 | public void setColumns(List columns) {
58 | this.columns = columns;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/AbstractBinlogEventV4.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4;
20 | import com.google.code.or.binlog.BinlogEventV4Header;
21 | import com.google.code.or.common.util.ToStringBuilder;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public abstract class AbstractBinlogEventV4 implements BinlogEventV4 {
28 | //
29 | protected BinlogEventV4Header header;
30 |
31 | /**
32 | *
33 | */
34 | @Override
35 | public String toString() {
36 | return new ToStringBuilder(this)
37 | .append("header", header).toString();
38 | }
39 |
40 | /**
41 | *
42 | */
43 | public BinlogEventV4Header getHeader() {
44 | return header;
45 | }
46 |
47 | public void setHeader(BinlogEventV4Header header) {
48 | this.header = header;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/StopEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.util.MySQLConstants;
21 | import com.google.code.or.common.util.ToStringBuilder;
22 |
23 | /**
24 | * Written when mysqld stops.
25 | *
26 | * @author Jingqi Xu
27 | */
28 | public final class StopEvent extends AbstractBinlogEventV4 {
29 | //
30 | public static final int EVENT_TYPE = MySQLConstants.STOP_EVENT;
31 |
32 | /**
33 | *
34 | */
35 | public StopEvent() {
36 | }
37 |
38 | public StopEvent(BinlogEventV4Header header) {
39 | this.header = header;
40 | }
41 |
42 | /**
43 | *
44 | */
45 | @Override
46 | public String toString() {
47 | return new ToStringBuilder(this)
48 | .append("header", header).toString();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/NopEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventParser;
22 | import com.google.code.or.binlog.BinlogEventV4Header;
23 | import com.google.code.or.binlog.BinlogParserContext;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public final class NopEventParser implements BinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public int getEventType() {
36 | throw new UnsupportedOperationException();
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final int available = is.available();
45 | is.skip(available);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/StopEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.StopEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class StopEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public StopEventParser() {
36 | super(StopEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final StopEvent event = new StopEvent(header);
45 | context.getEventListener().onEvents(event);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/SetColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class SetColumn implements Column {
26 | //
27 | private static final long serialVersionUID = -5274295462701023264L;
28 |
29 | //
30 | private final long value;
31 |
32 | /**
33 | *
34 | */
35 | private SetColumn(long value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public Long getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final SetColumn valueOf(long value) {
58 | return new SetColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/UserVariableReal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.common.util.MySQLConstants;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class UserVariableReal extends AbstractUserVariable {
27 | //
28 | public static final int TYPE = MySQLConstants.REAL_RESULT;
29 |
30 | //
31 | private final double value;
32 |
33 | /**
34 | *
35 | */
36 | public UserVariableReal(double value) {
37 | super(TYPE);
38 | this.value = value;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | @Override
45 | public String toString() {
46 | return new ToStringBuilder(this)
47 | .append("value", value).toString();
48 | }
49 |
50 | /**
51 | *
52 | */
53 | public Double getValue() {
54 | return this.value;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/UserVariableRow.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.common.util.MySQLConstants;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class UserVariableRow extends AbstractUserVariable {
27 | //
28 | public static final int TYPE = MySQLConstants.ROW_RESULT;
29 |
30 | //
31 | private final byte[] value;
32 |
33 | /**
34 | *
35 | */
36 | public UserVariableRow(byte[] value) {
37 | super(TYPE);
38 | this.value = value;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | @Override
45 | public String toString() {
46 | return new ToStringBuilder(this)
47 | .append("value", value).toString();
48 | }
49 |
50 | /**
51 | *
52 | */
53 | public byte[] getValue() {
54 | return this.value;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/EnumColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class EnumColumn implements Column {
26 | //
27 | private static final long serialVersionUID = -6017298545673303080L;
28 |
29 | //
30 | private final int value;
31 |
32 | /**
33 | *
34 | */
35 | private EnumColumn(int value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public Integer getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final EnumColumn valueOf(int value) {
58 | return new EnumColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/FloatColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class FloatColumn implements Column {
26 | //
27 | private static final long serialVersionUID = -890414733626452618L;
28 |
29 | //
30 | private final float value;
31 |
32 | /**
33 | *
34 | */
35 | private FloatColumn(float value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public Float getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final FloatColumn valueOf(float value) {
58 | return new FloatColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/StringColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class StringColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 1009717372407166422L;
28 |
29 | //
30 | private final byte[] value;
31 |
32 | /**
33 | *
34 | */
35 | private StringColumn(byte[] value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return new String(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public byte[] getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final StringColumn valueOf(byte[] value) {
58 | return new StringColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/UserVariableDecimal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.common.util.MySQLConstants;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class UserVariableDecimal extends AbstractUserVariable {
27 | //
28 | public static final int TYPE = MySQLConstants.DECIMAL_RESULT;
29 |
30 | //
31 | private final byte[] value;
32 |
33 | /**
34 | *
35 | */
36 | public UserVariableDecimal(byte[] value) {
37 | super(TYPE);
38 | this.value = value;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | @Override
45 | public String toString() {
46 | return new ToStringBuilder(this)
47 | .append("value", value).toString();
48 | }
49 |
50 | /**
51 | *
52 | */
53 | public byte[] getValue() {
54 | return this.value;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/DoubleColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class DoubleColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 7565759864274700531L;
28 |
29 | //
30 | private final double value;
31 |
32 | /**
33 | *
34 | */
35 | private DoubleColumn(double value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public Double getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final DoubleColumn valueOf(double value) {
58 | return new DoubleColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/DateColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class DateColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 959710929844516680L;
28 |
29 | //
30 | private final java.sql.Date value;
31 |
32 | /**
33 | *
34 | */
35 | private DateColumn(java.sql.Date value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.sql.Date getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final DateColumn valueOf(java.sql.Date value) {
58 | return new DateColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/TimeColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class TimeColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 2408833111678694298L;
28 |
29 | //
30 | private final java.sql.Time value;
31 |
32 | /**
33 | *
34 | */
35 | private TimeColumn(java.sql.Time value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.sql.Time getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final TimeColumn valueOf(java.sql.Time value) {
58 | return new TimeColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/Time2Column.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class Time2Column implements Column {
26 | //
27 | private static final long serialVersionUID = 2408833111678694298L;
28 |
29 | //
30 | private final java.sql.Time value;
31 |
32 | /**
33 | *
34 | */
35 | private Time2Column(java.sql.Time value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.sql.Time getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final Time2Column valueOf(java.sql.Time value) {
58 | return new Time2Column(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | import java.util.List;
20 | import java.util.concurrent.TimeUnit;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | * @see http://forge.mysql.com/wiki/MySQL_Internals
26 | */
27 | public interface BinlogParser {
28 |
29 | /**
30 | *
31 | */
32 | boolean isRunning();
33 |
34 | void start() throws Exception;
35 |
36 | void stop(long timeout, TimeUnit unit) throws Exception;
37 |
38 | /**
39 | *
40 | */
41 | void setEventFilter(BinlogEventFilter filter);
42 |
43 | void setEventListener(BinlogEventListener listener);
44 |
45 | /**
46 | *
47 | */
48 | List getParserListeners();
49 |
50 | boolean addParserListener(BinlogParserListener listener);
51 |
52 | boolean removeParserListener(BinlogParserListener listener);
53 |
54 | void setParserListeners(List listeners);
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/DatetimeColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class DatetimeColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 6444968242222031354L;
28 |
29 | //
30 | private final java.util.Date value;
31 |
32 | /**
33 | *
34 | */
35 | private DatetimeColumn(java.util.Date value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.util.Date getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final DatetimeColumn valueOf(java.util.Date value) {
58 | return new DatetimeColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/RandEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.RandEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class RandEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public RandEventParser() {
36 | super(RandEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final RandEvent event = new RandEvent(header);
45 | event.setRandSeed1(is.readLong(8));
46 | event.setRandSeed2(is.readLong(8));
47 | context.getEventListener().onEvents(event);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/Datetime2Column.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class Datetime2Column implements Column {
26 | //
27 | private static final long serialVersionUID = 6444968242222031354L;
28 |
29 | //
30 | private final java.util.Date value;
31 |
32 | /**
33 | *
34 | */
35 | private Datetime2Column(java.util.Date value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.util.Date getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final Datetime2Column valueOf(java.util.Date value) {
58 | return new Datetime2Column(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/TimestampColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class TimestampColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 6334849626188321306L;
28 |
29 | //
30 | private final java.sql.Timestamp value;
31 |
32 | /**
33 | *
34 | */
35 | private TimestampColumn(java.sql.Timestamp value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.sql.Timestamp getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final TimestampColumn valueOf(java.sql.Timestamp value) {
58 | return new TimestampColumn(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/Timestamp2Column.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class Timestamp2Column implements Column {
26 | //
27 | private static final long serialVersionUID = 6334849626188321306L;
28 |
29 | //
30 | private final java.sql.Timestamp value;
31 |
32 | /**
33 | *
34 | */
35 | private Timestamp2Column(java.sql.Timestamp value) {
36 | this.value = value;
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public String toString() {
44 | return String.valueOf(this.value);
45 | }
46 |
47 | /**
48 | *
49 | */
50 | public java.sql.Timestamp getValue() {
51 | return this.value;
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public static final Timestamp2Column valueOf(java.sql.Timestamp value) {
58 | return new Timestamp2Column(value);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/UserVariableInt.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.common.util.MySQLConstants;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class UserVariableInt extends AbstractUserVariable {
27 | //
28 | public static final int TYPE = MySQLConstants.INT_RESULT;
29 |
30 | //
31 | private final long value;
32 | @SuppressWarnings("unused") private final int todo; // TODO
33 |
34 | /**
35 | *
36 | */
37 | public UserVariableInt(long value, int todo) {
38 | super(TYPE);
39 | this.value = value;
40 | this.todo = todo;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | @Override
47 | public String toString() {
48 | return new ToStringBuilder(this)
49 | .append("value", value).toString();
50 | }
51 |
52 | /**
53 | *
54 | */
55 | public Long getValue() {
56 | return this.value;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/BlobColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class BlobColumn implements Column {
27 | //
28 | private static final long serialVersionUID = 756688909230132013L;
29 |
30 | //
31 | private final byte[] value;
32 |
33 | /**
34 | *
35 | */
36 | private BlobColumn(byte[] value) {
37 | this.value = value;
38 | }
39 |
40 | /**
41 | *
42 | */
43 | @Override
44 | public String toString() {
45 | return new ToStringBuilder(this)
46 | .append("value", value).toString();
47 | }
48 |
49 | /**
50 | *
51 | */
52 | public byte[] getValue() {
53 | return value;
54 | }
55 |
56 | /**
57 | *
58 | */
59 | public static final BlobColumn valueOf(byte[] value) {
60 | return new BlobColumn(value);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/BinlogEventV4.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog;
18 |
19 | /**
20 | * +=====================================+
21 | * | event | timestamp 0 : 4 |
22 | * | header +----------------------------+
23 | * | | type_code 4 : 1 |
24 | * | +----------------------------+
25 | * | | server_id 5 : 4 |
26 | * | +----------------------------+
27 | * | | event_length 9 : 4 |
28 | * | +----------------------------+
29 | * | | next_position 13 : 4 |
30 | * | +----------------------------+
31 | * | | flags 17 : 2 |
32 | * +=====================================+
33 | * | event | fixed part 19 : y |
34 | * | data +----------------------------+
35 | * | | variable part |
36 | * +=====================================+
37 | * @author Jingqi Xu
38 | */
39 | public interface BinlogEventV4 {
40 |
41 | BinlogEventV4Header getHeader();
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/RotateEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.RotateEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class RotateEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public RotateEventParser() {
36 | super(RotateEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final RotateEvent event = new RotateEvent(header);
45 | event.setBinlogPosition(is.readLong(8));
46 | event.setBinlogFileName(is.readFixedLengthString(is.available()));
47 | context.getEventListener().onEvents(event);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/IntvarEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.IntvarEvent;
24 | import com.google.code.or.common.glossary.UnsignedLong;
25 | import com.google.code.or.io.XInputStream;
26 |
27 | /**
28 | *
29 | * @author Jingqi Xu
30 | */
31 | public class IntvarEventParser extends AbstractBinlogEventParser {
32 |
33 | /**
34 | *
35 | */
36 | public IntvarEventParser() {
37 | super(IntvarEvent.EVENT_TYPE);
38 | }
39 |
40 | /**
41 | *
42 | */
43 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
44 | throws IOException {
45 | final IntvarEvent event = new IntvarEvent(header);
46 | event.setType(is.readInt(1));
47 | event.setValue(UnsignedLong.valueOf(is.readLong(8)));
48 | context.getEventListener().onEvents(event);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/LongLongColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class LongLongColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 4159913884779393654L;
28 |
29 | //
30 | public static final long MIN_VALUE = Long.MIN_VALUE;
31 | public static final long MAX_VALUE = Long.MAX_VALUE;
32 |
33 | //
34 | private final long value;
35 |
36 | /**
37 | *
38 | */
39 | private LongLongColumn(long value) {
40 | this.value = value;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | @Override
47 | public String toString() {
48 | return String.valueOf(this.value);
49 | }
50 |
51 | /**
52 | *
53 | */
54 | public Long getValue() {
55 | return this.value;
56 | }
57 |
58 | /**
59 | *
60 | */
61 | public static final LongLongColumn valueOf(long value) {
62 | return new LongLongColumn(value);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/IncidentEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.IncidentEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class IncidentEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public IncidentEventParser() {
36 | super(IncidentEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final IncidentEvent event = new IncidentEvent(header);
45 | event.setIncidentNumber(is.readInt(1));
46 | event.setMessageLength(is.readInt(1));
47 | if(event.getMessageLength() > 0) event.setMessage(is.readFixedLengthString(event.getMessageLength()));
48 | context.getEventListener().onEvents(event);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/user/UserVariableString.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.user;
18 |
19 | import com.google.code.or.common.util.MySQLConstants;
20 | import com.google.code.or.common.util.ToStringBuilder;
21 |
22 | /**
23 | *
24 | * @author Jingqi Xu
25 | */
26 | public class UserVariableString extends AbstractUserVariable {
27 | //
28 | public static final int TYPE = MySQLConstants.STRING_RESULT;
29 |
30 | //
31 | private final byte[] value;
32 | private final int collation;
33 |
34 | /**
35 | *
36 | */
37 | public UserVariableString(byte[] value, int collation) {
38 | super(TYPE);
39 | this.value = value;
40 | this.collation = collation;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | @Override
47 | public String toString() {
48 | return new ToStringBuilder(this)
49 | .append("value", value)
50 | .append("collation", collation).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public byte[] getValue() {
57 | return this.value;
58 | }
59 |
60 | public int getCollation() {
61 | return collation;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | open-replicator
2 | ===============
3 |
4 | Open Replicator is a high performance MySQL binlog parser written in Java. It unfolds the possibilities that you can parse, filter and broadcast the binlog events in a real time manner.
5 |
6 | ### note
7 |
8 | For MySQL 5.6.6 users, binlog_checksum system variable is NOT supported by open-replicator at the moment, please set it to NONE.
9 |
10 | ### releases
11 | 1.0.7
12 |
13 | release date: 2014-05-12
14 | support signed tinyint, smallint, mediumint, int, bigint
15 |
16 | 1.0.6
17 |
18 | release date: 2014-05-08
19 | remove dependency commons-lang, log4j
20 | support MYSQL_TYPE_TIMESTAMP2, MYSQL_TYPE_DATETIME2, MYSQL_TYPE_TIME2
21 |
22 | 1.0.0
23 |
24 | release date: 2011-12-29
25 |
26 | ### maven
27 | ```
28 |
29 | open-replicator
30 | open-replicator
31 | 1.0.7
32 |
33 | ```
34 | ### parsers
35 |
36 | BinlogEventParser is plugable. All available implementations are registered by default, but you can register only the parsers you are interested in.
37 | 
38 |
39 | ### usage
40 | ```
41 | final OpenReplicator or = new OpenReplicator();
42 | or.setUser("root");
43 | or.setPassword("123456");
44 | or.setHost("localhost");
45 | or.setPort(3306);
46 | or.setServerId(6789);
47 | or.setBinlogPosition(4);
48 | or.setBinlogFileName("mysql_bin.000001");
49 | or.setBinlogEventListener(new BinlogEventListener() {
50 | public void onEvents(BinlogEventV4 event) {
51 | // your code goes here
52 | }
53 | });
54 | or.start();
55 |
56 | System.out.println("press 'q' to stop");
57 | final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
58 | for(String line = br.readLine(); line != null; line = br.readLine()) {
59 | if(line.equals("q")) {
60 | or.stop();
61 | break;
62 | }
63 | }
64 | ```
65 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QFlags2Code.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QFlags2Code extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_FLAGS2_CODE;
32 |
33 | //
34 | private final int flags;
35 |
36 | /**
37 | *
38 | */
39 | public QFlags2Code(int flags) {
40 | super(TYPE);
41 | this.flags = flags;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("flags", flags).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public int getFlags() {
57 | return flags;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QFlags2Code valueOf(XInputStream tis) throws IOException {
64 | return new QFlags2Code(tis.readInt(4));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/XOutputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.UnsignedLong;
22 | import com.google.code.or.common.glossary.column.StringColumn;
23 |
24 | /**
25 | *
26 | * @author Jingqi Xu
27 | */
28 | public interface XOutputStream {
29 |
30 | /**
31 | *
32 | */
33 | void flush() throws IOException;
34 |
35 | void close() throws IOException;
36 |
37 | /**
38 | *
39 | */
40 | void writeBytes(byte value[]) throws IOException;
41 |
42 | void writeBytes(int value, int length) throws IOException;
43 |
44 | void writeInt(int value, int length) throws IOException;
45 |
46 | void writeLong(long value, int length) throws IOException;
47 |
48 | void writeUnsignedLong(UnsignedLong value) throws IOException;
49 |
50 | void writeLengthCodedString(StringColumn value) throws IOException;
51 |
52 | void writeFixedLengthString(StringColumn value) throws IOException;
53 |
54 | void writeNullTerminatedString(StringColumn value) throws IOException;
55 |
56 | void writeBytes(byte value[], int offset, int length) throws IOException;
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QSQLModeCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QSQLModeCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_SQL_MODE_CODE;
32 |
33 | //
34 | private final long sqlMode;
35 |
36 | /**
37 | *
38 | */
39 | public QSQLModeCode(long sqlMode) {
40 | super(TYPE);
41 | this.sqlMode = sqlMode;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("sqlMode", sqlMode).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public long getSqlMode() {
57 | return sqlMode;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QSQLModeCode valueOf(XInputStream tis) throws IOException {
64 | return new QSQLModeCode(tis.readLong(8));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QMicroseconds.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QMicroseconds extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_MICROSECONDS;
32 |
33 | //
34 | private final int startUsec;
35 |
36 | /**
37 | *
38 | */
39 | public QMicroseconds(int startUsec) {
40 | super(TYPE);
41 | this.startUsec = startUsec;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("startUsec", startUsec).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public int getStartUsec() {
57 | return startUsec;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QMicroseconds valueOf(XInputStream tis) throws IOException {
64 | return new QMicroseconds(tis.readInt(3));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/YearColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class YearColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 6428744630692270846L;
28 |
29 | //
30 | private static final YearColumn[] CACHE = new YearColumn[255];
31 | static {
32 | for(int i = 0; i < CACHE.length; i++) {
33 | CACHE[i] = new YearColumn(i + 1900);
34 | }
35 | }
36 |
37 | //
38 | private final int value;
39 |
40 | /**
41 | *
42 | */
43 | private YearColumn(int value) {
44 | this.value = value;
45 | }
46 |
47 | /**
48 | *
49 | */
50 | @Override
51 | public String toString() {
52 | return String.valueOf(this.value);
53 | }
54 |
55 | /**
56 | *
57 | */
58 | public Integer getValue() {
59 | return this.value;
60 | }
61 |
62 | /**
63 | *
64 | */
65 | public static final YearColumn valueOf(int value) {
66 | final int index = value - 1900;
67 | return (index >= 0 && index < CACHE.length) ? CACHE[index] : new YearColumn(value);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QMasterDataWrittenCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QMasterDataWrittenCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_MASTER_DATA_WRITTEN_CODE;
32 |
33 | //
34 | private final int value;
35 |
36 | /**
37 | *
38 | */
39 | public QMasterDataWrittenCode(int value) {
40 | super(TYPE);
41 | this.value = value;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("value", value).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public int getValue() {
57 | return value;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QMasterDataWrittenCode valueOf(XInputStream tis) throws IOException {
64 | return new QMasterDataWrittenCode(tis.readInt(4));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/GtidEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import java.util.Arrays;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 |
24 | /**
25 | *
26 | * @author brandtg
27 | */
28 | public class GtidEvent extends AbstractBinlogEventV4 {
29 | //
30 | private byte[] sourceId;
31 | private long transactionId;
32 |
33 | /**
34 | *
35 | */
36 | public GtidEvent() {
37 | }
38 |
39 | public GtidEvent(BinlogEventV4Header header) {
40 | this.header = header;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | @Override
47 | public String toString() {
48 | return new ToStringBuilder(this)
49 | .append("header", header)
50 | .append("transactionId", transactionId)
51 | .append("sourceId", Arrays.toString(sourceId)).toString();
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public byte[] getSourceId() {
58 | return sourceId;
59 | }
60 |
61 | public void setSourceId(byte[] sourceId) {
62 | this.sourceId = sourceId;
63 | }
64 |
65 | public long getTransactionId() {
66 | return transactionId;
67 | }
68 |
69 | public void setTransactionId(long transactionId) {
70 | this.transactionId = transactionId;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QLcTimeNamesCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QLcTimeNamesCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_LC_TIME_NAMES_CODE;
32 |
33 | //
34 | private final int lcTimeNames;
35 |
36 | /**
37 | *
38 | */
39 | public QLcTimeNamesCode(int lcTimeNames) {
40 | super(TYPE);
41 | this.lcTimeNames = lcTimeNames;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("lcTimeNames", lcTimeNames).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public int getLcTimeNames() {
57 | return lcTimeNames;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QLcTimeNamesCode valueOf(XInputStream tis) throws IOException {
64 | return new QLcTimeNamesCode(tis.readInt(2));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/TransportInputStreamImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | import com.google.code.or.io.impl.XInputStreamImpl;
23 | import com.google.code.or.net.Packet;
24 | import com.google.code.or.net.TransportInputStream;
25 | import com.google.code.or.net.impl.packet.RawPacket;
26 |
27 | /**
28 | *
29 | * @author Jingqi Xu
30 | */
31 | public class TransportInputStreamImpl extends XInputStreamImpl implements TransportInputStream {
32 |
33 | /**
34 | *
35 | */
36 | public TransportInputStreamImpl(InputStream is) {
37 | super(is);
38 | }
39 |
40 | public TransportInputStreamImpl(InputStream is, int size) {
41 | super(is, size);
42 | }
43 |
44 | /**
45 | *
46 | */
47 | public Packet readPacket() throws IOException {
48 | //
49 | final RawPacket r = new RawPacket();
50 | r.setLength(readInt(3));
51 | r.setSequence(readInt(1));
52 |
53 | //
54 | int total = 0;
55 | final byte[] body = new byte[r.getLength()];
56 | while(total < body.length) {
57 | total += this.read(body, total, body.length - total);
58 | }
59 | r.setPacketBody(body);
60 | return r;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/FormatDescriptionEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.FormatDescriptionEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class FormatDescriptionEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public FormatDescriptionEventParser() {
36 | super(FormatDescriptionEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | *
41 | */
42 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
43 | throws IOException {
44 | final FormatDescriptionEvent event = new FormatDescriptionEvent(header);
45 | event.setBinlogVersion(is.readInt(2));
46 | event.setServerVersion(is.readFixedLengthString(50));
47 | event.setCreateTimestamp(is.readLong(4) * 1000L);
48 | event.setHeaderLength(is.readInt(1));
49 | event.setEventTypes(is.readBytes(is.available()));
50 | context.getEventListener().onEvents(event);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/NullColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class NullColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 3300119160243172731L;
28 |
29 | //
30 | private static final NullColumn[] CACHE = new NullColumn[255];
31 | static {
32 | for(int i = 0; i < CACHE.length; i++) {
33 | CACHE[i] = new NullColumn(i);
34 | }
35 | }
36 |
37 | //
38 | private final int type;
39 |
40 | /**
41 | *
42 | */
43 | private NullColumn(int type) {
44 | this.type = type;
45 | }
46 |
47 | /**
48 | *
49 | */
50 | @Override
51 | public String toString() {
52 | return "null";
53 | }
54 |
55 | /**
56 | *
57 | */
58 | public int getType() {
59 | return type;
60 | }
61 |
62 | public Object getValue() {
63 | return null;
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public static final NullColumn valueOf(int type) {
70 | if(type < 0 || type >= CACHE.length) throw new IllegalArgumentException("invalid type: " + type);
71 | return CACHE[type];
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QTableMapForUpdateCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QTableMapForUpdateCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_TABLE_MAP_FOR_UPDATE_CODE;
32 |
33 | //
34 | private final long tableMap;
35 |
36 | /**
37 | *
38 | */
39 | public QTableMapForUpdateCode(long tableMap) {
40 | super(TYPE);
41 | this.tableMap = tableMap;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("tableMap", tableMap).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public long getTableMap() {
57 | return tableMap;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QTableMapForUpdateCode valueOf(XInputStream tis) throws IOException {
64 | return new QTableMapForUpdateCode(tis.readLong(8));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/filter/BinlogRowEventFilterImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.filter;
18 |
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import com.google.code.or.binlog.BinlogEventV4Header;
23 | import com.google.code.or.binlog.BinlogParserContext;
24 | import com.google.code.or.binlog.BinlogRowEventFilter;
25 | import com.google.code.or.binlog.impl.event.TableMapEvent;
26 |
27 | /**
28 | *
29 | * @author Jingqi Xu
30 | */
31 | public class BinlogRowEventFilterImpl implements BinlogRowEventFilter {
32 | //
33 | private static final Logger LOGGER = LoggerFactory.getLogger(BinlogRowEventFilterImpl.class);
34 |
35 | //
36 | private boolean verbose = true;
37 |
38 | /**
39 | *
40 | */
41 | public boolean isVerbose() {
42 | return verbose;
43 | }
44 |
45 | public void setVerbose(boolean verbose) {
46 | this.verbose = verbose;
47 | }
48 |
49 | /**
50 | *
51 | */
52 | public boolean accepts(BinlogEventV4Header header, BinlogParserContext context, TableMapEvent event) {
53 | //
54 | if(event == null) {
55 | if(isVerbose() && LOGGER.isWarnEnabled()) {
56 | LOGGER.warn("failed to find TableMapEvent, header: {}", header);
57 | }
58 | return false;
59 | }
60 |
61 | //
62 | return true;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/util/RamdomAccessFileInputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io.util;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.RandomAccessFile;
23 |
24 | /**
25 | *
26 | * @author Jingqi Xu
27 | */
28 | public class RamdomAccessFileInputStream extends InputStream {
29 | //
30 | private final RandomAccessFile file;
31 |
32 | /**
33 | *
34 | */
35 | public RamdomAccessFileInputStream(File file) throws IOException {
36 | this.file = new RandomAccessFile(file, "r");
37 | }
38 |
39 | /**
40 | *
41 | */
42 | @Override
43 | public int available() throws IOException {
44 | final long fp = this.file.getFilePointer();
45 | return (int)(this.file.length() - fp);
46 | }
47 |
48 | @Override
49 | public void close() throws IOException {
50 | this.file.close();
51 | }
52 |
53 | @Override
54 | public long skip(long n) throws IOException {
55 | final long fp = this.file.getFilePointer();
56 | this.file.seek(fp + n);
57 | return n;
58 | }
59 |
60 | @Override
61 | public int read() throws IOException {
62 | return this.file.read();
63 | }
64 |
65 | @Override
66 | public int read(byte b[], int off, int len) throws IOException {
67 | return this.file.read(b, off, len);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/TinyColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class TinyColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 3629858638897033423L;
28 |
29 | //
30 | public static final int MIN_VALUE = -128;
31 | public static final int MAX_VALUE = 127;
32 |
33 | //
34 | private static final TinyColumn[] CACHE = new TinyColumn[256];
35 | static {
36 | for(int i = MIN_VALUE; i <= MAX_VALUE; i++) {
37 | CACHE[i + 128] = new TinyColumn(i);
38 | }
39 | }
40 |
41 | //
42 | private final int value;
43 |
44 | /**
45 | *
46 | */
47 | private TinyColumn(int value) {
48 | this.value = value;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return String.valueOf(this.value);
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public Integer getValue() {
63 | return this.value;
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public static final TinyColumn valueOf(int value) {
70 | if(value < MIN_VALUE || value > MAX_VALUE) throw new IllegalArgumentException("invalid value: " + value);
71 | return CACHE[value + 128];
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QCatalogCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class QCatalogCode extends AbstractStatusVariable {
31 | //
32 | public static final int TYPE = MySQLConstants.Q_CATALOG_CODE;
33 |
34 | //
35 | private final StringColumn catalogName;
36 |
37 | /**
38 | *
39 | */
40 | public QCatalogCode(StringColumn catalogName) {
41 | super(TYPE);
42 | this.catalogName = catalogName;
43 | }
44 |
45 | /**
46 | *
47 | */
48 | @Override
49 | public String toString() {
50 | return new ToStringBuilder(this)
51 | .append("catalogName", catalogName).toString();
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public StringColumn getCatalogName() {
58 | return catalogName;
59 | }
60 |
61 | /**
62 | *
63 | */
64 | public static QCatalogCode valueOf(XInputStream tis) throws IOException {
65 | tis.readInt(1); // Length
66 | return new QCatalogCode(tis.readNullTerminatedString());
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QTimeZoneCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class QTimeZoneCode extends AbstractStatusVariable {
31 | //
32 | public static final int TYPE = MySQLConstants.Q_TIME_ZONE_CODE;
33 |
34 | //
35 | private final StringColumn timeZone;
36 |
37 | /**
38 | *
39 | */
40 | public QTimeZoneCode(StringColumn timeZone) {
41 | super(TYPE);
42 | this.timeZone = timeZone;
43 | }
44 |
45 | /**
46 | *
47 | */
48 | @Override
49 | public String toString() {
50 | return new ToStringBuilder(this)
51 | .append("timeZone", timeZone).toString();
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public StringColumn getTimeZone() {
58 | return timeZone;
59 | }
60 |
61 | /**
62 | *
63 | */
64 | public static QTimeZoneCode valueOf(XInputStream tis) throws IOException {
65 | final int length = tis.readInt(1); // Length
66 | return new QTimeZoneCode(tis.readFixedLengthString(length));
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/util/ClassUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.util;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public final class ClassUtils {
24 |
25 | /**
26 | *
27 | */
28 | public static String getShortClassName(String className) {
29 | //
30 | if(className == null) return "";
31 | if(className.length() == 0) return "";
32 | StringBuilder arrayPrefix = new StringBuilder();
33 |
34 | // Handle array encoding
35 | if (className.startsWith("[")) {
36 | while (className.charAt(0) == '[') {
37 | className = className.substring(1);
38 | arrayPrefix.append("[]");
39 | }
40 | // Strip Object type encoding
41 | if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') {
42 | className = className.substring(1, className.length() - 1);
43 | }
44 | }
45 |
46 | //
47 | int lastDotIdx = className.lastIndexOf('.');
48 | int innerIdx = className.indexOf('$', lastDotIdx == -1 ? 0 : lastDotIdx + 1);
49 | String out = className.substring(lastDotIdx + 1);
50 | if (innerIdx != -1) {
51 | out = out.replace('$', '.');
52 | }
53 | return out + arrayPrefix;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QCharsetDatabaseCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QCharsetDatabaseCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_CHARSET_DATABASE_CODE;
32 |
33 | //
34 | private final int collationDatabase;
35 |
36 | /**
37 | *
38 | */
39 | public QCharsetDatabaseCode(int collationDatabase) {
40 | super(TYPE);
41 | this.collationDatabase = collationDatabase;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("collationDatabase", collationDatabase).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public int getCollationDatabase() {
57 | return collationDatabase;
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public static QCharsetDatabaseCode valueOf(XInputStream tis) throws IOException {
64 | final int collationDatabase = tis.readInt(2);
65 | return new QCharsetDatabaseCode(collationDatabase);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/command/ComQuery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet.command;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.util.XSerializer;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class ComQuery extends AbstractCommandPacket {
31 | //
32 | private static final long serialVersionUID = 1580858690926781520L;
33 |
34 | //
35 | private StringColumn sql;
36 |
37 | /**
38 | *
39 | */
40 | public ComQuery() {
41 | super(MySQLConstants.COM_QUERY);
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("sql", sql).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public byte[] getPacketBody() throws IOException {
57 | final XSerializer ps = new XSerializer();
58 | ps.writeInt(this.command, 1);
59 | ps.writeFixedLengthString(this.sql);
60 | return ps.toByteArray();
61 | }
62 |
63 | /**
64 | *
65 | */
66 | public StringColumn getSql() {
67 | return sql;
68 | }
69 |
70 | public void setSql(StringColumn sql) {
71 | this.sql = sql;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QCatalogNzCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class QCatalogNzCode extends AbstractStatusVariable {
31 | //
32 | public static final int TYPE = MySQLConstants.Q_CATALOG_NZ_CODE;
33 |
34 | //
35 | private final StringColumn catalogName;
36 |
37 | /**
38 | *
39 | */
40 | public QCatalogNzCode(StringColumn catalogName) {
41 | super(TYPE);
42 | this.catalogName = catalogName;
43 | }
44 |
45 | /**
46 | *
47 | */
48 | @Override
49 | public String toString() {
50 | return new ToStringBuilder(this)
51 | .append("catalogName", catalogName).toString();
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public StringColumn getCatalogName() {
58 | return catalogName;
59 | }
60 |
61 | /**
62 | *
63 | */
64 | public static QCatalogNzCode valueOf(XInputStream tis) throws IOException {
65 | final int length = tis.readInt(1); // Length
66 | return new QCatalogNzCode(tis.readFixedLengthString(length));
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/impl/SocketFactoryImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io.impl;
18 |
19 | import java.net.Socket;
20 |
21 | import com.google.code.or.io.SocketFactory;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public class SocketFactoryImpl implements SocketFactory {
28 | //
29 | private boolean keepAlive = false;
30 | private boolean tcpNoDelay = false;
31 | private int receiveBufferSize = -1;
32 |
33 | /**
34 | *
35 | */
36 | public Socket create(String host, int port) throws Exception {
37 | final Socket r = new Socket(host, port);
38 | r.setKeepAlive(this.keepAlive);
39 | r.setTcpNoDelay(this.tcpNoDelay);
40 | if(this.receiveBufferSize > 0) r.setReceiveBufferSize(this.receiveBufferSize);
41 | return r;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | public boolean isKeepAlive() {
48 | return keepAlive;
49 | }
50 |
51 | public void setKeepAlive(boolean keepAlive) {
52 | this.keepAlive = keepAlive;
53 | }
54 |
55 | public boolean isTcpNoDelay() {
56 | return tcpNoDelay;
57 | }
58 |
59 | public void setTcpNoDelay(boolean tcpNoDelay) {
60 | this.tcpNoDelay = tcpNoDelay;
61 | }
62 |
63 | public int getReceiveBufferSize() {
64 | return receiveBufferSize;
65 | }
66 |
67 | public void setReceiveBufferSize(int receiveBufferSize) {
68 | this.receiveBufferSize = receiveBufferSize;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/DecimalColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import java.math.BigDecimal;
20 |
21 | import com.google.code.or.common.glossary.Column;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public final class DecimalColumn implements Column {
28 | //
29 | private static final long serialVersionUID = -3798378473095594835L;
30 |
31 | //
32 | private final BigDecimal value;
33 | private final int precision;
34 | private final int scale;
35 |
36 | /**
37 | *
38 | */
39 | private DecimalColumn(BigDecimal value, int precision, int scale) {
40 | this.value = value;
41 | this.scale = scale;
42 | this.precision = precision;
43 | }
44 |
45 | /**
46 | *
47 | */
48 | @Override
49 | public String toString() {
50 | return String.valueOf(this.value);
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public BigDecimal getValue() {
57 | return this.value;
58 | }
59 |
60 | public int getPrecision() {
61 | return precision;
62 | }
63 |
64 | public int getScale() {
65 | return scale;
66 | }
67 |
68 | /**
69 | *
70 | */
71 | public static final DecimalColumn valueOf(BigDecimal value, int precision, int scale) {
72 | if(precision < scale) throw new IllegalArgumentException("invalid precision: " + precision + ", scale: " + scale);
73 | return new DecimalColumn(value, precision, scale);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/Int24Column.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class Int24Column implements Column {
26 | //
27 | private static final long serialVersionUID = 6456161237369680803L;
28 |
29 | //
30 | public static final int MIN_VALUE = -8388608;
31 | public static final int MAX_VALUE = 8388607;
32 |
33 | //
34 | private static final Int24Column[] CACHE = new Int24Column[255];
35 | static {
36 | for(int i = 0; i < CACHE.length; i++) {
37 | CACHE[i] = new Int24Column(i + Byte.MIN_VALUE);
38 | }
39 | }
40 |
41 | //
42 | private final int value;
43 |
44 | /**
45 | *
46 | */
47 | private Int24Column(int value) {
48 | this.value = value;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return String.valueOf(this.value);
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public Integer getValue() {
63 | return this.value;
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public static final Int24Column valueOf(int value) {
70 | if(value < MIN_VALUE || value > MAX_VALUE) throw new IllegalArgumentException("invalid value: " + value);
71 | final int index = value - Byte.MIN_VALUE;
72 | return (index >= 0 && index < CACHE.length) ? CACHE[index] : new Int24Column(value);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/LongColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class LongColumn implements Column {
26 | //
27 | private static final long serialVersionUID = -4109941053716659749L;
28 |
29 | //
30 | public static final int MIN_VALUE = Integer.MIN_VALUE;
31 | public static final int MAX_VALUE = Integer.MAX_VALUE;
32 |
33 | //
34 | private static final LongColumn[] CACHE = new LongColumn[255];
35 | static {
36 | for(int i = 0; i < CACHE.length; i++) {
37 | CACHE[i] = new LongColumn(i + Byte.MIN_VALUE);
38 | }
39 | }
40 |
41 | //
42 | private final int value;
43 |
44 | /**
45 | *
46 | */
47 | private LongColumn(int value) {
48 | this.value = value;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return String.valueOf(this.value);
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public Integer getValue() {
63 | return this.value;
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public static final LongColumn valueOf(int value) {
70 | if(value < MIN_VALUE || value > MAX_VALUE) throw new IllegalArgumentException("invalid value: " + value);
71 | final int index = value - Byte.MIN_VALUE;
72 | return (index >= 0 && index < CACHE.length) ? CACHE[index] : new LongColumn(value);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/ShortColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class ShortColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 2278283065371267842L;
28 |
29 | //
30 | public static final int MIN_VALUE = Short.MIN_VALUE;
31 | public static final int MAX_VALUE = Short.MAX_VALUE;
32 |
33 | //
34 | private static final ShortColumn[] CACHE = new ShortColumn[255];
35 | static {
36 | for(int i = 0; i < CACHE.length; i++) {
37 | CACHE[i] = new ShortColumn(i + Byte.MIN_VALUE);
38 | }
39 | }
40 |
41 | //
42 | private final int value;
43 |
44 | /**
45 | *
46 | */
47 | private ShortColumn(int value) {
48 | this.value = value;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return String.valueOf(this.value);
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public Integer getValue() {
63 | return this.value;
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public static final ShortColumn valueOf(int value) {
70 | if(value < MIN_VALUE || value > MAX_VALUE) throw new IllegalArgumentException("invalid value: " + value);
71 | final int index = value - Byte.MIN_VALUE;
72 | return (index >= 0 && index < CACHE.length) ? CACHE[index] : new ShortColumn(value);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/command/ComInitDBPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet.command;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.util.XSerializer;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class ComInitDBPacket extends AbstractCommandPacket {
31 | //
32 | private static final long serialVersionUID = 449639496684376511L;
33 |
34 | //
35 | private StringColumn databaseName;
36 |
37 | /**
38 | *
39 | */
40 | public ComInitDBPacket() {
41 | super(MySQLConstants.COM_INIT_DB);
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | return new ToStringBuilder(this)
50 | .append("databaseName", databaseName).toString();
51 | }
52 |
53 | /**
54 | *
55 | */
56 | public byte[] getPacketBody() throws IOException {
57 | final XSerializer ps = new XSerializer();
58 | ps.writeInt(this.command, 1);
59 | ps.writeFixedLengthString(this.databaseName);
60 | return ps.toByteArray();
61 | }
62 |
63 | /**
64 | *
65 | */
66 | public StringColumn getDatabaseName() {
67 | return databaseName;
68 | }
69 |
70 | public void setDatabaseName(StringColumn databaseName) {
71 | this.databaseName = databaseName;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/Pair.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary;
18 |
19 | import com.google.code.or.common.util.ToStringBuilder;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class Pair {
26 | //
27 | private T before;
28 | private T after;
29 |
30 | /**
31 | *
32 | */
33 | public Pair() {
34 | }
35 |
36 | public Pair(T before, T after) {
37 | this.before = before;
38 | this.after = after;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | public String toString() {
45 | return new ToStringBuilder(this)
46 | .append("before", before)
47 | .append("after", after).toString();
48 | }
49 |
50 | /**
51 | *
52 | */
53 | public T getBefore() {
54 | return before;
55 | }
56 |
57 | public void setBefore(T before) {
58 | this.before = before;
59 | }
60 |
61 | public T getAfter() {
62 | return after;
63 | }
64 |
65 | public void setAfter(T after) {
66 | this.after = after;
67 | }
68 |
69 | /**
70 | *
71 | */
72 | public void swap() {
73 | final T t = this.before;
74 | this.before = this.after;
75 | this.after = t;
76 | }
77 |
78 | /**
79 | *
80 | */
81 | public static void swap(Pair> p) {
82 | doSwap(p); // Nothing but capture the >
83 | }
84 |
85 | private static void doSwap(Pair p) {
86 | synchronized(p) {
87 | final T t = p.before;
88 | p.before = p.after;
89 | p.after = t;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/XidEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.util.MySQLConstants;
21 | import com.google.code.or.common.util.ToStringBuilder;
22 |
23 | /**
24 | * Generated for a commit of a transaction that modifies one or more tables of an XA-capable storage engine.
25 | * Normal transactions are implemented by sending a QUERY_EVENT containing a BEGIN statement and a QUERY_EVENT
26 | * containing a COMMIT statement (or a ROLLBACK statement if the transaction is rolled back).
27 | * Strictly speaking, Xid_log_event is used if thd->transaction.xid_state.xid.get_my_xid() returns non-zero.
28 | *
29 | * @author Jingqi Xu
30 | */
31 | public final class XidEvent extends AbstractBinlogEventV4 {
32 | //
33 | public static final int EVENT_TYPE = MySQLConstants.XID_EVENT;
34 |
35 | //
36 | private long xid;
37 |
38 | /**
39 | *
40 | */
41 | public XidEvent() {
42 | }
43 |
44 | public XidEvent(BinlogEventV4Header header) {
45 | this.header = header;
46 | }
47 |
48 | /**
49 | *
50 | */
51 | @Override
52 | public String toString() {
53 | return new ToStringBuilder(this)
54 | .append("header", header)
55 | .append("xid", xid).toString();
56 | }
57 |
58 | /**
59 | *
60 | */
61 | public long getXid() {
62 | return xid;
63 | }
64 |
65 | public void setXid(long xid) {
66 | this.xid = xid;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/TransportException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.net.impl.packet.ErrorPacket;
22 |
23 | /**
24 | *
25 | * @author Jingqi Xu
26 | */
27 | public class TransportException extends IOException {
28 | //
29 | private static final long serialVersionUID = 646149465892278906L;
30 |
31 | //
32 | private int errorCode;
33 | private String sqlState;
34 | private String errorMessage;
35 |
36 | /**
37 | *
38 | */
39 | public TransportException() {
40 | }
41 |
42 | public TransportException(String message) {
43 | super(message);
44 | this.errorMessage = message;
45 | }
46 |
47 | public TransportException(ErrorPacket ep) {
48 | super(ep.getErrorMessage().toString());
49 | this.errorCode = ep.getErrorCode();
50 | this.sqlState = ep.getSqlState().toString();
51 | this.errorMessage = ep.getErrorMessage().toString();
52 | }
53 |
54 | /**
55 | *
56 | */
57 | public int getErrorCode() {
58 | return errorCode;
59 | }
60 |
61 | public void setErrorCode(int errorCode) {
62 | this.errorCode = errorCode;
63 | }
64 |
65 | public String getSqlState() {
66 | return sqlState;
67 | }
68 |
69 | public void setSqlState(String sqlState) {
70 | this.sqlState = sqlState;
71 | }
72 |
73 | public String getErrorMessage() {
74 | return errorMessage;
75 | }
76 |
77 | public void setErrorMessage(String errorMessage) {
78 | this.errorMessage = errorMessage;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/XidEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.XidEvent;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class XidEventParser extends AbstractBinlogEventParser {
31 |
32 | /**
33 | *
34 | */
35 | public XidEventParser() {
36 | super(XidEvent.EVENT_TYPE);
37 | }
38 |
39 | /**
40 | * Note: Contrary to all other numeric fields, the XID transaction number is not always
41 | * written in little-endian format. The bytes are copied unmodified from memory to disk,
42 | * so the format is machine-dependent. Hence, when replicating from a little-endian to a
43 | * big-endian machine (or vice versa), the numeric value of transaction numbers will differ.
44 | * In particular, the output of mysqlbinlog differs. This should does not cause inconsistencies
45 | * in replication because the only important property of transaction numbers is that different
46 | * transactions have different numbers (relative order does not matter).
47 | */
48 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
49 | throws IOException {
50 | final XidEvent event = new XidEvent(header);
51 | event.setXid(is.readLong(8));
52 | context.getEventListener().onEvents(event);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/io/XInputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.io;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.UnsignedLong;
22 | import com.google.code.or.common.glossary.column.BitColumn;
23 | import com.google.code.or.common.glossary.column.StringColumn;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public interface XInputStream {
30 |
31 | /**
32 | *
33 | */
34 | void close() throws IOException;
35 |
36 | int available() throws IOException;
37 |
38 | boolean hasMore() throws IOException;
39 |
40 | void setReadLimit(int limit) throws IOException;
41 |
42 | /**
43 | *
44 | */
45 | long skip(long n) throws IOException;
46 |
47 | int readInt(int length) throws IOException;
48 |
49 | long readLong(int length) throws IOException;
50 |
51 | byte[] readBytes(int length) throws IOException;
52 |
53 | BitColumn readBit(int length) throws IOException;
54 |
55 | int readSignedInt(int length) throws IOException;
56 |
57 | long readSignedLong(int length) throws IOException;
58 |
59 | UnsignedLong readUnsignedLong() throws IOException;
60 |
61 | StringColumn readLengthCodedString() throws IOException;
62 |
63 | StringColumn readNullTerminatedString() throws IOException;
64 |
65 | StringColumn readFixedLengthString(int length) throws IOException;
66 |
67 | int readInt(int length, boolean littleEndian) throws IOException;
68 |
69 | long readLong(int length, boolean littleEndian) throws IOException;
70 |
71 | BitColumn readBit(int length, boolean littleEndian) throws IOException;
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/GtidEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.binlog.BinlogParserContext;
23 | import com.google.code.or.binlog.impl.event.GtidEvent;
24 | import com.google.code.or.common.util.MySQLConstants;
25 | import com.google.code.or.io.XInputStream;
26 |
27 | /**
28 | * GTID Event
29 | *
30 | *
31 | * Event format:
32 | *
33 | * +-------------------+
34 | * | 1B commit flag |
35 | * +-------------------+
36 | * | 16B Source ID |
37 | * +-------------------+
38 | * | 8B Txn ID |
39 | * +-------------------+
40 | * | ... |
41 | * +-------------------+
42 | *
43 | *
44 | * @author brandtg
45 | */
46 | public class GtidEventParser extends AbstractBinlogEventParser {
47 |
48 | /**
49 | *
50 | */
51 | public GtidEventParser() {
52 | super(MySQLConstants.GTID_LOG_EVENT);
53 | }
54 |
55 | /**
56 | *
57 | */
58 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context) throws IOException {
59 | GtidEvent event = new GtidEvent(header);
60 | is.readBytes(1); // commit flag, always true
61 | event.setSourceId(is.readBytes(16));
62 | event.setTransactionId(is.readLong(8, true));
63 | //event.setTransactionId(ByteBuffer.wrap(is.readBytes(8)).order(ByteOrder.LITTLE_ENDIAN).getLong());
64 | is.skip(is.available()); // position at next event
65 | context.getEventListener().onEvents(event);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QInvoker.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class QInvoker extends AbstractStatusVariable {
31 | //
32 | public static final int TYPE = MySQLConstants.Q_INVOKER;
33 |
34 | //
35 | private final StringColumn user;
36 | private final StringColumn host;
37 |
38 | /**
39 | *
40 | */
41 | public QInvoker(StringColumn user, StringColumn host) {
42 | super(TYPE);
43 | this.user = user;
44 | this.host = host;
45 | }
46 |
47 | /**
48 | *
49 | */
50 | @Override
51 | public String toString() {
52 | return new ToStringBuilder(this)
53 | .append("user", user)
54 | .append("host", host).toString();
55 | }
56 |
57 | /**
58 | *
59 | */
60 | public StringColumn getUser() {
61 | return user;
62 | }
63 |
64 | public StringColumn getHost() {
65 | return host;
66 | }
67 |
68 | /**
69 | *
70 | */
71 | public static QInvoker valueOf(XInputStream tis) throws IOException {
72 | final int userLength = tis.readInt(1);
73 | final StringColumn user = tis.readFixedLengthString(userLength);
74 | final int hostLength = tis.readInt(1);
75 | final StringColumn host = tis.readFixedLengthString(hostLength);
76 | return new QInvoker(user, host);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/RandEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.util.MySQLConstants;
21 | import com.google.code.or.common.util.ToStringBuilder;
22 |
23 | /**
24 | * Written every time a statement uses the RAND() function; precedes other events for the statement.
25 | * Indicates the seed values to use for generating a random number with RAND() in the next statement.
26 | * This is written only before a QUERY_EVENT and is not used with row-based logging.
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public final class RandEvent extends AbstractBinlogEventV4 {
31 | //
32 | public static final int EVENT_TYPE = MySQLConstants.RAND_EVENT;
33 |
34 | //
35 | private long randSeed1;
36 | private long randSeed2;
37 |
38 | /**
39 | *
40 | */
41 | public RandEvent() {
42 | }
43 |
44 | public RandEvent(BinlogEventV4Header header) {
45 | this.header = header;
46 | }
47 |
48 | /**
49 | *
50 | */
51 | @Override
52 | public String toString() {
53 | return new ToStringBuilder(this)
54 | .append("header", header)
55 | .append("randSeed1", randSeed1)
56 | .append("randSeed2", randSeed2).toString();
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public long getRandSeed1() {
63 | return randSeed1;
64 | }
65 |
66 | public void setRandSeed1(long randSeed1) {
67 | this.randSeed1 = randSeed1;
68 | }
69 |
70 | public long getRandSeed2() {
71 | return randSeed2;
72 | }
73 |
74 | public void setRandSeed2(long randSeed2) {
75 | this.randSeed2 = randSeed2;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QAutoIncrement.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QAutoIncrement extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_AUTO_INCREMENT;
32 |
33 | //
34 | private final int autoIncrementIncrement;
35 | private final int autoIncrementOffset;
36 |
37 | /**
38 | *
39 | */
40 | public QAutoIncrement(int autoIncrementIncrement, int autoIncrementOffset) {
41 | super(TYPE);
42 | this.autoIncrementIncrement = autoIncrementIncrement;
43 | this.autoIncrementOffset = autoIncrementOffset;
44 | }
45 |
46 | /**
47 | *
48 | */
49 | @Override
50 | public String toString() {
51 | return new ToStringBuilder(this)
52 | .append("autoIncrementIncrement", autoIncrementIncrement)
53 | .append("autoIncrementOffset", autoIncrementOffset).toString();
54 | }
55 |
56 | /**
57 | *
58 | */
59 | public int getAutoIncrementIncrement() {
60 | return autoIncrementIncrement;
61 | }
62 |
63 | public int getAutoIncrementOffset() {
64 | return autoIncrementOffset;
65 | }
66 |
67 | /**
68 | *
69 | */
70 | public static QAutoIncrement valueOf(XInputStream tis) throws IOException {
71 | final int autoIncrementIncrement = tis.readInt(2);
72 | final int autoIncrementOffset = tis.readInt(2);
73 | return new QAutoIncrement(autoIncrementIncrement, autoIncrementOffset);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/util/ToStringBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.util;
18 |
19 | /**
20 | *
21 | * @author Jingqi Xu
22 | */
23 | public final class ToStringBuilder {
24 | //
25 | private int count;
26 | private final StringBuilder builder;
27 |
28 | /**
29 | *
30 | */
31 | public ToStringBuilder(Object object) {
32 | String name = ClassUtils.getShortClassName(object.getClass().getName());
33 | this.builder = new StringBuilder(32); this.builder.append(name).append("[");
34 | }
35 |
36 | /**
37 | *
38 | */
39 | @Override
40 | public String toString() {
41 | return this.builder.append("]").toString();
42 | }
43 |
44 | /**
45 | *
46 | */
47 | public ToStringBuilder append(String key, int value) {
48 | if(count++ > 0) this.builder.append(',');
49 | this.builder.append(key).append('=').append(value);
50 | return this;
51 | }
52 |
53 | public ToStringBuilder append(String key, long value) {
54 | if(count++ > 0) this.builder.append(',');
55 | this.builder.append(key).append('=').append(value);
56 | return this;
57 | }
58 |
59 | public ToStringBuilder append(String key, byte value) {
60 | if(count++ > 0) this.builder.append(',');
61 | this.builder.append(key).append('=').append(value);
62 | return this;
63 | }
64 |
65 | public ToStringBuilder append(String key, String value) {
66 | if(count++ > 0) this.builder.append(',');
67 | this.builder.append(key).append('=').append(value == null ? "" : value);
68 | return this;
69 | }
70 |
71 | public ToStringBuilder append(String key, Object value) {
72 | if(count++ > 0) this.builder.append(',');
73 | this.builder.append(key).append('=').append(value == null ? "" : value);
74 | return this;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/RotateEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.glossary.column.StringColumn;
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 |
24 | /**
25 | * Written when mysqld switches to a new binary log file. This occurs when someone
26 | * issues a FLUSH LOGS statement or the current binary log file becomes too large.
27 | * The maximum size is determined by max_binlog_size.
28 | *
29 | * @author Jingqi Xu
30 | */
31 | public final class RotateEvent extends AbstractBinlogEventV4 {
32 | //
33 | public static final int EVENT_TYPE = MySQLConstants.ROTATE_EVENT;
34 |
35 | //
36 | private long binlogPosition;
37 | private StringColumn binlogFileName;
38 |
39 | /**
40 | *
41 | */
42 | public RotateEvent() {
43 | }
44 |
45 | public RotateEvent(BinlogEventV4Header header) {
46 | this.header = header;
47 | }
48 |
49 | /**
50 | *
51 | */
52 | @Override
53 | public String toString() {
54 | return new ToStringBuilder(this)
55 | .append("header", header)
56 | .append("binlogPosition", binlogPosition)
57 | .append("binlogFileName", binlogFileName).toString();
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public long getBinlogPosition() {
64 | return binlogPosition;
65 | }
66 |
67 | public void setBinlogPosition(long binlogPosition) {
68 | this.binlogPosition = binlogPosition;
69 | }
70 |
71 | public StringColumn getBinlogFileName() {
72 | return binlogFileName;
73 | }
74 |
75 | public void setBinlogFileName(StringColumn binlogFileName) {
76 | this.binlogFileName = binlogFileName;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/IntvarEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.glossary.UnsignedLong;
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 |
24 | /**
25 | * Written every time a statement uses an AUTO_INCREMENT column or the LAST_INSERT_ID() function;
26 | * precedes other events for the statement. This is written only before a QUERY_EVENT and is not
27 | * used with row-based logging. An INTVAR_EVENT is written with a "subtype" in the event data part:
28 | * INSERT_ID_EVENT indicates the value to use for an AUTO_INCREMENT column in the next statement.
29 | * LAST_INSERT_ID_EVENT indicates the value to use for the LAST_INSERT_ID() function in the next statement.
30 | *
31 | * @author Jingqi Xu
32 | */
33 | public final class IntvarEvent extends AbstractBinlogEventV4 {
34 | //
35 | public static final int EVENT_TYPE = MySQLConstants.INTVAR_EVENT;
36 |
37 | //
38 | private int type;
39 | private UnsignedLong value;
40 |
41 | /**
42 | *
43 | */
44 | public IntvarEvent() {
45 | }
46 |
47 | public IntvarEvent(BinlogEventV4Header header) {
48 | this.header = header;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return new ToStringBuilder(this)
57 | .append("header", header)
58 | .append("type", type)
59 | .append("value", value).toString();
60 | }
61 |
62 | /**
63 | *
64 | */
65 | public int getType() {
66 | return type;
67 | }
68 |
69 | public void setType(int type) {
70 | this.type = type;
71 | }
72 |
73 | public UnsignedLong getValue() {
74 | return value;
75 | }
76 |
77 | public void setValue(UnsignedLong value) {
78 | this.value = value;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/common/glossary/column/BitColumn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.common.glossary.column;
18 |
19 | import com.google.code.or.common.glossary.Column;
20 |
21 | /**
22 | *
23 | * @author Jingqi Xu
24 | */
25 | public final class BitColumn implements Column {
26 | //
27 | private static final long serialVersionUID = 4193150509864408687L;
28 |
29 | //
30 | private static final int BIT_MASKS[] = {1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7};
31 |
32 | //
33 | private final int length;
34 | private final byte[] value;
35 |
36 | /**
37 | *
38 | */
39 | private BitColumn(int length, byte[] value) {
40 | this.length = length;
41 | this.value = value;
42 | }
43 |
44 | /**
45 | *
46 | */
47 | @Override
48 | public String toString() {
49 | final StringBuilder r = new StringBuilder(this.length);
50 | for(int i = this.length - 1; i >= 0; i--) {
51 | r.append(get(i) ? "1" : "0");
52 | }
53 | return r.toString();
54 | }
55 |
56 | /**
57 | *
58 | */
59 | public int getLength() {
60 | return this.length;
61 | }
62 |
63 | public byte[] getValue() {
64 | return this.value;
65 | }
66 |
67 | /**
68 | *
69 | */
70 | public boolean get(int index) {
71 | final int byteIndex = (index >> 3);
72 | final int bitIndex = (index - (byteIndex << 3));
73 | return (this.value[byteIndex] & BIT_MASKS[bitIndex]) != 0;
74 | }
75 |
76 | public void set(int index) {
77 | final int byteIndex = (index >> 3);
78 | final int bitIndex = (index - (byteIndex << 3));
79 | this.value[byteIndex] |= BIT_MASKS[bitIndex];
80 | }
81 |
82 | /**
83 | *
84 | */
85 | public static final BitColumn valueOf(int length, byte[] value) {
86 | if(length < 0 || length > (value.length << 3)) throw new IllegalArgumentException("invalid length: " + length);
87 | return new BitColumn(length, value);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/net/impl/packet/ResultSetRowPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.net.impl.packet;
18 |
19 | import java.io.IOException;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | import com.google.code.or.common.glossary.column.StringColumn;
24 | import com.google.code.or.common.util.ToStringBuilder;
25 | import com.google.code.or.io.util.XDeserializer;
26 | import com.google.code.or.io.util.XSerializer;
27 | import com.google.code.or.net.Packet;
28 |
29 | /**
30 | *
31 | * @author Jingqi Xu
32 | */
33 | public class ResultSetRowPacket extends AbstractPacket {
34 | //
35 | private static final long serialVersionUID = 698187140476020984L;
36 |
37 | //
38 | private List columns;
39 |
40 | /**
41 | *
42 | */
43 | @Override
44 | public String toString() {
45 | return new ToStringBuilder(this)
46 | .append("columns", columns).toString();
47 | }
48 |
49 | /**
50 | *
51 | */
52 | public byte[] getPacketBody() {
53 | final XSerializer s = new XSerializer(1024);
54 | for(StringColumn column : this.columns) {
55 | s.writeLengthCodedString(column);
56 | }
57 | return s.toByteArray();
58 | }
59 |
60 | /**
61 | *
62 | */
63 | public List getColumns() {
64 | return columns;
65 | }
66 |
67 | public void setColumns(List columns) {
68 | this.columns = columns;
69 | }
70 |
71 | /**
72 | *
73 | */
74 | public static ResultSetRowPacket valueOf(Packet packet) throws IOException {
75 | final XDeserializer d = new XDeserializer(packet.getPacketBody());
76 | final ResultSetRowPacket r = new ResultSetRowPacket();
77 | r.length = packet.getLength();
78 | r.sequence = packet.getSequence();
79 | r.setColumns(new LinkedList());
80 | while(d.available() > 0) {
81 | r.getColumns().add(d.readLengthCodedString());
82 | }
83 | return r;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/WriteRowsEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | import com.google.code.or.binlog.BinlogEventV4Header;
24 | import com.google.code.or.binlog.BinlogParserContext;
25 | import com.google.code.or.binlog.impl.event.TableMapEvent;
26 | import com.google.code.or.binlog.impl.event.WriteRowsEvent;
27 | import com.google.code.or.common.glossary.Row;
28 | import com.google.code.or.io.XInputStream;
29 |
30 | /**
31 | *
32 | * @author Jingqi Xu
33 | */
34 | public class WriteRowsEventParser extends AbstractRowEventParser {
35 |
36 | /**
37 | *
38 | */
39 | public WriteRowsEventParser() {
40 | super(WriteRowsEvent.EVENT_TYPE);
41 | }
42 |
43 | /**
44 | *
45 | */
46 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
47 | throws IOException {
48 | //
49 | final long tableId = is.readLong(6);
50 | final TableMapEvent tme = context.getTableMapEvent(tableId);
51 | if(this.rowEventFilter != null && !this.rowEventFilter.accepts(header, context, tme)) {
52 | is.skip(is.available());
53 | return;
54 | }
55 |
56 | //
57 | final WriteRowsEvent event = new WriteRowsEvent(header);
58 | event.setTableId(tableId);
59 | event.setReserved(is.readInt(2));
60 | event.setColumnCount(is.readUnsignedLong());
61 | event.setUsedColumns(is.readBit(event.getColumnCount().intValue()));
62 | event.setRows(parseRows(is, tme, event));
63 | context.getEventListener().onEvents(event);
64 | }
65 |
66 | /**
67 | *
68 | */
69 | protected List parseRows(XInputStream is, TableMapEvent tme, WriteRowsEvent wre)
70 | throws IOException {
71 | final List r = new LinkedList();
72 | while(is.available() > 0) {
73 | r.add(parseRow(is, tme, wre.getUsedColumns()));
74 | }
75 | return r;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/parser/DeleteRowsEventParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.parser;
18 |
19 | import java.io.IOException;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | import com.google.code.or.binlog.BinlogEventV4Header;
24 | import com.google.code.or.binlog.BinlogParserContext;
25 | import com.google.code.or.binlog.impl.event.DeleteRowsEvent;
26 | import com.google.code.or.binlog.impl.event.TableMapEvent;
27 | import com.google.code.or.common.glossary.Row;
28 | import com.google.code.or.io.XInputStream;
29 |
30 | /**
31 | *
32 | * @author Jingqi Xu
33 | */
34 | public class DeleteRowsEventParser extends AbstractRowEventParser {
35 |
36 | /**
37 | *
38 | */
39 | public DeleteRowsEventParser() {
40 | super(DeleteRowsEvent.EVENT_TYPE);
41 | }
42 |
43 | /**
44 | *
45 | */
46 | public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
47 | throws IOException {
48 | //
49 | final long tableId = is.readLong(6);
50 | final TableMapEvent tme = context.getTableMapEvent(tableId);
51 | if(this.rowEventFilter != null && !this.rowEventFilter.accepts(header, context, tme)) {
52 | is.skip(is.available());
53 | return;
54 | }
55 |
56 | //
57 | final DeleteRowsEvent event = new DeleteRowsEvent(header);
58 | event.setTableId(tableId);
59 | event.setReserved(is.readInt(2));
60 | event.setColumnCount(is.readUnsignedLong());
61 | event.setUsedColumns(is.readBit(event.getColumnCount().intValue()));
62 | event.setRows(parseRows(is, tme, event));
63 | context.getEventListener().onEvents(event);
64 | }
65 |
66 | /**
67 | *
68 | */
69 | protected List parseRows(XInputStream is, TableMapEvent tme, DeleteRowsEvent dre)
70 | throws IOException {
71 | final List r = new LinkedList();
72 | while(is.available() > 0) {
73 | r.add(parseRow(is, tme, dre.getUsedColumns()));
74 | }
75 | return r;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QCharsetCode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 | import com.google.code.or.io.XInputStream;
24 |
25 | /**
26 | *
27 | * @author Jingqi Xu
28 | */
29 | public class QCharsetCode extends AbstractStatusVariable {
30 | //
31 | public static final int TYPE = MySQLConstants.Q_CHARSET_CODE;
32 |
33 | //
34 | private final int characterSetClient;
35 | private final int collationConnection;
36 | private final int collationServer;
37 |
38 | /**
39 | *
40 | */
41 | public QCharsetCode(int characterSetClient, int collationConnection, int collationServer) {
42 | super(TYPE);
43 | this.characterSetClient = characterSetClient;
44 | this.collationConnection = collationConnection;
45 | this.collationServer = collationServer;
46 | }
47 |
48 | /**
49 | *
50 | */
51 | @Override
52 | public String toString() {
53 | return new ToStringBuilder(this)
54 | .append("characterSetClient", characterSetClient)
55 | .append("collationConnection", collationConnection)
56 | .append("collationServer", collationServer).toString();
57 | }
58 |
59 | /**
60 | *
61 | */
62 | public int getCharacterSetClient() {
63 | return characterSetClient;
64 | }
65 |
66 | public int getCollationConnection() {
67 | return collationConnection;
68 | }
69 |
70 | public int getCollationServer() {
71 | return collationServer;
72 | }
73 |
74 | /**
75 | *
76 | */
77 | public static QCharsetCode valueOf(XInputStream tis) throws IOException {
78 | final int characterSetClient = tis.readInt(2);
79 | final int collationConnection = tis.readInt(2);
80 | final int collationServer = tis.readInt(2);
81 | return new QCharsetCode(characterSetClient, collationConnection, collationServer);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/variable/status/QUpdatedDBNames.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.variable.status;
18 |
19 | import java.io.IOException;
20 |
21 | import com.google.code.or.common.glossary.column.StringColumn;
22 | import com.google.code.or.common.util.MySQLConstants;
23 | import com.google.code.or.common.util.ToStringBuilder;
24 | import com.google.code.or.io.XInputStream;
25 |
26 | /**
27 | *
28 | * @author Jingqi Xu
29 | */
30 | public class QUpdatedDBNames extends AbstractStatusVariable {
31 | //
32 | public static final int TYPE = MySQLConstants.Q_UPDATED_DB_NAMES;
33 |
34 | //
35 | private final int accessedDbCount;
36 | private final StringColumn[] accessedDbs;
37 |
38 | /**
39 | *
40 | */
41 | public QUpdatedDBNames(int accessedDbCount, StringColumn[] accessedDbs) {
42 | super(TYPE);
43 | this.accessedDbCount = accessedDbCount;
44 | this.accessedDbs = accessedDbs;
45 | }
46 |
47 | /**
48 | *
49 | */
50 | @Override
51 | public String toString() {
52 | return new ToStringBuilder(this)
53 | .append("accessedDbCount", accessedDbCount)
54 | .append("accessedDbs", accessedDbs).toString();
55 | }
56 |
57 | /**
58 | *
59 | */
60 | public int getAccessedDbCount() {
61 | return accessedDbCount;
62 | }
63 |
64 | public StringColumn[] getAccessedDbs() {
65 | return accessedDbs;
66 | }
67 |
68 | /**
69 | *
70 | */
71 | public static QUpdatedDBNames valueOf(XInputStream tis) throws IOException {
72 | int accessedDbCount= tis.readInt(1);
73 | StringColumn accessedDbs[] = null;
74 | if(accessedDbCount > MySQLConstants.MAX_DBS_IN_EVENT_MTS) {
75 | accessedDbCount = MySQLConstants.OVER_MAX_DBS_IN_EVENT_MTS;
76 | } else {
77 | accessedDbs = new StringColumn[accessedDbCount];
78 | for(int i = 0; i < accessedDbCount; i++) {
79 | accessedDbs[i] = tis.readNullTerminatedString();
80 | }
81 | }
82 | return new QUpdatedDBNames(accessedDbCount, accessedDbs);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/IncidentEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import com.google.code.or.binlog.BinlogEventV4Header;
20 | import com.google.code.or.common.glossary.column.StringColumn;
21 | import com.google.code.or.common.util.MySQLConstants;
22 | import com.google.code.or.common.util.ToStringBuilder;
23 |
24 | /**
25 | * Used to log an out of the ordinary event that occurred on the master.
26 | * It notifies the slave that something happened on the master that might
27 | * cause data to be in an inconsistent state.
28 | *
29 | * @author Jingqi Xu
30 | * @see sql/rpl_constants.h
31 | */
32 | public final class IncidentEvent extends AbstractBinlogEventV4 {
33 | //
34 | public static final int EVENT_TYPE = MySQLConstants.INCIDENT_EVENT;
35 |
36 | //
37 | private int incidentNumber;
38 | private int messageLength;
39 | private StringColumn message;
40 |
41 | /**
42 | *
43 | */
44 | public IncidentEvent() {
45 | }
46 |
47 | public IncidentEvent(BinlogEventV4Header header) {
48 | this.header = header;
49 | }
50 |
51 | /**
52 | *
53 | */
54 | @Override
55 | public String toString() {
56 | return new ToStringBuilder(this)
57 | .append("header", header)
58 | .append("incidentNumber", incidentNumber)
59 | .append("messageLength", messageLength)
60 | .append("message", message).toString();
61 | }
62 |
63 | /**
64 | *
65 | */
66 | public int getIncidentNumber() {
67 | return incidentNumber;
68 | }
69 |
70 | public void setIncidentNumber(int incidentNumber) {
71 | this.incidentNumber = incidentNumber;
72 | }
73 |
74 | public int getMessageLength() {
75 | return messageLength;
76 | }
77 |
78 | public void setMessageLength(int messageLength) {
79 | this.messageLength = messageLength;
80 | }
81 |
82 | public StringColumn getMessage() {
83 | return message;
84 | }
85 |
86 | public void setMessage(StringColumn message) {
87 | this.message = message;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/WriteRowsEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import java.util.List;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.common.glossary.Row;
23 | import com.google.code.or.common.glossary.UnsignedLong;
24 | import com.google.code.or.common.glossary.column.BitColumn;
25 | import com.google.code.or.common.util.MySQLConstants;
26 | import com.google.code.or.common.util.ToStringBuilder;
27 |
28 | /**
29 | * Used for row-based binary logging. This event logs inserts of rows in a single table.
30 | *
31 | * @author Jingqi Xu
32 | */
33 | public final class WriteRowsEvent extends AbstractRowEvent {
34 | //
35 | public static final int EVENT_TYPE = MySQLConstants.WRITE_ROWS_EVENT;
36 |
37 | //
38 | private UnsignedLong columnCount;
39 | private BitColumn usedColumns;
40 | private List rows;
41 |
42 | /**
43 | *
44 | */
45 | public WriteRowsEvent() {
46 | }
47 |
48 | public WriteRowsEvent(BinlogEventV4Header header) {
49 | this.header = header;
50 | }
51 |
52 | /**
53 | *
54 | */
55 | @Override
56 | public String toString() {
57 | return new ToStringBuilder(this)
58 | .append("header", header)
59 | .append("tableId", tableId)
60 | .append("reserved", reserved)
61 | .append("columnCount", columnCount)
62 | .append("usedColumns", usedColumns)
63 | .append("rows", rows).toString();
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public UnsignedLong getColumnCount() {
70 | return columnCount;
71 | }
72 |
73 | public void setColumnCount(UnsignedLong columnCount) {
74 | this.columnCount = columnCount;
75 | }
76 |
77 | public BitColumn getUsedColumns() {
78 | return usedColumns;
79 | }
80 |
81 | public void setUsedColumns(BitColumn usedColumns) {
82 | this.usedColumns = usedColumns;
83 | }
84 |
85 | public List getRows() {
86 | return rows;
87 | }
88 |
89 | public void setRows(List rows) {
90 | this.rows = rows;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/google/code/or/binlog/impl/event/DeleteRowsEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.google.code.or.binlog.impl.event;
18 |
19 | import java.util.List;
20 |
21 | import com.google.code.or.binlog.BinlogEventV4Header;
22 | import com.google.code.or.common.glossary.Row;
23 | import com.google.code.or.common.glossary.UnsignedLong;
24 | import com.google.code.or.common.glossary.column.BitColumn;
25 | import com.google.code.or.common.util.MySQLConstants;
26 | import com.google.code.or.common.util.ToStringBuilder;
27 |
28 | /**
29 | * Used for row-based binary logging. This event logs deletions of rows in a single table.
30 | *
31 | * @author Jingqi Xu
32 | */
33 | public final class DeleteRowsEvent extends AbstractRowEvent {
34 | //
35 | public static final int EVENT_TYPE = MySQLConstants.DELETE_ROWS_EVENT;
36 |
37 | //
38 | private UnsignedLong columnCount;
39 | private BitColumn usedColumns;
40 | private List rows;
41 |
42 | /**
43 | *
44 | */
45 | public DeleteRowsEvent() {
46 | }
47 |
48 | public DeleteRowsEvent(BinlogEventV4Header header) {
49 | this.header = header;
50 | }
51 |
52 | /**
53 | *
54 | */
55 | @Override
56 | public String toString() {
57 | return new ToStringBuilder(this)
58 | .append("header", header)
59 | .append("tableId", tableId)
60 | .append("reserved", reserved)
61 | .append("columnCount", columnCount)
62 | .append("usedColumns", usedColumns)
63 | .append("rows", rows).toString();
64 | }
65 |
66 | /**
67 | *
68 | */
69 | public UnsignedLong getColumnCount() {
70 | return columnCount;
71 | }
72 |
73 | public void setColumnCount(UnsignedLong columnCount) {
74 | this.columnCount = columnCount;
75 | }
76 |
77 | public BitColumn getUsedColumns() {
78 | return usedColumns;
79 | }
80 |
81 | public void setUsedColumns(BitColumn usedColumns) {
82 | this.usedColumns = usedColumns;
83 | }
84 |
85 | public List getRows() {
86 | return rows;
87 | }
88 |
89 | public void setRows(List rows) {
90 | this.rows = rows;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------